|
|
@@ -61,20 +61,30 @@ export const getRawRoute = (route: RouteLocationNormalized): RouteLocationNormal
|
|
|
}
|
|
|
|
|
|
// 后端控制路由生成
|
|
|
-export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecordRaw[] => {
|
|
|
+export const generateRoute = (routes: AppCustomRouteRecordRaw[], lang): AppRouteRecordRaw[] => {
|
|
|
const res: AppRouteRecordRaw[] = []
|
|
|
const modulesRoutesKeys = Object.keys(modules)
|
|
|
for (const route of routes) {
|
|
|
// 1. 生成 meta 菜单元数据
|
|
|
+ let title = route.nameEn
|
|
|
+ switch (lang) {
|
|
|
+ case 'zh-CN':
|
|
|
+ title = route.name
|
|
|
+ break
|
|
|
+ case 'en':
|
|
|
+ title = route.nameEn
|
|
|
+ break
|
|
|
+ case 'ja':
|
|
|
+ title = route.nameJp
|
|
|
+ break
|
|
|
+ }
|
|
|
+
|
|
|
const meta = {
|
|
|
- title: route.name,
|
|
|
+ title: title,
|
|
|
icon: route.icon,
|
|
|
hidden: !route.visible,
|
|
|
noCache: !route.keepAlive,
|
|
|
- alwaysShow:
|
|
|
- route.children &&
|
|
|
- route.children.length === 1 &&
|
|
|
- (route.alwaysShow !== undefined ? route.alwaysShow : true)
|
|
|
+ alwaysShow: route.children && route.children.length === 1 && (route.alwaysShow !== undefined ? route.alwaysShow : true)
|
|
|
} as any
|
|
|
// 特殊逻辑:如果后端配置的 MenuDO.component 包含 ?,则表示需要传递参数
|
|
|
// 此时,我们需要解析参数,并且将参数放到 meta.query 中
|
|
|
@@ -89,10 +99,7 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
|
|
|
// 路由地址转首字母大写驼峰,作为路由名称,适配keepAlive
|
|
|
let data: AppRouteRecordRaw = {
|
|
|
path: route.path.indexOf('?') > -1 ? route.path.split('?')[0] : route.path,
|
|
|
- name:
|
|
|
- route.componentName && route.componentName.length > 0
|
|
|
- ? route.componentName
|
|
|
- : toCamelCase(route.path, true),
|
|
|
+ name: route.componentName && route.componentName.length > 0 ? route.componentName : toCamelCase(route.path, true),
|
|
|
redirect: route.redirect,
|
|
|
meta: meta
|
|
|
}
|
|
|
@@ -105,10 +112,7 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
|
|
|
meta.alwaysShow = true
|
|
|
const childrenData: AppRouteRecordRaw = {
|
|
|
path: '',
|
|
|
- name:
|
|
|
- route.componentName && route.componentName.length > 0
|
|
|
- ? route.componentName
|
|
|
- : toCamelCase(route.path, true),
|
|
|
+ name: route.componentName && route.componentName.length > 0 ? route.componentName : toCamelCase(route.path, true),
|
|
|
redirect: route.redirect,
|
|
|
meta: meta
|
|
|
}
|
|
|
@@ -141,7 +145,7 @@ export const generateRoute = (routes: AppCustomRouteRecordRaw[]): AppRouteRecord
|
|
|
data.component = modules[modulesRoutesKeys[index]]
|
|
|
}
|
|
|
if (route.children) {
|
|
|
- data.children = generateRoute(route.children)
|
|
|
+ data.children = generateRoute(route.children, lang)
|
|
|
}
|
|
|
}
|
|
|
res.push(data as AppRouteRecordRaw)
|
|
|
@@ -218,11 +222,7 @@ const promoteRouteLevel = (route: AppRouteRecordRaw) => {
|
|
|
}
|
|
|
|
|
|
// 添加所有子菜单
|
|
|
-const addToChildren = (
|
|
|
- routes: RouteRecordNormalized[],
|
|
|
- children: AppRouteRecordRaw[],
|
|
|
- routeModule: AppRouteRecordRaw
|
|
|
-) => {
|
|
|
+const addToChildren = (routes: RouteRecordNormalized[], children: AppRouteRecordRaw[], routeModule: AppRouteRecordRaw) => {
|
|
|
for (let index = 0; index < children.length; index++) {
|
|
|
const child = children[index]
|
|
|
const route = routes.find((item) => item.name === child.name)
|