mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-08 01:17:23 +08:00
perf: multiTags route delete realPath
This commit is contained in:
parent
3af52cf6c4
commit
1b052023b6
@ -89,7 +89,7 @@ router.beforeEach((to: toRouteType, _from, next) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
|
// 未开启标签页缓存,刷新页面重定向到顶级路由(参考标签页操作例子,只针对静态路由)
|
||||||
if (to.meta?.realPath) {
|
if (to.meta?.dynamicLevel) {
|
||||||
const routes = router.options.routes;
|
const routes = router.options.routes;
|
||||||
const { refreshRedirect } = to.meta;
|
const { refreshRedirect } = to.meta;
|
||||||
const { name, meta } = findRouteByPath(refreshRedirect, routes);
|
const { name, meta } = findRouteByPath(refreshRedirect, routes);
|
||||||
|
@ -4,6 +4,6 @@ export interface toRouteType extends RouteLocationNormalized {
|
|||||||
meta: {
|
meta: {
|
||||||
keepAlive: boolean;
|
keepAlive: boolean;
|
||||||
refreshRedirect: string;
|
refreshRedirect: string;
|
||||||
realPath: string;
|
dynamicLevel: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -55,31 +55,30 @@ export const useMultiTagsStore = defineStore({
|
|||||||
case "push":
|
case "push":
|
||||||
{
|
{
|
||||||
const tagVal = value as multiType;
|
const tagVal = value as multiType;
|
||||||
|
const tagPath = tagVal?.path;
|
||||||
// 判断tag是否已存在
|
// 判断tag是否已存在
|
||||||
const tagHasExits = this.multiTags.some(tag => {
|
const tagHasExits = this.multiTags.some(tag => {
|
||||||
return tag.path === tagVal?.path;
|
return tag.path === tagPath;
|
||||||
});
|
});
|
||||||
|
|
||||||
// 判断tag中的query键值是否相等
|
// 判断tag中的query键值是否相等
|
||||||
const tagQueryHasExits = this.multiTags.some(tag => {
|
const tagQueryHasExits = this.multiTags.some(tag => {
|
||||||
return isEqual(tag.query, tagVal.query);
|
return isEqual(tag.query, tagVal?.query);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (tagHasExits && tagQueryHasExits) return;
|
if (tagHasExits && tagQueryHasExits) return;
|
||||||
|
|
||||||
const meta = tagVal?.meta;
|
const dynamicLevel = tagVal?.meta?.dynamicLevel ?? -1;
|
||||||
const dynamicLevel = meta?.dynamicLevel ?? -1;
|
|
||||||
if (dynamicLevel > 0) {
|
if (dynamicLevel > 0) {
|
||||||
// dynamicLevel动态路由可打开的数量
|
// dynamicLevel动态路由可打开的数量
|
||||||
const realPath = meta?.realPath ?? "";
|
|
||||||
// 获取到已经打开的动态路由数, 判断是否大于dynamicLevel
|
// 获取到已经打开的动态路由数, 判断是否大于dynamicLevel
|
||||||
if (
|
if (
|
||||||
this.multiTags.filter(e => e.meta?.realPath ?? "" === realPath)
|
this.multiTags.filter(e => e?.path === tagPath).length >=
|
||||||
.length >= dynamicLevel
|
dynamicLevel
|
||||||
) {
|
) {
|
||||||
// 关闭第一个
|
// 关闭第一个
|
||||||
const index = this.multiTags.findIndex(
|
const index = this.multiTags.findIndex(
|
||||||
item => item.meta?.realPath === realPath
|
item => item?.path === tagPath
|
||||||
);
|
);
|
||||||
index !== -1 && this.multiTags.splice(index, 1);
|
index !== -1 && this.multiTags.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ export type multiType = {
|
|||||||
path: string;
|
path: string;
|
||||||
parentPath: string;
|
parentPath: string;
|
||||||
name: string;
|
name: string;
|
||||||
query: object;
|
|
||||||
meta: any;
|
meta: any;
|
||||||
|
query?: object;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type setType = {
|
export type setType = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user