From 699b174f95ffb26d50210a3d938eabd1f265eb98 Mon Sep 17 00:00:00 2001 From: xiaoxian521 <1923740402@qq.com> Date: Mon, 15 Apr 2024 11:15:57 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E9=A1=B6=E7=BA=A7=E8=8F=9C=E5=8D=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/utils.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/router/utils.ts b/src/router/utils.ts index ba5a29d32..35065c723 100644 --- a/src/router/utils.ts +++ b/src/router/utils.ts @@ -367,9 +367,23 @@ function hasAuth(value: string | Array): 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; }