diff --git a/frontend/src/layout/components/Sidebar/components/Collapse.vue b/frontend/src/layout/components/Sidebar/components/Collapse.vue index 7b46f32e0..8b09c4d95 100644 --- a/frontend/src/layout/components/Sidebar/components/Collapse.vue +++ b/frontend/src/layout/components/Sidebar/components/Collapse.vue @@ -238,6 +238,10 @@ const logout = () => { }) .then(async () => { await logOutApi(); + sessionStorage.removeItem('dashboardCache'); + localStorage.removeItem('dashboardCache'); + sessionStorage.removeItem('upgradeChecked'); + localStorage.removeItem('upgradeChecked'); router.push({ name: 'entrance', params: { code: globalStore.entrance } }); globalStore.setLogStatus(false); MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); diff --git a/frontend/src/utils/dashboardCache.ts b/frontend/src/utils/dashboardCache.ts new file mode 100644 index 000000000..2755ca7c8 --- /dev/null +++ b/frontend/src/utils/dashboardCache.ts @@ -0,0 +1,61 @@ +const DASHBOARD_CACHE_KEY = 'dashboardCache'; + +type CacheEntry = { + value: any; + expireAt: number; +}; + +const readCache = (): Record | null => { + try { + const cacheRaw = localStorage.getItem(DASHBOARD_CACHE_KEY); + return cacheRaw ? JSON.parse(cacheRaw) : {}; + } catch { + return null; + } +}; + +export const getDashboardCache = (key: string) => { + const cache = readCache(); + if (!cache) return null; + const entry = cache[key]; + if (entry && entry.expireAt > Date.now()) { + return entry.value; + } + return null; +}; + +export const setDashboardCache = (key: string, value: any, ttl: number) => { + try { + const cacheRaw = localStorage.getItem(DASHBOARD_CACHE_KEY); + const cache = cacheRaw ? JSON.parse(cacheRaw) : {}; + cache[key] = { + value, + expireAt: Date.now() + ttl, + }; + localStorage.setItem(DASHBOARD_CACHE_KEY, JSON.stringify(cache)); + } catch { + localStorage.removeItem(DASHBOARD_CACHE_KEY); + } +}; + +export const clearDashboardCache = () => { + localStorage.removeItem(DASHBOARD_CACHE_KEY); +}; + +export const clearDashboardCacheByPrefix = (prefixes: string[]) => { + try { + const cacheRaw = localStorage.getItem(DASHBOARD_CACHE_KEY); + if (!cacheRaw) return; + const cache = JSON.parse(cacheRaw); + Object.keys(cache).forEach((key: string) => { + if (prefixes.some((prefix) => key.startsWith(prefix))) { + delete cache[key]; + } + }); + localStorage.setItem(DASHBOARD_CACHE_KEY, JSON.stringify(cache)); + } catch { + clearDashboardCache(); + } +}; + +export { DASHBOARD_CACHE_KEY }; diff --git a/frontend/src/views/home/app/index.vue b/frontend/src/views/home/app/index.vue index 1a44d1fc9..be5ae93fa 100644 --- a/frontend/src/views/home/app/index.vue +++ b/frontend/src/views/home/app/index.vue @@ -1,7 +1,13 @@