diff --git a/mes-ui/mes-ui-admin-vue3/src/store/modules/tagsView.ts b/mes-ui/mes-ui-admin-vue3/src/store/modules/tagsView.ts index 91de7581..1b3ca693 100644 --- a/mes-ui/mes-ui-admin-vue3/src/store/modules/tagsView.ts +++ b/mes-ui/mes-ui-admin-vue3/src/store/modules/tagsView.ts @@ -60,18 +60,23 @@ export const useTagsViewStore = defineStore('tagsView', { delView(view: RouteLocationNormalizedLoaded) { this.delVisitedView(view) this.delCachedView() - routeParamsCache.remove(view.path) + setTimeout(() => { + routeParamsCache.remove(view.path) + }, 300) }, // 删除tag delVisitedView(view: RouteLocationNormalizedLoaded) { + const list = []; for (const [i, v] of this.visitedViews.entries()) { if (v.path === view.path) { - this.visitedViews.splice(i, 1) - routeParamsCache.remove(view.path) + list.push(view.path); break } } + setTimeout(() => { + routeParamsCache.removeBatch(list) + }, 300) }, // 删除缓存 delCachedView() { diff --git a/mes-ui/mes-ui-admin-vue3/src/utils/routeParamsCache.ts b/mes-ui/mes-ui-admin-vue3/src/utils/routeParamsCache.ts index eb191e01..a707ff09 100644 --- a/mes-ui/mes-ui-admin-vue3/src/utils/routeParamsCache.ts +++ b/mes-ui/mes-ui-admin-vue3/src/utils/routeParamsCache.ts @@ -1,7 +1,7 @@ import { pa } from 'element-plus/es/locale'; import { reactive } from 'vue'; // import type { String } from 'vue-router'; - + export type QueryParams = { pageNo: number; pageSize: number; @@ -41,11 +41,11 @@ const saveCache = (cache: Map) => { ); sessionStorage.setItem(ROUTE_PARAMS_CACHE_KEY, JSON.stringify(serializable)); }; - + const initCache = (): Map => { const cached = sessionStorage.getItem(ROUTE_PARAMS_CACHE_KEY); if (!cached) return new Map(); - + try { const parsed = JSON.parse(cached); return new Map( @@ -73,9 +73,8 @@ const routeParamsCache = { timestamp: Date.now(), }; this.cache.set(path, cachedParams); - saveCache(this.cache); }, - + get(route: String) { const path = getCacheKey(route); return this.cache.get(path)?.queryParams; // 简化返回 @@ -90,7 +89,17 @@ const routeParamsCache = { } return false; }, + removeBatch(routeArrary: []) { + routeArrary.forEach(route =>{ + const path = getCacheKey(route); + if (this.cache.has(path)) { + this.cache.delete(path); + saveCache(this.cache); + + } + }) + }, cleanExpired(expireHours = DEFAULT_EXPIRE_HOURS) { const now = Date.now(); const expired = Array.from(this.cache.entries()).filter( @@ -106,4 +115,4 @@ const routeParamsCache = { }, }; -export default routeParamsCache; \ No newline at end of file +export default routeParamsCache;