From b8353fe1f262b87cc20af56aaf380ae1a5599724 Mon Sep 17 00:00:00 2001 From: vben Date: Wed, 14 Oct 2020 22:08:56 +0800 Subject: [PATCH] fix: fix menu permission failure --- src/router/menus/index.ts | 10 ++++++++-- src/router/routes/modules/demo/feat.ts | 1 + src/router/types.d.ts | 4 +++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/router/menus/index.ts b/src/router/menus/index.ts index 7a2934df..7600b619 100644 --- a/src/router/menus/index.ts +++ b/src/router/menus/index.ts @@ -6,6 +6,7 @@ import { transformMenuModule, flatMenus, getAllParentPath } from '/@/utils/helpe import { filter } from '/@/utils/helper/treeHelper'; import router from '/@/router'; import { PermissionModeEnum } from '/@/enums/appEnum'; +import { pathToRegexp } from 'path-to-regexp'; // =========================== // ==========module import==== @@ -106,9 +107,14 @@ export async function getFlatChildrenMenus(children: Menu[]) { // 通用过滤方法 function basicFilter(routes: RouteRecordNormalized[]) { return (menu: Menu) => { - const matchRoute = routes.find((route) => route.path === menu.path); + const matchRoute = routes.find((route) => { + if (route.meta && route.meta.carryParam) { + return pathToRegexp(route.path).test(menu.path); + } + return route.path === menu.path; + }); - if (!matchRoute) return true; + if (!matchRoute) return false; menu.icon = menu.icon || matchRoute.meta.icon; menu.meta = matchRoute.meta; return true; diff --git a/src/router/routes/modules/demo/feat.ts b/src/router/routes/modules/demo/feat.ts index 1725a6c2..3cec49d9 100644 --- a/src/router/routes/modules/demo/feat.ts +++ b/src/router/routes/modules/demo/feat.ts @@ -102,6 +102,7 @@ export default { component: () => import('/@/views/demo/feat/tab-params/index.vue'), meta: { title: 'Tab带参', + carryParam: true, }, }, ], diff --git a/src/router/types.d.ts b/src/router/types.d.ts index e3fe4052..84969fc3 100644 --- a/src/router/types.d.ts +++ b/src/router/types.d.ts @@ -29,8 +29,10 @@ export interface RouteMeta { // close loading afterCloseLoading?: boolean; - + // Is it in the tab inTab?: boolean; + // Carrying parameters + carryParam?: boolean; } export interface AppRouteRecordRaw extends Omit {