You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.6 KiB

// 路由收集器 - 收集前端路由信息
import { mainRoutes } from './generated-route-mapping.js'
5 days ago
import { RouteUtils } from './RouteConfig.js'
// 路由收集器
export class RouteCollector {
constructor() {
this.routes = []
}
// 收集路由
collectRoutes() {
try {
// 从生成的路由映射文件收集
if (!mainRoutes || !Array.isArray(mainRoutes)) {
console.warn('⚠ 生成的路由映射文件格式不正确')
return []
}
// 转换为主入口路由格式
const frontendRoutes = mainRoutes.map(route => {
// 确保模块信息正确
if (!route.module) {
5 days ago
route.module = RouteUtils.extractModuleFromPath(route.path)
}
return {
path: route.path,
name: route.name,
module: route.module,
description: route.description || route.name,
type: route.type || 'list'
}
})
this.routes = frontendRoutes
return frontendRoutes
} catch (error) {
console.error('❌ 从生成的路由映射文件收集路由失败:', error)
return []
}
}
// 获取菜单路由
getMenuRoutes() {
return this.routes.filter(route => route.name && route.name !== '')
}
// 获取操作路由
getOperationRoutes() {
return this.routes.filter(route => route.type && route.type !== 'list')
}
// 按模块分组路由
getRoutesByModule() {
const grouped = {}
this.routes.forEach(route => {
const module = route.module
if (!grouped[module]) {
grouped[module] = []
}
grouped[module].push(route)
})
return grouped
}
}