From 517ee39707f2d7de89228e1d0a1148524ab2ca0d Mon Sep 17 00:00:00 2001 From: Julian Freeman Date: Tue, 31 Mar 2026 18:28:07 -0400 Subject: [PATCH] not sync after every install --- src/store/software.ts | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/store/software.ts b/src/store/software.ts index f55a93a..548b51f 100644 --- a/src/store/software.ts +++ b/src/store/software.ts @@ -45,7 +45,8 @@ export const useSoftwareStore = defineStore('software', { loading: false, isInitialized: false, initStatus: '正在检查系统环境...', - lastFetched: 0 + lastFetched: 0, + refreshTimer: null as any }), getters: { mergedEssentials: (state) => { @@ -244,6 +245,26 @@ export const useSoftwareStore = defineStore('software', { } } }, + + // 引入防抖刷新:在批量安装期间,仅在最后一次成功后的 5 秒执行全量扫描 + scheduleDataRefresh() { + if (this.refreshTimer) clearTimeout(this.refreshTimer); + + this.refreshTimer = setTimeout(async () => { + // 执行全量刷新 + await this.fetchAllData(); + + // 刷新完成后清理所有已成功的任务状态,让卡片恢复正常显示 + Object.keys(this.activeTasks).forEach(id => { + if (this.activeTasks[id].status === 'success') { + delete this.activeTasks[id]; + } + }); + + this.refreshTimer = null; + }, 5000); + }, + findSoftware(id: string) { return this.essentials.find(s => s.id === id) || this.updates.find(s => s.id === id) || @@ -260,15 +281,12 @@ export const useSoftwareStore = defineStore('software', { if (status === 'success') { this.lastFetched = 0; + // 立即更新勾选状态,提升响应感 this.selectedEssentialIds = this.selectedEssentialIds.filter(i => i !== id); this.selectedUpdateIds = this.selectedUpdateIds.filter(i => i !== id); - setTimeout(() => { - if (this.activeTasks[id]?.status === 'success') { - delete this.activeTasks[id]; - this.fetchAllData(); - } - }, 3000); + // 触发防抖刷新 + this.scheduleDataRefresh(); } })