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.
|
|
|
|
// 路由收集器 - 收集前端路由信息
|
|
|
|
|
import { directRouteMappings } from './direct-route-mappings.js'
|
|
|
|
|
import { RouteUtils } from './RouteConfig.js'
|
|
|
|
|
|
|
|
|
|
// 路由收集器
|
|
|
|
|
export class RouteCollector {
|
|
|
|
|
constructor() {
|
|
|
|
|
this.routes = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 收集路由
|
|
|
|
|
collectRoutes() {
|
|
|
|
|
try {
|
|
|
|
|
// 从生成的路由映射文件收集
|
|
|
|
|
if (!directRouteMappings || !directRouteMappings.pageMappings) {
|
|
|
|
|
console.warn('⚠️ 生成的路由映射文件格式不正确')
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从页面映射中提取路由信息
|
|
|
|
|
const frontendRoutes = directRouteMappings.pageMappings.map(mapping => {
|
|
|
|
|
return {
|
|
|
|
|
path: mapping.route,
|
|
|
|
|
name: mapping.routeName,
|
|
|
|
|
module: mapping.module,
|
|
|
|
|
description: `${mapping.routeName}页面`,
|
|
|
|
|
type: 'list',
|
|
|
|
|
component: mapping.component,
|
|
|
|
|
apiCalls: mapping.apiCalls
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|