Skip to content

Commit

Permalink
perf: 优化获取顶级菜单逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxian521 committed Apr 15, 2024
1 parent 0934c97 commit 699b174
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 699b174

Please sign in to comment.