diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/GroupingController.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/GroupingController.java index 8dc7072..3ba4bc4 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/GroupingController.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/GroupingController.java @@ -1,5 +1,6 @@ package com.test.bijihoudaun.controller; +import cn.hutool.core.util.StrUtil; import com.test.bijihoudaun.common.response.R; import com.test.bijihoudaun.entity.Grouping; import com.test.bijihoudaun.service.GroupingService; @@ -29,14 +30,14 @@ public class GroupingController { @Operation(summary = "获取全部分组") @Parameters({ - @Parameter(name = "parentId", description = "0是一级,其他的是看它的父级id", required = true) + @Parameter(name = "parentId", description = "0是一级,其他的是看它的父级id", required = false) }) @GetMapping - public R> getAllGroupings(String parentId) { - if (parentId == null) { - return R.fail("参数不能为空"); + public R> getAllGroupings(@RequestParam(required = false) String parentId) { + Long l= null; + if (StrUtil.isNotEmpty(parentId)) { + l = Long.parseLong(parentId); } - long l = Long.parseLong(parentId); List groupings = groupingService.getAllGroupings(l); return R.success(groupings); } diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/MarkdownController.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/MarkdownController.java index 89c17e9..9a4afcd 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/MarkdownController.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/controller/MarkdownController.java @@ -10,6 +10,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.Date; import java.util.List; @Tag(name = "markdown接口") @@ -61,21 +62,10 @@ public class MarkdownController { } @Operation(summary = "更新Markdown文件") - @Parameters({ - @Parameter(name = "id", description = "Markdown文件ID", required = true), - @Parameter(name = "content", description = "Markdown文件内容", required = true) - }) - @PostMapping("/{id}") - public R updateMarkdown( - @PathVariable String id, - String content) { - long l = Long.parseLong(id); - MarkdownFile file = markdownFileService.updateMarkdownContent(l, content); - - if (file != null) { - return R.success(file); - } - return R.fail(); + @PostMapping("/updateMarkdown") + public R updateMarkdown(@RequestBody MarkdownFile markdownFile) { + MarkdownFile file = markdownFileService.updateMarkdownContent(markdownFile); + return R.success(file); } @Operation(summary = "获取所有Markdown文件") diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/MarkdownFileService.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/MarkdownFileService.java index c807c6d..0bbffd9 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/MarkdownFileService.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/MarkdownFileService.java @@ -18,11 +18,9 @@ public interface MarkdownFileService extends IService { /** * 更新Markdown内容 - * @param id 文件ID - * @param content 新内容 * @return 更新后的文件对象 */ - MarkdownFile updateMarkdownContent(Long id, String content); + MarkdownFile updateMarkdownContent(MarkdownFile markdownFile); /** * 根据ID获取Markdown文件 diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java index 63ab582..3fa94bd 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/GroupingServiceImpl.java @@ -27,9 +27,11 @@ public class GroupingServiceImpl @Override public List getAllGroupings(Long parentId) { -// return groupingMapper.selectList(new LambdaQueryWrapper() -// .eq(Grouping::getParentId, parentId)); - return groupingMapper.selectList(null); + if (parentId == null){ + return groupingMapper.selectList(null); + } + return groupingMapper.selectList(new LambdaQueryWrapper() + .eq(Grouping::getParentId, parentId)); } @Override diff --git a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/MarkdownFileServiceImpl.java b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/MarkdownFileServiceImpl.java index 0ce1431..c3bf34a 100644 --- a/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/MarkdownFileServiceImpl.java +++ b/biji-houdaun/src/main/java/com/test/bijihoudaun/service/impl/MarkdownFileServiceImpl.java @@ -40,14 +40,16 @@ public class MarkdownFileServiceImpl } @Override - public MarkdownFile updateMarkdownContent(Long id, String content) { - MarkdownFile file = this.getById(id); - if (file != null) { - file.setContent(content); - file.setUpdatedAt(new Date()); - this.updateById(file); + public MarkdownFile updateMarkdownContent(MarkdownFile markdownFile) { + markdownFile.setUpdatedAt(new Date()); + if (markdownFile.getId() != null){ + markdownFileMapper.update(markdownFile, new QueryWrapper().eq("id", markdownFile.getId())); + }else { + markdownFile.setId(snowflakeIdGenerator.nextId()); + markdownFile.setCreatedAt(new Date()); + markdownFileMapper.insert(markdownFile); } - return file; + return markdownFile; } @Override diff --git a/biji-qianduan/src/api/CommonApi.js b/biji-qianduan/src/api/CommonApi.js index 991c20e..8c2c99c 100644 --- a/biji-qianduan/src/api/CommonApi.js +++ b/biji-qianduan/src/api/CommonApi.js @@ -21,14 +21,8 @@ export const addGroupings = (name) => { }) } //更新Markdown文件 -export const updateMarkdown = (id, data) => { - const formData = new FormData() - if (data) formData.append('content', data) - return axiosApi.post(`/api/markdown/${id}`, formData, { - headers: { - 'Content-Type': 'multipart/form-data' - } - }) +export const updateMarkdown = (data) => { + return axiosApi.post(`/api/markdown/updateMarkdown`, data) } // 批量删除图片 export const deleteImages = (list) => { diff --git a/biji-qianduan/src/components/HomePage.vue b/biji-qianduan/src/components/HomePage.vue index eb5cb81..801bc55 100644 --- a/biji-qianduan/src/components/HomePage.vue +++ b/biji-qianduan/src/components/HomePage.vue @@ -99,7 +99,14 @@ - + + + + + + + + @@ -115,12 +122,22 @@ + + + + + @@ -150,7 +167,11 @@ import { } from '@/api/CommonApi.js' import {DArrowRight} from "@element-plus/icons-vue"; - +const isGroup1=ref(true) +// 创建新文件中大分类的信息 +const fenlei1=ref(null) +// 创建新文件中分类信息 +const fenlei2=ref(null) const markdownFiles = ref([]); const groupings = ref([]); // 二级分类下的markdown文件 @@ -162,22 +183,36 @@ const isCollapsed = ref(false); const showCreateGroupDialog = ref(false); const showCreateNoteDialog = ref(false); const newGroupForm = ref({ name: '' }); -const newNoteForm = ref({ title: '', groupingId: null }); - +const newNoteForm = ref({ + id: null, + title: '', + groupingId: null , + fileName: '', + content: '' +}); +// 创建新笔记的多级菜单 +const options=ref([]) +// 编辑笔记的数据 const editData=ref(null) - // 笔记中的所有图片url const imageUrls = ref([]); // 刚开始笔记中的所有图片url const originalImages = ref([]); - +// 分类为二级的数据 const jb22=ref([]) +// 创建md文件时通过大分类获取二级分类 +const getjb2 = async () => { + if (fenlei1.value != null) { + const response = await groupingAll(fenlei1.value) + fenlei2.value=response.data + } +} + // 获取所有分组 const fetchGroupings = async () => { try { - const response = await groupingAll(0) - + const response = await groupingAll("") const jb1 = [] const jb2 = [] for (let i = 0; i { } groupings.value=jb1 jb22.value=jb2 + for (let i = 0; i < jb1.length; i++){ + jb1[i].children=[] + options.value.push(jb1[i]) + for (let j = 0; j < jb2.length; j++) { + if (+jb2[j].parentId===+jb1[i].id){ + options.value[i].children.push(jb2[i]) + } + } + } } catch (error) { console.error('获取分组失败:', error); ElMessage.error('获取分组失败: ' + (error.response?.data?.message || error.message)); @@ -237,20 +281,13 @@ const createGrouping = async () => { // 创建新笔记 const createNote = async () => { - // TODO 添加笔记创建逻辑 try { - await axios.post(`${API_BASE_URL}/api/markdown`, '# 新笔记内容', { - params: { - groupingId: newNoteForm.value.groupingId, - title: newNoteForm.value.title, - fileName: newNoteForm.value.title - } - }); - - ElMessage.success('笔记创建成功'); - showCreateNoteDialog.value = false; - newNoteForm.value = { title: '', groupingId: null }; - await chushihua() + newNoteForm.value.fileName = newNoteForm.value.title+'.md' + editData.value=newNoteForm.value + console.log(editData.value) + showCreateNoteDialog.value = false + showEditor.value = true; + selectedFile.value=editData.value } catch (error) { ElMessage.error('创建笔记失败: ' + error.message); } @@ -258,6 +295,11 @@ const createNote = async () => { // 选择文件预览 const previewFile = async (file) => { + if (file.id === null){ + editData.value=file + selectedFile.value=null + return; + } try { const response = await Preview(file.id) @@ -313,7 +355,8 @@ const handleImageUpload=async (event, insertImage, files) => { const handleSave= async (file) => { imageUrls.value = extractImageUrls(file); extractDeletedImageUrls(imageUrls.value) - const filesRes = await updateMarkdown(editData.value.id,file); + editData.value.content = file + const filesRes = await updateMarkdown(editData.value); if (filesRes.code===200){ ElMessage.success(filesRes.msg); await chushihua() diff --git a/mydatabase.db b/mydatabase.db index 1273e81..f6ae0f3 100644 Binary files a/mydatabase.db and b/mydatabase.db differ diff --git a/uploads/7bc7657f-caea-45ff-a892-0ef0459e4915.jpg b/uploads/7bc7657f-caea-45ff-a892-0ef0459e4915.jpg new file mode 100644 index 0000000..496975c Binary files /dev/null and b/uploads/7bc7657f-caea-45ff-a892-0ef0459e4915.jpg differ