diff --git a/src/components/layouts/TabLayout.vue b/src/components/layouts/TabLayout.vue index b54e528..7be1037 100644 --- a/src/components/layouts/TabLayout.vue +++ b/src/components/layouts/TabLayout.vue @@ -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 diff --git a/src/utils/util.js b/src/utils/util.js index c7c2673..9313aaa 100644 --- a/src/utils/util.js +++ b/src/utils/util.js @@ -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,