29 lines
1.1 KiB
TypeScript
29 lines
1.1 KiB
TypeScript
import { AppRouteRecord } from '@/types/router'
|
|
import { PORTAL_TOP_MODULE_ORDER } from '@/utils/router/portal-menu'
|
|
import { sqxpAdminRoutes } from './sqxp'
|
|
import { plRoutes } from './pl'
|
|
|
|
/**
|
|
* 动态菜单与路由(前端权限模式 VITE_ACCESS_MODE=frontend 时使用)
|
|
* 一级业务模块顺序与 PORTAL_TOP_MODULE_ORDER 对齐(左侧菜单展示)。
|
|
*/
|
|
const mergedRoutes: AppRouteRecord[] = [...sqxpAdminRoutes, ...plRoutes]
|
|
const topModuleOrder = new Map<string, number>(
|
|
PORTAL_TOP_MODULE_ORDER.map((path, index) => [path, index])
|
|
)
|
|
|
|
export const routeModules: AppRouteRecord[] = mergedRoutes.slice().sort((a, b) => {
|
|
const indexA = topModuleOrder.has(String(a.path ?? ''))
|
|
? (topModuleOrder.get(String(a.path ?? '')) as number)
|
|
: -1
|
|
const indexB = topModuleOrder.has(String(b.path ?? ''))
|
|
? (topModuleOrder.get(String(b.path ?? '')) as number)
|
|
: -1
|
|
if (indexA < 0 && indexB < 0) {
|
|
return mergedRoutes.indexOf(a) - mergedRoutes.indexOf(b)
|
|
}
|
|
if (indexA < 0) return -1
|
|
if (indexB < 0) return 1
|
|
return indexA - indexB
|
|
})
|