清除缓存新增批量清楚
This commit is contained in:
		
							parent
							
								
									b8dcd6d572
								
							
						
					
					
						commit
						0a2e4647e8
					
				@ -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() {
 | 
			
		||||
 | 
			
		||||
@ -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<string, CachedParams>) => {
 | 
			
		||||
  );
 | 
			
		||||
  sessionStorage.setItem(ROUTE_PARAMS_CACHE_KEY, JSON.stringify(serializable));
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
 | 
			
		||||
const initCache = (): Map<string, CachedParams> => {
 | 
			
		||||
  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;
 | 
			
		||||
export default routeParamsCache;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user