路由更新

This commit is contained in:
2025-10-17 12:05:04 +08:00
parent 0811af6d03
commit edadcc72ca
15 changed files with 456 additions and 557 deletions

View File

@@ -81,38 +81,46 @@ function generateRouteFromMenu(menu: SysMenu, isTopLevel = true): RouteRecordRaw
}
};
// 如果有子菜单使用布局组件
if (menu.children && menu.children.length > 0) {
// 根据layout字段选择布局
const layout = (menu as any).layout || menu.component;
if (layout) {
// 如果指定了layout,使用指定的布局
route.component = getComponent(layout);
// 检查是否指定了布局(只有顶层菜单使用布局
const layout = isTopLevel ? (menu as any).layout : null;
const hasChildren = menu.children && menu.children.length > 0;
// 确定路由组件
if (layout && LAYOUT_MAP[layout]) {
// 如果指定了布局,使用指定的布局
route.component = getComponent(layout);
} else if (hasChildren && isTopLevel) {
// 如果有子菜单但没有指定布局,根据菜单类型选择默认布局
if (isTopLevel && menu.type === MenuType.NAVIGATION) {
route.component = getComponent('NavigationLayout');
} else if (menu.type === MenuType.SIDEBAR) {
route.component = getComponent('BlankLayout');
} else {
// 根据菜单类型选择默认布局
if (isTopLevel && menu.type === MenuType.NAVIGATION) {
route.component = getComponent('NavigationLayout');
} else if (menu.type === MenuType.SIDEBAR) {
route.component = getComponent('BlankLayout');
} else {
route.component = getComponent('BasicLayout');
}
route.component = getComponent('BasicLayout');
}
} else {
// 没有子菜单,使用具体的页面组件
// 没有子菜单,也没有指定布局,使用具体的页面组件
if (menu.component) {
route.component = getComponent(menu.component);
} else {
// 如果没有指定组件,使用BlankLayout作为默认
// 非顶层菜单没有组件,使用简单的占位组件
route.component = getComponent('BlankLayout');
}
}
// 处理子菜单
if (menu.children && menu.children.length > 0) {
// 处理子路由
if (layout && LAYOUT_MAP[layout] && !hasChildren && menu.component && isTopLevel) {
// 如果指定了布局但没有子菜单,将页面组件作为子路由
route.children = [{
path: '',
name: `${menu.menuID}_page`,
component: getComponent(menu.component),
meta: route.meta
}];
} else if (hasChildren) {
// 处理有子菜单的情况
route.children = [];
menu.children.forEach(child => {
menu.children!.forEach(child => {
const childRoute = generateRouteFromMenu(child, false);
if (childRoute) {
route.children!.push(childRoute);
@@ -121,7 +129,7 @@ function generateRouteFromMenu(menu: SysMenu, isTopLevel = true): RouteRecordRaw
// 如果没有设置重定向自动重定向到第一个有URL的子菜单
if (!route.redirect && route.children.length > 0) {
const firstChildWithUrl = findFirstMenuWithUrl(menu.children);
const firstChildWithUrl = findFirstMenuWithUrl(menu.children!);
if (firstChildWithUrl?.url) {
route.redirect = firstChildWithUrl.url;
}