diff --git a/src/components/BackupPanel.spec.ts b/src/components/BackupPanel.spec.ts index 77203bd..85b730a 100644 --- a/src/components/BackupPanel.spec.ts +++ b/src/components/BackupPanel.spec.ts @@ -118,6 +118,7 @@ describe('BackupPanel 导入', () => { expect(store.tasks.map((task) => task.title).sort()).toEqual(['新任务一', '新任务二']) expect(wrapper.text()).toContain('已从 backup.json 导入 2 个任务') + expect(wrapper.text()).toContain('导入前的数据已自动备份') }) it('取消确认后数据保持不变', async () => { diff --git a/src/components/BackupPanel.vue b/src/components/BackupPanel.vue index 7b7f493..f68c0d1 100644 --- a/src/components/BackupPanel.vue +++ b/src/components/BackupPanel.vue @@ -59,9 +59,13 @@ function confirmImport(): void { const target = pending.value if (!target) return + // 记录导入前的数量,用于提示「旧数据已自动备份」是否真的发生了 + const beforeCount = store.tasks.length + try { const count = store.importJson(target.text) - message.value = `已从 ${target.fileName} 导入 ${count} 个任务` + const backupNote = beforeCount > 0 ? ',导入前的数据已自动备份' : '' + message.value = `已从 ${target.fileName} 导入 ${count} 个任务${backupNote}` error.value = null } catch (cause) { error.value = cause instanceof Error ? cause.message : '导入失败' @@ -71,9 +75,12 @@ function confirmImport(): void { } function restore(key: string): void { + const beforeCount = store.tasks.length try { const count = store.restoreSnapshot(key) - message.value = count > 0 ? `已从备份恢复 ${count} 个任务` : '该备份是空的,未做改动' + const backupNote = beforeCount > 0 ? ',恢复前的数据已自动备份' : '' + message.value = + count > 0 ? `已从备份恢复 ${count} 个任务${backupNote}` : '该备份是空的,未做改动' error.value = null } catch (cause) { error.value = cause instanceof Error ? cause.message : '恢复失败' @@ -137,7 +144,8 @@ function formatTime(iso: string): string { >

将从「{{ pending.fileName }}」导入 {{ pending.count }} 个任务, - 并覆盖当前全部 {{ store.tasks.length }} 个任务。此操作不可撤销。 + 并覆盖当前全部 {{ store.tasks.length }} 个任务。 覆盖前会自动把当前数据 + 存一份到下方「自动备份」,选错文件也能从那里恢复。