Skip to content

Commit e614e1a

Browse files
authored
Merge pull request #98 from BUAA-SE-coders007/feature/note-create
feat: 进入文献阅读页立刻自动生成第一篇笔记
2 parents 8ced545 + a30a2ee commit e614e1a

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/layouts/PaperNote.vue

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
import { Back, Loading } from '@element-plus/icons-vue';
5858
import http from '@/utils/http';
5959
import CustomMdEditor from '@/components/Editor/MdEditor.vue'; // 使用 CustomMdEditor
60-
import { getNotes } from '@/api/note'; // 导入 getNotes API
60+
import { getNotes, createNote } from '@/api/note'; // 导入笔记相关 API
6161
import { Splitpanes, Pane } from 'splitpanes';
6262
import 'splitpanes/dist/splitpanes.css';
6363
import { ElMessage } from 'element-plus';
@@ -122,13 +122,21 @@ export default {
122122
this.noteId = firstNote.id;
123123
// CustomMdEditor 会通过 noteId prop 自动加载其内容,
124124
// 并通过 v-model 更新 editorContent。
125-
// 如果 CustomMdEditor 内部加载内容后没有立即通过 emit 更新 modelValue,
126-
// 可能需要在这里手动设置 this.editorContent = firstNote.content;
127-
// 但通常 v-model 组件会处理好双向绑定。
128125
} 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+
}
132140
}
133141
} catch (error) {
134142
console.error("获取关联笔记失败:", error);

0 commit comments

Comments
 (0)