From 553caa5307ba09503086ed3d7b490b10153c310e Mon Sep 17 00:00:00 2001 From: Hooray <304327508@qq.com> Date: Thu, 7 Nov 2024 23:37:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E8=B7=AF=E7=94=B1=E6=A8=A1=E5=BC=8F=E4=B8=8B=E4=B8=BB?= =?UTF-8?q?=E5=AF=BC=E8=88=AA=E9=AB=98=E4=BA=AE=E6=95=88=E6=9E=9C=E4=B8=8D?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/menu.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index 0dee817e..6c912bd6 100755 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -188,6 +188,16 @@ const useMenuStore = defineStore( }).catch(() => {}) } // 设置主导航 + function isPathInMenus(menus: Menu.recordRaw[], path: string) { + let flag = false + flag = menus.some((item) => { + if (item.children) { + return isPathInMenus(item.children, path) + } + return path.indexOf(`${item.path}/`) === 0 || path === item.path + }) + return flag + } function setActived(data: number | string) { if (typeof data === 'number') { // 如果是 number 类型,则认为是主导航的索引 @@ -195,7 +205,7 @@ const useMenuStore = defineStore( } else { // 如果是 string 类型,则认为是路由,需要查找对应的主导航索引 - const findIndex = allMenus.value.findIndex(item => item.children.some(r => data.indexOf(`${r.path}/`) === 0 || data === r.path)) + const findIndex = allMenus.value.findIndex(item => isPathInMenus(item.children, data)) if (findIndex >= 0) { actived.value = findIndex }