Skip to content

Commit 7413ddb

Browse files
committed
fix: outline auto-save now works when recordId is missing (closes #47)
- autoSaveOutline() now creates a history record as fallback when recordId is null, instead of silently skipping the save - onMounted properly awaits checkAndCreateHistory() to ensure recordId exists before watch triggers auto-save
1 parent 80a8ca7 commit 7413ddb

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

frontend/src/views/OutlineView.vue

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,31 @@ let saveTimer: number | null = null
154154
* 当大纲内容发生变化时,自动更新到后端
155155
*/
156156
const autoSaveOutline = async () => {
157-
// 如果没有 recordId,说明还未创建历史记录,无法自动保存
157+
// 如果没有 recordId,尝试创建历史记录
158158
if (!store.recordId) {
159-
console.warn('未找到历史记录ID,无法自动保存')
160-
return
159+
if (store.outline.pages && store.outline.pages.length > 0) {
160+
try {
161+
const result = await createHistory(
162+
store.topic || '未命名主题',
163+
{
164+
raw: store.outline.raw,
165+
pages: store.outline.pages
166+
},
167+
store.taskId || undefined
168+
)
169+
if (result.success && result.record_id) {
170+
store.setRecordId(result.record_id)
171+
} else {
172+
console.warn('自动保存:创建历史记录失败')
173+
return
174+
}
175+
} catch (error) {
176+
console.error('自动保存:创建历史记录出错:', error)
177+
return
178+
}
179+
} else {
180+
return
181+
}
161182
}
162183
163184
// 如果没有大纲内容,不需要保存
@@ -243,8 +264,8 @@ const checkAndCreateHistory = async () => {
243264
}
244265
245266
// 组件挂载时检查历史记录
246-
onMounted(() => {
247-
checkAndCreateHistory()
267+
onMounted(async () => {
268+
await checkAndCreateHistory()
248269
})
249270
250271
// 组件卸载时清理定时器

0 commit comments

Comments
 (0)