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.
 
 
 
 
 
 

79 lines
2.5 KiB

// 路由收集器 - 收集前端路由信息
import { directRouteMappings } from './direct-route-mappings.js'
import { RouteUtils } from './RouteConfig.js'
// 路由收集器
export class RouteCollector {
constructor() {
this.routes = []
}
// 收集路由
collectRoutes() {
try {
console.log('🔄 开始收集路由...')
console.log('📊 directRouteMappings:', directRouteMappings)
console.log('📊 directRouteMappings类型:', typeof directRouteMappings)
console.log('📊 directRouteMappings是否为undefined:', directRouteMappings === undefined)
// 从生成的路由映射文件收集
if (!directRouteMappings || !directRouteMappings.pageMappings) {
console.warn('⚠ 生成的路由映射文件格式不正确')
console.log('🔍 调试信息:')
console.log(' - directRouteMappings:', directRouteMappings)
console.log(' - pageMappings:', directRouteMappings?.pageMappings)
console.log(' - 导入是否成功:', directRouteMappings !== undefined)
return []
}
console.log(`📊 找到 ${directRouteMappings.pageMappings.length} 个页面映射`)
// 从页面映射中提取路由信息
const frontendRoutes = directRouteMappings.pageMappings.map(mapping => {
console.log(`📋 处理页面映射: ${mapping.route} (${mapping.component})`)
return {
path: mapping.route,
name: mapping.routeName,
module: mapping.module,
description: `${mapping.routeName}页面`,
type: 'list',
component: mapping.component,
apiCalls: mapping.apiCalls
}
})
this.routes = frontendRoutes
console.log(`✅ 成功收集到 ${frontendRoutes.length} 个前端路由`)
return frontendRoutes
} catch (error) {
console.error('❌ 从生成的路由映射文件收集路由失败:', error)
console.error('错误堆栈:', error.stack)
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
}
}