From 057163b3f4952d16baf96088a99667088c7d6aa9 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Thu, 14 Jan 2021 12:28:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=B8=8D=E5=90=8C=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E8=87=AA=E5=AE=9A=E4=B9=89=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/model/sys_authority.go | 1 + web/src/permission.js | 4 +-- web/src/store/module/router.js | 5 +++- web/src/store/module/user.js | 7 +++-- .../layout/aside/historyComponent/history.vue | 28 +++++++++++++------ .../superAdmin/authority/components/menus.vue | 27 ++++++++++++++++-- 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/server/model/sys_authority.go b/server/model/sys_authority.go index f0a971a8..ac80ea6e 100644 --- a/server/model/sys_authority.go +++ b/server/model/sys_authority.go @@ -14,4 +14,5 @@ type SysAuthority struct { DataAuthorityId []SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id"` Children []SysAuthority `json:"children" gorm:"-"` SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"` + DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` } diff --git a/web/src/permission.js b/web/src/permission.js index a7163a9d..dc7c3165 100644 --- a/web/src/permission.js +++ b/web/src/permission.js @@ -13,7 +13,7 @@ router.beforeEach(async(to, from, next) => { document.title = getPageTitle(to.meta.title) if (whiteList.indexOf(to.name) > -1) { if (token) { - next({ path: '/layout/dashboard' }) + next({ name: store.getters["user/userInfo"].authority.defaultRouter }) } else { next() } @@ -21,7 +21,7 @@ router.beforeEach(async(to, from, next) => { // 不在白名单中并且已经登陆的时候 if (token) { // 添加flag防止多次获取动态路由和栈溢出 - if (!asyncRouterFlag) { + if (!asyncRouterFlag && store.getters['router/asyncRouters'].length == 0) { asyncRouterFlag++ await store.dispatch('router/SetAsyncRouter') const asyncRouters = store.getters['router/asyncRouters'] diff --git a/web/src/store/module/router.js b/web/src/store/module/router.js index 6685e4bc..8272e025 100644 --- a/web/src/store/module/router.js +++ b/web/src/store/module/router.js @@ -28,7 +28,7 @@ export const router = { // 设置动态路由 setAsyncRouter(state, asyncRouters) { state.asyncRouters = asyncRouters - } + }, }, actions: { // 从后台获取动态路由 @@ -73,6 +73,9 @@ export const router = { }, routerList(state) { return state.routerList + }, + defaultRouter(state) { + return state.defaultRouter } } } \ No newline at end of file diff --git a/web/src/store/module/user.js b/web/src/store/module/user.js index e9dc5810..ff677c00 100644 --- a/web/src/store/module/user.js +++ b/web/src/store/module/user.js @@ -35,16 +35,19 @@ export const user = { } }, actions: { - async LoginIn({ commit }, loginInfo) { + async LoginIn({ commit, dispatch, rootGetters, getters }, loginInfo) { const res = await login(loginInfo) if (res.code == 0) { commit('setUserInfo', res.data.user) commit('setToken', res.data.token) + await dispatch('router/SetAsyncRouter', {}, { root: true }) + const asyncRouters = rootGetters['router/asyncRouters'] + router.addRoutes(asyncRouters) const redirect = router.history.current.query.redirect if (redirect) { router.push({ path: redirect }) } else { - router.push({ path: '/layout/dashboard' }) + router.push({ name: getters["userInfo"].authority.defaultRouter }) } return true } diff --git a/web/src/view/layout/aside/historyComponent/history.vue b/web/src/view/layout/aside/historyComponent/history.vue index 0e96f20e..4c94906b 100644 --- a/web/src/view/layout/aside/historyComponent/history.vue +++ b/web/src/view/layout/aside/historyComponent/history.vue @@ -1,7 +1,7 @@