提交 72ac240f 编写于 作者: 无木

feat: routers support `ignoreRoute` option

为路由配置添加`meta`.`ignoreRoute`配置,允许在`ROUTE_MAPPING`及`BACK`模式下配置纯菜单数据

fixed:
上级 b5046f07
......@@ -9,6 +9,10 @@ export function getAllParentPath<T = Recordable>(treeData: T[], path: string) {
return (menuList || []).map((item) => item.path);
}
function isPlainPath(path: string) {
return path.indexOf(':') === -1;
}
function joinParentPath(menus: Menu[], parentPath = '') {
for (let index = 0; index < menus.length; index++) {
const menu = menus[index];
......@@ -20,7 +24,7 @@ function joinParentPath(menus: Menu[], parentPath = '') {
menu.path = `${parentPath}/${menu.path}`;
}
if (menu?.children?.length) {
joinParentPath(menu.children, menu.path);
joinParentPath(menu.children, isPlainPath(menu.path) ? menu.path : parentPath);
}
}
}
......
......@@ -241,6 +241,28 @@ const feat: AppRouteModule = {
title: t('routes.demo.feat.tab'),
carryParam: true,
},
children: [
{
path: 'testTab/id1',
name: 'TestTab1',
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
meta: {
title: t('routes.demo.feat.tab1'),
carryParam: true,
ignoreRoute: true,
},
},
{
path: 'testTab/id2',
name: 'TestTab2',
component: () => import('/@/views/demo/feat/tab-params/index.vue'),
meta: {
title: t('routes.demo.feat.tab2'),
carryParam: true,
ignoreRoute: true,
},
},
],
},
],
};
......
......@@ -111,6 +111,12 @@ export const usePermissionStore = defineStore({
return roleList.some((role) => roles.includes(role));
};
const routeRmoveIgnoreFilter = (route: AppRouteRecordRaw) => {
const { meta } = route;
const { ignoreRoute } = meta || {};
return !ignoreRoute;
};
switch (permissionMode) {
case PermissionModeEnum.ROLE:
routes = filter(asyncRoutes, routeFilter);
......@@ -123,6 +129,8 @@ export const usePermissionStore = defineStore({
routes = filter(asyncRoutes, routeFilter);
routes = routes.filter(routeFilter);
const menuList = transformRouteToMenu(routes, true);
routes = filter(routes, routeRmoveIgnoreFilter);
routes = routes.filter(routeRmoveIgnoreFilter);
menuList.sort((a, b) => {
return (a.meta?.orderNo || 0) - (b.meta?.orderNo || 0);
});
......@@ -158,6 +166,10 @@ export const usePermissionStore = defineStore({
const backMenuList = transformRouteToMenu(routeList);
this.setBackMenuList(backMenuList);
// remove meta.ignoreRoute item
routeList = filter(routeList, routeRmoveIgnoreFilter);
routeList = routeList.filter(routeRmoveIgnoreFilter);
routeList = flatMultiLevelRoutes(routeList);
routes = [PAGE_NOT_FOUND_ROUTE, ...routeList];
break;
......
......@@ -33,5 +33,6 @@ declare module 'vue-router' {
// Never show in menu
hideMenu?: boolean;
isLink?: boolean;
ignoreRoute?: boolean;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册