This commit is contained in:
张成
2025-10-08 19:20:24 +08:00
parent 845658f193
commit 7e888970d3
11 changed files with 1726 additions and 68 deletions

View File

@@ -168,26 +168,17 @@ export default class uiTool {
return []
}
static getRoutes(Main, ParentView, Page404, HomePage) {
static getRoutes(Main, ParentView, Page404) {
let mainRoute = {
path: '/',
name: '主视图',
redirect: '/home',
component: Main,
meta: { title: '首页', notCache: true },
children: [
// 默认 home 路由,确保登录后能跳转
{
path: '/home',
name: 'home',
meta: { title: '首页', notCache: true },
component: HomePage || {
render: h => h('div', { style: { padding: '20px' } }, '欢迎使用管理系统')
}
}
]
children: []
}
// 从 localStorage 读取权限菜单
if (
localStorage.authorityMenus &&
localStorage.authorityMenus !== 'undefined'
@@ -198,17 +189,8 @@ export default class uiTool {
let menus = uiTool.transformTree(authorityMenus)
let curRoutes = uiTool.menuToRoute(menus, ParentView, Page404)
// 合并权限路由,保留默认 home 路由
const homeRoute = mainRoute.children.find(r => r.name === 'home')
const hasHome = curRoutes.some(r => r.name === 'home')
if (hasHome) {
// 如果权限路由中有 home使用权限路由的 home
mainRoute.children = curRoutes
} else {
// 如果权限路由中没有 home保留默认 home 并添加其他路由
mainRoute.children = [homeRoute, ...curRoutes]
}
// 使用后端返回的路由(包括首页)
mainRoute.children = curRoutes
}
}