From 08d6f4fd588dc2d11bb99dbba0bbc48e770f0bf2 Mon Sep 17 00:00:00 2001 From: Dane <875126243@qq.com> Date: Thu, 24 Aug 2023 11:21:34 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=AD=90=E9=9B=86=E8=8F=9C=E5=8D=95=E6=9D=83?= =?UTF-8?q?=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/router/index.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/admin/src/router/index.ts b/admin/src/router/index.ts index ba004d088..967b69f3e 100644 --- a/admin/src/router/index.ts +++ b/admin/src/router/index.ts @@ -84,10 +84,26 @@ export function findFirstValidRoute(routes: RouteRecordRaw[]): string | undefine } } } +// 递归检测 +const findPathWithPermission = (arr: any[], searchString: string) => { + for (const item of arr) { + if (item.meta && item.meta.perms && item.meta.perms.includes(searchString)) { + return item.path || ''; // 返回找到的项的路径,如果没有路径则返回空字符串 + } + if (item.children && Array.isArray(item.children)) { + const pathInChildren: string = findPathWithPermission(item.children, searchString); + if (pathInChildren) { + return pathInChildren; + } + } + } + return ''; // 没有找到匹配项,返回空字符串 +} + //通过权限字符查询路由路径 export function getRoutePath(perms: string) { const routerObj = useRouter() || router - return routerObj.getRoutes().find((item) => item.meta?.perms == perms)?.path || '' + return findPathWithPermission(routerObj.getRoutes(), perms) } // 重置路由