修复内容统计

This commit is contained in:
2026-01-26 17:51:56 +08:00
parent da82e82e7c
commit 2420ce7660
8 changed files with 508 additions and 22 deletions
+14 -20
View File
@@ -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;
}