From 216932c32bedde75b8b129021374d00d5b0979fb Mon Sep 17 00:00:00 2001 From: User Date: Mon, 13 Oct 2025 15:58:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=A0=8F=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=9B=B4=E5=90=8D=EF=BC=9B=20=E4=BC=98=E5=8C=96=20=E4=BE=BF?= =?UTF-8?q?=E7=AD=BE=E5=88=97=E8=A1=A8=E9=A1=B5=E5=B8=83=E5=B1=80=E8=B0=83?= =?UTF-8?q?=E6=95=B4=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/{searchBar.vue => Search.vue} | 0 src/pages/NoteEditorPage.vue | 84 +++++++++----------- src/pages/NoteListPage.vue | 8 +- 3 files changed, 42 insertions(+), 50 deletions(-) rename src/components/{searchBar.vue => Search.vue} (100%) diff --git a/src/components/searchBar.vue b/src/components/Search.vue similarity index 100% rename from src/components/searchBar.vue rename to src/components/Search.vue diff --git a/src/pages/NoteEditorPage.vue b/src/pages/NoteEditorPage.vue index 2413a5a..47dd7a1 100644 --- a/src/pages/NoteEditorPage.vue +++ b/src/pages/NoteEditorPage.vue @@ -12,28 +12,8 @@
- +
- - @@ -63,21 +43,21 @@ const editorRef = ref(null) // 设置便签内容的函数 // 用于在编辑器中加载指定便签的内容 -const setNoteContent = async (noteId) => { +const setNoteContent = async noteId => { // 确保store数据已加载,如果便签列表为空则先加载数据 if (store.notes.length === 0) { await store.loadData() console.log('Store loaded, notes count:', store.notes.length) } - + // 从store中查找指定ID的便签 const note = store.notes.find(n => n.id === noteId) console.log('Found note:', note) - + // 确保编辑器已经初始化完成 await nextTick() console.log('Editor ref:', editorRef.value) - + if (note) { console.log('Setting content:', note.content) // 无论editorRef是否可用,都先设置content的值作为备份 @@ -96,7 +76,7 @@ onMounted(async () => { console.log('NoteEditorPage mounted') await store.loadData() console.log('Store loaded, notes count:', store.notes.length) - + // 如果是编辑现有便签,在组件挂载后设置内容 if (noteId.value) { await setNoteContent(noteId.value) @@ -104,19 +84,27 @@ onMounted(async () => { }) // 监听noteId变化,确保在编辑器准备好后设置内容 -watch(noteId, async (newNoteId) => { - console.log('Note ID changed:', newNoteId) - if (newNoteId) { - await setNoteContent(newNoteId) - } -}, { immediate: true }) +watch( + noteId, + async newNoteId => { + console.log('Note ID changed:', newNoteId) + if (newNoteId) { + await setNoteContent(newNoteId) + } + }, + { immediate: true } +) // 监听store变化,确保在store加载后设置内容 -watch(() => store.notes, async (newNotes) => { - if (noteId.value && newNotes.length > 0) { - await setNoteContent(noteId.value) - } -}, { immediate: true }) +watch( + () => store.notes, + async newNotes => { + if (noteId.value && newNotes.length > 0) { + await setNoteContent(noteId.value) + } + }, + { immediate: true } +) // 检查是否正在编辑现有便签 // 如果noteId存在则表示是编辑模式,否则是新建模式 @@ -135,11 +123,15 @@ onMounted(() => { }) // 监听store变化,确保在store加载后设置内容 -watch(() => store.notes, async (newNotes) => { - if (noteId.value && newNotes.length > 0) { - await setNoteContent(noteId.value) - } -}, { immediate: true }) +watch( + () => store.notes, + async newNotes => { + if (noteId.value && newNotes.length > 0) { + await setNoteContent(noteId.value) + } + }, + { immediate: true } +) const showAlert = ref(false) // 防抖函数 @@ -154,14 +146,14 @@ const debounce = (func, delay) => { // 防抖处理内容变化 // 延迟300ms更新内容,避免用户输入时频繁触发更新 -const debouncedHandleContentChange = debounce((newContent) => { +const debouncedHandleContentChange = debounce(newContent => { content.value = newContent console.log('Content updated:', newContent) }, 300) // 监听编辑器内容变化 // 当编辑器内容发生变化时调用此函数 -const handleContentChange = (newContent) => { +const handleContentChange = newContent => { console.log('Editor content changed:', newContent) debouncedHandleContentChange(newContent) } @@ -188,7 +180,7 @@ const handleSave = async () => { try { // 获取编辑器中的实际内容 const editorContent = editorRef.value ? editorRef.value.getContent() : content.value - + if (isEditing && existingNote) { // Update existing note await store.updateNote(noteId.value, { @@ -227,7 +219,7 @@ const handleCreate = async () => { try { // 获取编辑器中的实际内容 const editorContent = editorRef.value ? editorRef.value.getContent() : content.value - + // Create new note await store.addNote({ content: editorContent, diff --git a/src/pages/NoteListPage.vue b/src/pages/NoteListPage.vue index 4ceaf1d..3e448b2 100644 --- a/src/pages/NoteListPage.vue +++ b/src/pages/NoteListPage.vue @@ -12,9 +12,9 @@ :isFolderExpanded="isFolderExpanded" :onTitlePress="handleFolderToggle" slot="fixed" /> - + -
+
-
+
@@ -58,7 +58,7 @@ import { useAppStore } from '../stores/useAppStore' import NoteItem from '../components/NoteItem.vue' import Header from '../components/Header.vue' import FolderManage from '../components/FolderManage.vue' -import SearchBar from '../components/SearchBar.vue' +import SearchBar from '../components/Search.vue' import { formatNoteListDate } from '../utils/dateUtils' import { IonContent, IonPage } from '@ionic/vue'