From fff060f6707338d10d873c560b6439f5ce2f99e5 Mon Sep 17 00:00:00 2001 From: panqihua Date: Thu, 26 Jan 2023 21:41:05 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=B0=83=E6=95=B4=E6=80=BB=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=202.=E9=A6=96=E9=A1=B5=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/permission.js | 11 +- src/router/index.js | 22 +-- src/views/platform/index.vue | 323 +++++++++++++++++++++++++++++++++++ 3 files changed, 337 insertions(+), 19 deletions(-) create mode 100644 src/views/platform/index.vue diff --git a/src/permission.js b/src/permission.js index 6bb0a1f..37fa9a9 100644 --- a/src/permission.js +++ b/src/permission.js @@ -25,9 +25,18 @@ router.beforeEach((to, from, next) => { store.dispatch('GetInfo').then(() => { isRelogin.show = false store.dispatch('GenerateRoutes').then(accessRoutes => { + // 自动跳转到根路由 + let root = accessRoutes.find(item => item.path === '/') + let _to + if (root && root.children.find(item => item.path.endsWith('index'))) { + root.redirect = root.children.find(item => item.path.endsWith('/index')).path + _to = { ...to, replace: true, path: root.redirect } + } else { + _to = { ...to, replace: true } + } // 根据roles权限生成可访问的路由表 router.addRoutes(accessRoutes) // 动态添加可访问路由表 - next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 + next(_to) // hack方法 确保addRoutes已完成 }) }).catch(err => { store.dispatch('LogOut').then(() => { diff --git a/src/router/index.js b/src/router/index.js index d3d358e..87e9b58 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,11 +1,10 @@ -import Vue from "vue"; -import Router from "vue-router"; +import Vue from 'vue' +import Router from 'vue-router' +/* Layout */ +import Layout from '@/layout' Vue.use(Router); -/* Layout */ -import Layout from "@/layout"; - /** * Note: 路由配置项 * @@ -61,19 +60,6 @@ export const constantRoutes = [ component: () => import("@/views/error/401"), hidden: true, }, - { - path: "", - component: Layout, - redirect: "index", - children: [ - { - path: "index", - component: () => import("@/views/index"), - name: "Index", - meta: { title: "数据面板", icon: "dashboard", affix: true }, - }, - ], - }, { path: "/user", component: Layout, diff --git a/src/views/platform/index.vue b/src/views/platform/index.vue new file mode 100644 index 0000000..c1a5e22 --- /dev/null +++ b/src/views/platform/index.vue @@ -0,0 +1,323 @@ + + + + + +