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 3ba4bc4..ffa7d7b 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 @@ -24,6 +24,9 @@ public class GroupingController { @Operation(summary = "创建分组") @PostMapping public R createGrouping(@RequestBody Grouping grouping) { + if (grouping.getParentId() == null) { + grouping.setParentId(0L); + } Grouping created = groupingService.createGrouping(grouping); return R.success(created); } diff --git a/biji-qianduan/src/api/CommonApi.js b/biji-qianduan/src/api/CommonApi.js index 4692261..415b8bc 100644 --- a/biji-qianduan/src/api/CommonApi.js +++ b/biji-qianduan/src/api/CommonApi.js @@ -11,14 +11,8 @@ export const markdownAll = () => axiosApi.get(`/api/markdown`); export const Preview = (id) => axiosApi.get(`/api/markdown/${id}`); // 创建分类分组 -export const addGroupings = (name) => { - const formData = new FormData() - if (name) formData.append('grouping', name) - return axiosApi.post('/api/groupings', formData, { - headers: { - 'Content-Type': 'multipart/form-data' - } - }) +export const addGroupings = (group) => { + return axiosApi.post('/api/groupings', group); } //更新Markdown文件 export const updateMarkdown = (data) => { diff --git a/biji-qianduan/src/components/HomePage.vue b/biji-qianduan/src/components/HomePage.vue index b3f9ef6..dc91813 100644 --- a/biji-qianduan/src/components/HomePage.vue +++ b/biji-qianduan/src/components/HomePage.vue @@ -40,6 +40,7 @@
返回 + 移动 编辑 删除 返回 @@ -93,7 +94,10 @@
-
{{ file.title }}
+
+ {{ file.title }} + {{ currentGroupName }} +
@@ -169,6 +173,22 @@ 确定 + + + + + + @@ -213,6 +233,9 @@ const newName = ref(''); const showSelectGroupDialog = ref(false); const importGroupId = ref(null); const fileToImport = ref(null); +const showMoveNoteDialog = ref(false); +const moveToGroupId = ref(null); +const currentGroupName = ref(''); const groupFormRef = ref(null); const newGroupForm = ref({ name: '', parentId: null }); @@ -242,9 +265,7 @@ const previewHtml = ref(''); const saveStatus = ref('空闲'); let debounceTimer = null; -const categoryCascaderOptions = computed(() => { - return [{ id: 0, grouping: '根分类', value: 0, label: '根分类' }, ...categoryTree.value]; -}); +const categoryCascaderOptions = computed(() => categoryTree.value); const initVditor = () => { vditor.value = new Vditor('vditor', { @@ -274,11 +295,11 @@ const buildTree = (items) => { // First, map all items by their id items.forEach(item => { itemMap.set(String(item.id), { - ...item, - value: item.id, - label: item.grouping, - children: [], // Initialize children array - }); + ...item, + value: item.id, + label: item.grouping, + children: [], // Initialize children array + }); }); // Then, build the tree structure @@ -323,6 +344,7 @@ const fetchGroupings = async () => { const selectFile = async (data) => { const promise = await markdownList(data.id); groupMarkdownFiles.value = promise.data; + currentGroupName.value = data.grouping; selectedFile.value = null; }; @@ -344,7 +366,7 @@ const createGrouping = async () => { if (valid) { try { const payload = { - name: newGroupForm.value.name, + grouping: newGroupForm.value.name, // 将 name 映射到 grouping parentId: newGroupForm.value.parentId || 0 }; await addGroupings(payload); @@ -406,7 +428,7 @@ const resetNoteForm = () => { const renderMenu = (item) => { if (item.children && item.children.length > 0) { return h(ElSubMenu, { index: `group-${item.id}` }, { - title: () => h('div', { class: 'menu-item-title' }, [ + title: () => h('div', { class: 'menu-item-title', onClick: () => selectFile(item) }, [ h(ElIcon, () => h(Folder)), h('span', null, item.grouping), h(ElIcon, { class: 'edit-icon', onClick: (e) => { e.stopPropagation(); openRenameDialog(item, 'group'); } }, () => h(Edit)) @@ -710,6 +732,31 @@ const handleExportMd = () => { document.body.removeChild(link); window.URL.revokeObjectURL(url); }; + +const handleMoveNote = async () => { + if (!moveToGroupId.value) { + ElMessage.error('请选择目标分类'); + return; + } + if (!selectedFile.value) { + ElMessage.error('没有选中的笔记'); + return; + } + + try { + const updatedFile = { + ...selectedFile.value, + groupingId: moveToGroupId.value, + }; + await updateMarkdown(updatedFile); + ElMessage.success('笔记移动成功'); + showMoveNoteDialog.value = false; + selectedFile.value = null; // 返回列表页 + await chushihua(); // 刷新数据 + } catch (error) { + ElMessage.error('移动失败: ' + error.message); + } +};