fix(biji): 优化笔记编辑器自动保存机制并修复相关问题
- 实现了更可靠的自动保存功能,仅在用户停止输入后触发保存操作 - 修复了切换笔记时意外触发自动保存的问题 - 优化了重命名文件后的预览更新逻辑 - 调整了保存成功后的状态清理策略,提高了用户体验
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
v-if="showEditor"
|
||||
:edit-data="editData"
|
||||
@back="handleEditorBack"
|
||||
@save-success="handleSaveSuccess"
|
||||
@update:edit-data="handleSaveSuccess"
|
||||
/>
|
||||
|
||||
<!-- Note Preview View -->
|
||||
@@ -188,6 +188,10 @@ const showPrivacyDialog = ref(false);
|
||||
const itemToRename = ref(null);
|
||||
const fileToImport = ref(null);
|
||||
|
||||
const resetEdit = () => {
|
||||
editData.value = null;
|
||||
};
|
||||
|
||||
// --- Core Logic ---
|
||||
|
||||
// Data Fetching
|
||||
@@ -225,6 +229,7 @@ const buildTree = (items) => {
|
||||
};
|
||||
|
||||
const resetToHomeView = async () => {
|
||||
resetEdit();
|
||||
selectedFile.value = null;
|
||||
showEditor.value = false;
|
||||
searchKeyword.value = '';
|
||||
@@ -239,6 +244,7 @@ const resetToHomeView = async () => {
|
||||
|
||||
// Event Handlers from Components
|
||||
const handleSelectFile = async (data) => {
|
||||
resetEdit();
|
||||
try {
|
||||
const files = await markdownList(data.id);
|
||||
groupMarkdownFiles.value = files || [];
|
||||
@@ -257,6 +263,7 @@ const handleGroupDeleted = async () => {
|
||||
};
|
||||
|
||||
const handleCreateNote = (payload) => {
|
||||
resetEdit();
|
||||
editData.value = payload;
|
||||
showEditor.value = true;
|
||||
selectedFile.value = null; // Ensure preview is hidden
|
||||
@@ -268,24 +275,27 @@ const handleEditorBack = (data) => {
|
||||
};
|
||||
|
||||
const handleSaveSuccess = (updatedFile) => {
|
||||
editData.value = null; // Clear edit data
|
||||
selectedFile.value = updatedFile; // Update the selected file to show the preview
|
||||
showEditor.value = false; // Hide the editor
|
||||
selectedFile.value = updatedFile;
|
||||
showEditor.value = false;
|
||||
|
||||
// Find the file in the current list and update it
|
||||
const index = groupMarkdownFiles.value.findIndex(f => f.id === updatedFile.id);
|
||||
if (index !== -1) {
|
||||
groupMarkdownFiles.value[index] = updatedFile;
|
||||
} else {
|
||||
// If the file is new (or not in the current list), add it to the top
|
||||
groupMarkdownFiles.value.unshift(updatedFile);
|
||||
}
|
||||
|
||||
// Also refresh the category tree to reflect new file counts or changes
|
||||
fetchGroupings();
|
||||
|
||||
// 延迟清空 editData,确保所有响应式更新完成后再清理状态
|
||||
// Delay clearing editData to ensure all reactive updates are complete before cleaning up the state.
|
||||
setTimeout(() => {
|
||||
resetEdit();
|
||||
}, 100); // A short delay is usually sufficient
|
||||
};
|
||||
|
||||
const previewFile = async (file) => {
|
||||
resetEdit();
|
||||
if (!file || file.id === null) {
|
||||
editData.value = file;
|
||||
selectedFile.value = null;
|
||||
@@ -328,12 +338,20 @@ const openRenameDialog = (item, type) => {
|
||||
showRenameDialog.value = true;
|
||||
};
|
||||
|
||||
const handleRenamed = async () => {
|
||||
const handleRenamed = async (newName) => {
|
||||
await fetchGroupings();
|
||||
if (selectedFile.value && itemToRename.value.type === 'file' && selectedFile.value.id === itemToRename.value.id) {
|
||||
previewFile(selectedFile.value); // Refresh preview
|
||||
// 直接更新当前选中文件的标题
|
||||
selectedFile.value.title = newName;
|
||||
// 更新笔记列表中的对应项
|
||||
const index = groupMarkdownFiles.value.findIndex(f => f.id === selectedFile.value.id);
|
||||
if (index !== -1) {
|
||||
groupMarkdownFiles.value[index].title = newName;
|
||||
}
|
||||
// 重新获取文件内容以确保是最新的
|
||||
previewFile(selectedFile.value); // Refresh preview
|
||||
} else {
|
||||
resetToHomeView();
|
||||
resetToHomeView();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user