[优化]-初始化进入系统必须进入首页修改成初始化进入第一个有权限的页面,无首页权限不显示首页tab标签

This commit is contained in:
zhaoxiao
2021-10-22 13:34:54 +08:00
parent 982ddaf1c0
commit 3a499e7cf8
2 changed files with 23 additions and 3 deletions
+3 -1
View File
@@ -80,7 +80,9 @@
}
},
created() {
if (this.$route.path != indexKey) {
// if (this.$route.path != indexKey) {
// 在当前页面不是首页 并且有首页权限的时候,把首页增加到面板的第一位
if (this.$route.path !== indexKey && this.$store.state.user.permissionList.find(item => item.component === 'dashboard/Analysis')) {
this.addIndexToFirst()
}
// 复制一个route对象出来,不能影响原route
+20 -2
View File
@@ -81,8 +81,26 @@ export function formatDate(value, fmt) {
}
}
/**
* 代码找出第一个没有下级子菜单的路由
* @param data
*/
function findFirstRoute(data) {
if (data[0]) {
if (data[0] && data[0].children && data[0].children.length > 0) {
return findFirstRoute(data[0].children)
} else {
return data[0].path
}
} else {
return '/'
}
}
// 生成首页路由
export function generateIndexRouter(data) {
// 对任意页面重定向的地址做改变,
const redirectPath = findFirstRoute(data)
let indexRouter = [{
path: '/',
name: 'dashboard',
@@ -90,7 +108,8 @@ export function generateIndexRouter(data) {
// eslint-disable-next-line
component: resolve => require(['@/components/layouts/TabLayout'], resolve),
meta: { title: '首页' },
redirect: '/dashboard/analysis',
// redirect: '/dashboard/analysis',
redirect: redirectPath,
children: [
...generateChildRouters(data)
]
@@ -141,7 +160,6 @@ function generateChildRouters(data) {
// eslint-disable-next-line
componentPath = resolve => require(['@/' + component + '.vue'], resolve)
// }
let menu = {
path: item.path,
name: item.name,