【更新】优化登录无角色用户的显示

pull/178/head
小诺 2023-11-26 06:21:42 +08:00 committed by 俞宝山
parent 3bb2de5244
commit 5062c92b9f
3 changed files with 17 additions and 14 deletions

View File

@ -25,7 +25,7 @@ const routes = {
children: [] children: []
} }
], ],
// 默认首页为个人中心 // 默认谁都有个人中心
menu: [ menu: [
{ {
id: '001', id: '001',
@ -36,8 +36,7 @@ const routes = {
title: '个人中心', title: '个人中心',
type: 'menu', type: 'menu',
hidden: true hidden: true
}, }
children: []
} }
] ]
} }

View File

@ -107,10 +107,9 @@ router.beforeEach(async (to, from, next) => {
if (apiMenu.length === 0) { if (apiMenu.length === 0) {
// 创建默认模块,显示默认菜单 // 创建默认模块,显示默认菜单
apiMenu[0] = cloneDeep(userRoutes.module[0]) apiMenu[0] = cloneDeep(userRoutes.module[0])
const userMenu = userRoutes.menu
const childrenApiMenu = apiMenu[0].children
apiMenu[0].children = [...userMenu, ...childrenApiMenu]
} }
const childrenApiMenu = apiMenu[0].children
apiMenu[0].children = [...childrenApiMenu ? childrenApiMenu : [], ...userRoutes.menu]
let menuRouter = filterAsyncRouter(apiMenu) let menuRouter = filterAsyncRouter(apiMenu)
menuRouter = flatAsyncRoutes(menuRouter) menuRouter = flatAsyncRoutes(menuRouter)
menuRouter.forEach((item) => { menuRouter.forEach((item) => {
@ -147,10 +146,9 @@ router.getMenu = () => {
if (apiMenu.length === 0) { if (apiMenu.length === 0) {
// 创建默认模块,显示默认菜单 // 创建默认模块,显示默认菜单
apiMenu[0] = cloneDeep(userRoutes.module[0]) apiMenu[0] = cloneDeep(userRoutes.module[0])
const userMenu = userRoutes.menu
const childrenApiMenu = apiMenu[0].children
apiMenu[0].children = [...userMenu, ...childrenApiMenu]
} }
const childrenApiMenu = apiMenu[0].children
apiMenu[0].children = [...childrenApiMenu ? childrenApiMenu : [], ...userRoutes.menu]
return filterUrl(apiMenu) return filterUrl(apiMenu)
} }

View File

@ -8,14 +8,20 @@
* 5.不可二次分发开源参与同类竞品如有想法可联系团队xiaonuobase@qq.com商议合作 * 5.不可二次分发开源参与同类竞品如有想法可联系团队xiaonuobase@qq.com商议合作
* 6.若您的项目无法满足以上几点需要更多功能代码获取Snowy商业授权许可请在官网购买授权地址为 https://www.xiaonuo.vip * 6.若您的项目无法满足以上几点需要更多功能代码获取Snowy商业授权许可请在官网购买授权地址为 https://www.xiaonuo.vip
*/ */
import userRoutes from '@/config/route'
// 获取第一个界面 // 获取第一个界面
const getIndexMenu = (menu) => { const getIndexMenu = (menu) => {
let indexMenu = menu[0].children[0] if (menu[0] && menu[0].children) {
// 如果第一个菜单为目录,接着往下找 let indexMenu = menu[0].children[0]
if (indexMenu.meta.type === 'catalog') { // 如果第一个菜单为目录,接着往下找
indexMenu = traverseChild(menu) if (indexMenu.meta.type === 'catalog') {
indexMenu = traverseChild(menu)
}
return indexMenu
} else {
return userRoutes.menu[0]
} }
return indexMenu
} }
// 遍历进行判断,其中处理了被隐藏的 // 遍历进行判断,其中处理了被隐藏的
const traverseChild = (menu) => { const traverseChild = (menu) => {