mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-28 00:42:12 +08:00
perf: the routeModule can ignore the layou configuration without writing
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
- Layout 界面布局样式调整
|
- Layout 界面布局样式调整
|
||||||
- 优化表格渲染性能
|
- 优化表格渲染性能
|
||||||
- 表单折叠搜索添图标添加动画
|
- 表单折叠搜索添图标添加动画
|
||||||
|
- routeModule 可以忽略 layou 配置不写。方便配置一级菜单
|
||||||
|
|
||||||
### 🐛 Bug Fixes
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
@@ -87,9 +87,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) => {
|
const matchRoute = routes.find((route) => {
|
||||||
if (route.meta && route.meta.carryParam) {
|
if (route.meta) {
|
||||||
|
if (route.meta.carryParam) {
|
||||||
return pathToRegexp(route.path).test(menu.path);
|
return pathToRegexp(route.path).test(menu.path);
|
||||||
}
|
}
|
||||||
|
if (route.meta.ignoreAuth) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return route.path === menu.path;
|
return route.path === menu.path;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
2
src/router/types.d.ts
vendored
2
src/router/types.d.ts
vendored
@@ -67,6 +67,6 @@ export interface MenuModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface AppRouteModule {
|
export interface AppRouteModule {
|
||||||
layout: AppRouteRecordRaw;
|
layout?: AppRouteRecordRaw;
|
||||||
routes: AppRouteRecordRaw[];
|
routes: AppRouteRecordRaw[];
|
||||||
}
|
}
|
||||||
|
@@ -49,8 +49,12 @@ export function transformRouteToMenu(routeModList: AppRouteModule[]) {
|
|||||||
const routeList: AppRouteRecordRaw[] = [];
|
const routeList: AppRouteRecordRaw[] = [];
|
||||||
cloneRouteModList.forEach((item) => {
|
cloneRouteModList.forEach((item) => {
|
||||||
const { layout, routes } = item;
|
const { layout, routes } = item;
|
||||||
|
if (layout) {
|
||||||
layout.children = routes;
|
layout.children = routes;
|
||||||
routeList.push(layout);
|
routeList.push(layout);
|
||||||
|
} else {
|
||||||
|
routeList.push(...routes);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return treeMap(routeList, {
|
return treeMap(routeList, {
|
||||||
conversion: (node: AppRouteRecordRaw) => {
|
conversion: (node: AppRouteRecordRaw) => {
|
||||||
|
@@ -23,18 +23,24 @@ export function genRouteModule(moduleList: AppRouteModule[]) {
|
|||||||
for (const routeMod of moduleList) {
|
for (const routeMod of moduleList) {
|
||||||
const routes = routeMod.routes as any;
|
const routes = routeMod.routes as any;
|
||||||
const layout = routeMod.layout;
|
const layout = routeMod.layout;
|
||||||
let router = createRouter({ routes, history: createWebHashHistory() });
|
const router = createRouter({ routes, history: createWebHashHistory() });
|
||||||
|
|
||||||
const flatList = toRaw(router.getRoutes()).filter((item) => item.children.length === 0);
|
const flatList = (toRaw(router.getRoutes()).filter(
|
||||||
|
(item) => item.children.length === 0
|
||||||
|
) as unknown) as AppRouteRecordRaw[];
|
||||||
try {
|
try {
|
||||||
(router as any) = null;
|
(router as any) = null;
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
|
|
||||||
flatList.forEach((item) => {
|
flatList.forEach((item) => {
|
||||||
item.path = `${layout.path}${item.path}`;
|
item.path = `${layout ? layout.path : ''}${item.path}`;
|
||||||
});
|
});
|
||||||
layout.children = (flatList as unknown) as AppRouteRecordRaw[];
|
if (layout) {
|
||||||
|
layout.children = flatList;
|
||||||
ret.push(layout);
|
ret.push(layout);
|
||||||
|
} else {
|
||||||
|
ret.push(...flatList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret as RouteRecordRaw[];
|
return ret as RouteRecordRaw[];
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user