mirror of
https://github.com/vbenjs/vben-admin-thin-next.git
synced 2025-01-24 02:00:22 +08:00
fix: fix menu permission failure
This commit is contained in:
parent
9abba7af3e
commit
b8353fe1f2
@ -6,6 +6,7 @@ import { transformMenuModule, flatMenus, getAllParentPath } from '/@/utils/helpe
|
|||||||
import { filter } from '/@/utils/helper/treeHelper';
|
import { filter } from '/@/utils/helper/treeHelper';
|
||||||
import router from '/@/router';
|
import router from '/@/router';
|
||||||
import { PermissionModeEnum } from '/@/enums/appEnum';
|
import { PermissionModeEnum } from '/@/enums/appEnum';
|
||||||
|
import { pathToRegexp } from 'path-to-regexp';
|
||||||
|
|
||||||
// ===========================
|
// ===========================
|
||||||
// ==========module import====
|
// ==========module import====
|
||||||
@ -106,9 +107,14 @@ export async function getFlatChildrenMenus(children: Menu[]) {
|
|||||||
// 通用过滤方法
|
// 通用过滤方法
|
||||||
function basicFilter(routes: RouteRecordNormalized[]) {
|
function basicFilter(routes: RouteRecordNormalized[]) {
|
||||||
return (menu: Menu) => {
|
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.icon = menu.icon || matchRoute.meta.icon;
|
||||||
menu.meta = matchRoute.meta;
|
menu.meta = matchRoute.meta;
|
||||||
return true;
|
return true;
|
||||||
|
@ -102,6 +102,7 @@ export default {
|
|||||||
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
|
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Tab带参',
|
title: 'Tab带参',
|
||||||
|
carryParam: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
4
src/router/types.d.ts
vendored
4
src/router/types.d.ts
vendored
@ -29,8 +29,10 @@ export interface RouteMeta {
|
|||||||
|
|
||||||
// close loading
|
// close loading
|
||||||
afterCloseLoading?: boolean;
|
afterCloseLoading?: boolean;
|
||||||
|
// Is it in the tab
|
||||||
inTab?: boolean;
|
inTab?: boolean;
|
||||||
|
// Carrying parameters
|
||||||
|
carryParam?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
|
export interface AppRouteRecordRaw extends Omit<RouteRecordRaw, 'meta'> {
|
||||||
|
Loading…
Reference in New Issue
Block a user