|
57 | 57 | import { Back, Loading } from '@element-plus/icons-vue'; |
58 | 58 | import http from '@/utils/http'; |
59 | 59 | import CustomMdEditor from '@/components/Editor/MdEditor.vue'; // 使用 CustomMdEditor |
60 | | -import { getNotes } from '@/api/note'; // 导入 getNotes API |
| 60 | +import { getNotes, createNote } from '@/api/note'; // 导入笔记相关 API |
61 | 61 | import { Splitpanes, Pane } from 'splitpanes'; |
62 | 62 | import 'splitpanes/dist/splitpanes.css'; |
63 | 63 | import { ElMessage } from 'element-plus'; |
@@ -122,13 +122,21 @@ export default { |
122 | 122 | this.noteId = firstNote.id; |
123 | 123 | // CustomMdEditor 会通过 noteId prop 自动加载其内容, |
124 | 124 | // 并通过 v-model 更新 editorContent。 |
125 | | - // 如果 CustomMdEditor 内部加载内容后没有立即通过 emit 更新 modelValue, |
126 | | - // 可能需要在这里手动设置 this.editorContent = firstNote.content; |
127 | | - // 但通常 v-model 组件会处理好双向绑定。 |
128 | 125 | } else { |
129 | | - this.noteId = null; // 没有关联笔记 |
130 | | - this.editorContent = ""; // 清空编辑器内容 |
131 | | - ElMessage.info("当前文献没有关联笔记,您可以开始新的记录。"); |
| 126 | + // 没有关联笔记,创建新笔记 |
| 127 | + const createResponse = await createNote({ |
| 128 | + article_id: articleId, |
| 129 | + content: "", |
| 130 | + title: `note` // 使用文献标题或ID作为笔记标题 |
| 131 | + }); |
| 132 | + |
| 133 | + if (createResponse && createResponse.data) { |
| 134 | + this.noteId = createResponse.data.note_id; // 假设后端返回新创建笔记的ID |
| 135 | + this.editorContent = ""; // 清空编辑器内容 |
| 136 | + // ElMessage.success("已为您创建新笔记,可以开始记录了。"); |
| 137 | + } else { |
| 138 | + throw new Error("创建笔记失败"); |
| 139 | + } |
132 | 140 | } |
133 | 141 | } catch (error) { |
134 | 142 | console.error("获取关联笔记失败:", error); |
|
0 commit comments