修复内容统计
This commit is contained in:
+14
-20
@@ -2,12 +2,17 @@ import { createComponentLoader } from '@/utils/pathResolver';
|
||||
import { h, resolveComponent as resolveVueComponent } from 'vue';
|
||||
|
||||
// 递归转换嵌套菜单为嵌套路由
|
||||
export function convertMenusToRoutes(menus) {
|
||||
export function convertMenusToRoutes(menus, parentPath = '') {
|
||||
if (!menus || menus.length === 0) return [];
|
||||
|
||||
return menus.map(menu => {
|
||||
// 拼接完整的路由路径(处理相对路径)
|
||||
const fullPath = menu.path ?
|
||||
(menu.path.startsWith('/') ? menu.path : `${parentPath}/${menu.path}`)
|
||||
: '';
|
||||
|
||||
const route = {
|
||||
path: menu.path || '',
|
||||
path: fullPath || menu.path || '',
|
||||
name: `menu_${menu.id}`,
|
||||
meta: {
|
||||
title: menu.title,
|
||||
@@ -32,32 +37,21 @@ export function convertMenusToRoutes(menus) {
|
||||
route.component = () => import('@/views/404/404.vue');
|
||||
}
|
||||
|
||||
// 2. 递归子路由
|
||||
// 2. 递归子路由(传递当前完整路径作为父路径)
|
||||
if (menu.children && menu.children.length > 0) {
|
||||
route.children = convertMenusToRoutes(menu.children);
|
||||
route.children = convertMenusToRoutes(menu.children, fullPath);
|
||||
|
||||
// 目录节点添加重定向,防止点击父菜单页面空白
|
||||
const firstChild = menu.children[0];
|
||||
if (firstChild && firstChild.path) {
|
||||
route.redirect = firstChild.path;
|
||||
// 计算第一个子路由的完整路径
|
||||
const childFullPath = firstChild.path.startsWith('/') ?
|
||||
firstChild.path :
|
||||
`${fullPath}/${firstChild.path}`;
|
||||
route.redirect = childFullPath;
|
||||
}
|
||||
}
|
||||
|
||||
return route;
|
||||
});
|
||||
}
|
||||
|
||||
// 查找第一个有效的子路由
|
||||
function findFirstValidRoute(children) {
|
||||
if (!children || children.length === 0) return null;
|
||||
for (const child of children) {
|
||||
if (child.path && (child.component_path || (child.children && child.children.length > 0))) {
|
||||
return child;
|
||||
}
|
||||
if (child.children && child.children.length > 0) {
|
||||
const grandChild = findFirstValidRoute(child.children);
|
||||
if (grandChild) return grandChild;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user