fix: 提前实现localStorage管理方法
- 添加saveImportTaskToStorage方法 - 添加getImportTaskFromStorage方法 - 添加clearImportTaskFromStorage方法 - 修复lastImportInfo计算属性无法运行的问题 这些方法原本计划在Task 5-7实现,提前到现在以修复Task 2的审查问题。 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -993,6 +993,68 @@ export default {
|
|||||||
handleImportDialogClose() {
|
handleImportDialogClose() {
|
||||||
this.upload.isUploading = false;
|
this.upload.isUploading = false;
|
||||||
this.$refs.upload.clearFiles();
|
this.$refs.upload.clearFiles();
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 保存导入任务到localStorage
|
||||||
|
* @param {Object} taskData - 任务数据
|
||||||
|
*/
|
||||||
|
saveImportTaskToStorage(taskData) {
|
||||||
|
try {
|
||||||
|
const data = {
|
||||||
|
...taskData,
|
||||||
|
saveTime: Date.now()
|
||||||
|
};
|
||||||
|
localStorage.setItem('purchase_transaction_import_last_task', JSON.stringify(data));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('保存导入任务状态失败:', error);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 从localStorage读取导入任务
|
||||||
|
* @returns {Object|null} 任务数据或null
|
||||||
|
*/
|
||||||
|
getImportTaskFromStorage() {
|
||||||
|
try {
|
||||||
|
const data = localStorage.getItem('purchase_transaction_import_last_task');
|
||||||
|
if (!data) return null;
|
||||||
|
|
||||||
|
const task = JSON.parse(data);
|
||||||
|
|
||||||
|
// 数据格式校验
|
||||||
|
if (!task || !task.taskId) {
|
||||||
|
this.clearImportTaskFromStorage();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 时间戳校验
|
||||||
|
if (task.saveTime && typeof task.saveTime !== 'number') {
|
||||||
|
this.clearImportTaskFromStorage();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过期检查(7天)
|
||||||
|
const sevenDays = 7 * 24 * 60 * 60 * 1000;
|
||||||
|
if (Date.now() - task.saveTime > sevenDays) {
|
||||||
|
this.clearImportTaskFromStorage();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return task;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('读取导入任务状态失败:', error);
|
||||||
|
this.clearImportTaskFromStorage();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 清除localStorage中的导入任务
|
||||||
|
*/
|
||||||
|
clearImportTaskFromStorage() {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem('purchase_transaction_import_last_task');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('清除导入任务状态失败:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user