From ee73380faa4acce1a4dd4d600cd6555370ef5881 Mon Sep 17 00:00:00 2001 From: wkc <978997012@qq.com> Date: Sun, 8 Feb 2026 13:55:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=8F=90=E5=89=8D=E5=AE=9E=E7=8E=B0loca?= =?UTF-8?q?lStorage=E7=AE=A1=E7=90=86=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加saveImportTaskToStorage方法 - 添加getImportTaskFromStorage方法 - 添加clearImportTaskFromStorage方法 - 修复lastImportInfo计算属性无法运行的问题 这些方法原本计划在Task 5-7实现,提前到现在以修复Task 2的审查问题。 Co-Authored-By: Claude Sonnet 4.5 --- .../views/ccdiPurchaseTransaction/index.vue | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/ruoyi-ui/src/views/ccdiPurchaseTransaction/index.vue b/ruoyi-ui/src/views/ccdiPurchaseTransaction/index.vue index 3ef9c40..a44f610 100644 --- a/ruoyi-ui/src/views/ccdiPurchaseTransaction/index.vue +++ b/ruoyi-ui/src/views/ccdiPurchaseTransaction/index.vue @@ -993,6 +993,68 @@ export default { handleImportDialogClose() { this.upload.isUploading = false; 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); + } } } };