perf: multiTags route delete realPath

This commit is contained in:
lrl 2021-12-20 22:14:26 +08:00 committed by 啝裳
parent 3af52cf6c4
commit 1b052023b6
4 changed files with 10 additions and 11 deletions

View File

@ -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);

View File

@ -4,6 +4,6 @@ export interface toRouteType extends RouteLocationNormalized {
meta: {
keepAlive: boolean;
refreshRedirect: string;
realPath: string;
dynamicLevel: string;
};
}

View File

@ -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);
}

View File

@ -25,8 +25,8 @@ export type multiType = {
path: string;
parentPath: string;
name: string;
query: object;
meta: any;
query?: object;
};
export type setType = {