fix: fix menu permission failure

This commit is contained in:
vben 2020-10-14 22:08:56 +08:00
parent 9abba7af3e
commit b8353fe1f2
3 changed files with 12 additions and 3 deletions

View File

@ -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;

View File

@ -102,6 +102,7 @@ export default {
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
meta: {
title: 'Tab带参',
carryParam: true,
},
},
],

View File

@ -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<RouteRecordRaw, 'meta'> {