Skip to content

Commit

Permalink
fix: fix menu permission failure
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Oct 14, 2020
1 parent 9abba7a commit b8353fe
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/router/menus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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====
Expand Down Expand Up @@ -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);

if (!matchRoute) return true;
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 false;
menu.icon = menu.icon || matchRoute.meta.icon;
menu.meta = matchRoute.meta;
return true;
Expand Down
1 change: 1 addition & 0 deletions src/router/routes/modules/demo/feat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default {
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
meta: {
title: 'Tab带参',
carryParam: true,
},
},
],
Expand Down
4 changes: 3 additions & 1 deletion src/router/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'> {
Expand Down

0 comments on commit b8353fe

Please sign in to comment.