diff --git a/src/store/modules/permission.ts b/src/store/modules/permission.ts index 97bc7cd9b..b5e3b5dee 100644 --- a/src/store/modules/permission.ts +++ b/src/store/modules/permission.ts @@ -2,7 +2,6 @@ import { defineStore } from "pinia"; import { type cacheType, store, - debounce, ascending, getKeyList, filterTree, @@ -33,33 +32,35 @@ export const usePermissionStore = defineStore("pure-permission", { this.constantMenus.concat(routes) as any ); }, + /** 监听缓存页面是否存在于标签页,不存在则删除 */ + clearCache() { + let cacheLength = this.cachePageList.length; + const nameList = getKeyList(useMultiTagsStoreHook().multiTags, "name"); + while (cacheLength > 0) { + nameList.findIndex(v => v === this.cachePageList[cacheLength - 1]) === + -1 && + this.cachePageList.splice( + this.cachePageList.indexOf(this.cachePageList[cacheLength - 1]), + 1 + ); + cacheLength--; + } + }, cacheOperate({ mode, name }: cacheType) { const delIndex = this.cachePageList.findIndex(v => v === name); switch (mode) { case "refresh": this.cachePageList = this.cachePageList.filter(v => v !== name); + this.clearCache(); break; case "add": this.cachePageList.push(name); break; case "delete": delIndex !== -1 && this.cachePageList.splice(delIndex, 1); + this.clearCache(); break; } - /** 监听缓存页面是否存在于标签页,不存在则删除 */ - debounce(() => { - let cacheLength = this.cachePageList.length; - const nameList = getKeyList(useMultiTagsStoreHook().multiTags, "name"); - while (cacheLength > 0) { - nameList.findIndex(v => v === this.cachePageList[cacheLength - 1]) === - -1 && - this.cachePageList.splice( - this.cachePageList.indexOf(this.cachePageList[cacheLength - 1]), - 1 - ); - cacheLength--; - } - })(); }, /** 清空缓存页面 */ clearAllCachePage() {