+
### Use Gitpod diff --git a/README.md b/README.md index 4cc9bd0b4..8083c9b87 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ UI 设计:+
### 使用 Gitpod From 1b052023b6215968ac368c6a069a72c5d05fcab2 Mon Sep 17 00:00:00 2001 From: lrl <742798240@qq.com> Date: Mon, 20 Dec 2021 22:14:26 +0800 Subject: [PATCH 3/3] perf: multiTags route delete realPath --- src/router/index.ts | 2 +- src/router/types.ts | 2 +- src/store/modules/multiTags.ts | 15 +++++++-------- src/store/modules/types.ts | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index d2fbc115f..74b04bf16 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -89,7 +89,7 @@ router.beforeEach((to: toRouteType, _from, next) => { }); }; // 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由) - if (to.meta?.realPath) { + if (to.meta?.dynamicLevel) { const routes = router.options.routes; const { refreshRedirect } = to.meta; const { name, meta } = findRouteByPath(refreshRedirect, routes); diff --git a/src/router/types.ts b/src/router/types.ts index 0577e04de..fa4e103dd 100644 --- a/src/router/types.ts +++ b/src/router/types.ts @@ -4,6 +4,6 @@ export interface toRouteType extends RouteLocationNormalized { meta: { keepAlive: boolean; refreshRedirect: string; - realPath: string; + dynamicLevel: string; }; } diff --git a/src/store/modules/multiTags.ts b/src/store/modules/multiTags.ts index 4ad05296b..64a31f578 100644 --- a/src/store/modules/multiTags.ts +++ b/src/store/modules/multiTags.ts @@ -55,31 +55,30 @@ export const useMultiTagsStore = defineStore({ case "push": { const tagVal = value as multiType; + const tagPath = tagVal?.path; // 判断tag是否已存在 const tagHasExits = this.multiTags.some(tag => { - return tag.path === tagVal?.path; + return tag.path === tagPath; }); // 判断tag中的query键值是否相等 const tagQueryHasExits = this.multiTags.some(tag => { - return isEqual(tag.query, tagVal.query); + return isEqual(tag.query, tagVal?.query); }); if (tagHasExits && tagQueryHasExits) return; - const meta = tagVal?.meta; - const dynamicLevel = meta?.dynamicLevel ?? -1; + const dynamicLevel = tagVal?.meta?.dynamicLevel ?? -1; if (dynamicLevel > 0) { // dynamicLevel动态路由可打开的数量 - const realPath = meta?.realPath ?? ""; // 获取到已经打开的动态路由数, 判断是否大于dynamicLevel if ( - this.multiTags.filter(e => e.meta?.realPath ?? "" === realPath) - .length >= dynamicLevel + this.multiTags.filter(e => e?.path === tagPath).length >= + dynamicLevel ) { // 关闭第一个 const index = this.multiTags.findIndex( - item => item.meta?.realPath === realPath + item => item?.path === tagPath ); index !== -1 && this.multiTags.splice(index, 1); } diff --git a/src/store/modules/types.ts b/src/store/modules/types.ts index 644ce8622..c5eb062bd 100644 --- a/src/store/modules/types.ts +++ b/src/store/modules/types.ts @@ -25,8 +25,8 @@ export type multiType = { path: string; parentPath: string; name: string; - query: object; meta: any; + query?: object; }; export type setType = {