perf: 优化获取顶级菜单逻辑

This commit is contained in:
xiaoxian521 2024-04-15 11:15:57 +08:00
parent 0934c97413
commit 699b174f95

View File

@ -367,9 +367,23 @@ function hasAuth(value: string | Array<string>): boolean {
return isAuths ? true : false;
}
function handleTopMenu(route) {
if (route?.children && route.children.length > 1) {
if (route.redirect) {
return route.children.filter(cur => cur.path === route.redirect)[0];
} else {
return route.children[0];
}
} else {
return route;
}
}
/** 获取所有菜单中的第一个菜单(顶级菜单)*/
function getTopMenu(tag = false): menuType {
const topMenu = usePermissionStoreHook().wholeMenus[0]?.children[0];
const topMenu = handleTopMenu(
usePermissionStoreHook().wholeMenus[0]?.children[0]
);
tag && useMultiTagsStoreHook().handleTags("push", topMenu);
return topMenu;
}