Commit b8353fe1f262b87cc20af56aaf380ae1a5599724
1 parent
9abba7af
fix: fix menu permission failure
Showing
3 changed files
with
13 additions
and
4 deletions
src/router/menus/index.ts
... | ... | @@ -6,6 +6,7 @@ import { transformMenuModule, flatMenus, getAllParentPath } from '/@/utils/helpe |
6 | 6 | import { filter } from '/@/utils/helper/treeHelper'; |
7 | 7 | import router from '/@/router'; |
8 | 8 | import { PermissionModeEnum } from '/@/enums/appEnum'; |
9 | +import { pathToRegexp } from 'path-to-regexp'; | |
9 | 10 | |
10 | 11 | // =========================== |
11 | 12 | // ==========module import==== |
... | ... | @@ -106,9 +107,14 @@ export async function getFlatChildrenMenus(children: Menu[]) { |
106 | 107 | // 通用过滤方法 |
107 | 108 | function basicFilter(routes: RouteRecordNormalized[]) { |
108 | 109 | return (menu: Menu) => { |
109 | - const matchRoute = routes.find((route) => route.path === menu.path); | |
110 | - | |
111 | - if (!matchRoute) return true; | |
110 | + const matchRoute = routes.find((route) => { | |
111 | + if (route.meta && route.meta.carryParam) { | |
112 | + return pathToRegexp(route.path).test(menu.path); | |
113 | + } | |
114 | + return route.path === menu.path; | |
115 | + }); | |
116 | + | |
117 | + if (!matchRoute) return false; | |
112 | 118 | menu.icon = menu.icon || matchRoute.meta.icon; |
113 | 119 | menu.meta = matchRoute.meta; |
114 | 120 | return true; | ... | ... |
src/router/routes/modules/demo/feat.ts
src/router/types.d.ts
... | ... | @@ -29,8 +29,10 @@ export interface RouteMeta { |
29 | 29 | |
30 | 30 | // close loading |
31 | 31 | afterCloseLoading?: boolean; |
32 | - | |
32 | + // Is it in the tab | |
33 | 33 | inTab?: boolean; |
34 | + // Carrying parameters | |
35 | + carryParam?: boolean; | |
34 | 36 | } |
35 | 37 | |
36 | 38 | export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> { | ... | ... |