From 3a499e7cf8ccea475ea13d598c6177419ba16cf0 Mon Sep 17 00:00:00 2001 From: zhaoxiao Date: Fri, 22 Oct 2021 13:34:54 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]-=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E8=BF=9B=E5=85=A5=E7=B3=BB=E7=BB=9F=E5=BF=85=E9=A1=BB?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E9=A6=96=E9=A1=B5=E4=BF=AE=E6=94=B9=E6=88=90?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E8=BF=9B=E5=85=A5=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E6=9C=89=E6=9D=83=E9=99=90=E7=9A=84=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=EF=BC=8C=E6=97=A0=E9=A6=96=E9=A1=B5=E6=9D=83=E9=99=90=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=A6=96=E9=A1=B5tab=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/layouts/TabLayout.vue | 4 +++- src/utils/util.js | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) 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,