|
@@ -10,22 +10,25 @@ import { ACCESS_TOKEN } from '@/store/mutation-types'
|
|
|
NProgress.configure({ showSpinner: false })
|
|
|
|
|
|
const whiteList = ['login', 'register', 'registerResult']
|
|
|
+const loginRoutePath = '/user/login'
|
|
|
const defaultRoutePath = '/dashboard/workplace'
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
NProgress.start()
|
|
|
to.meta && (typeof to.meta.title !== 'undefined' && setDocumentTitle(`${to.meta.title} - ${domTitle}`))
|
|
|
+
|
|
|
if (storage.get(ACCESS_TOKEN)) {
|
|
|
-
|
|
|
- if (to.path === '/user/login') {
|
|
|
+ if (to.path === loginRoutePath) {
|
|
|
next({ path: defaultRoutePath })
|
|
|
NProgress.done()
|
|
|
} else {
|
|
|
+
|
|
|
if (store.getters.roles.length === 0) {
|
|
|
store
|
|
|
.dispatch('GetInfo')
|
|
|
.then(res => {
|
|
|
const roles = res.result && res.result.role
|
|
|
+
|
|
|
store.dispatch('GenerateRoutes', { roles }).then(() => {
|
|
|
|
|
|
|
|
@@ -33,7 +36,7 @@ router.beforeEach((to, from, next) => {
|
|
|
|
|
|
const redirect = decodeURIComponent(from.query.redirect || to.path)
|
|
|
if (to.path === redirect) {
|
|
|
-
|
|
|
+
|
|
|
next({ ...to, replace: true })
|
|
|
} else {
|
|
|
|
|
@@ -46,8 +49,9 @@ router.beforeEach((to, from, next) => {
|
|
|
message: '错误',
|
|
|
description: '请求用户信息失败,请重试'
|
|
|
})
|
|
|
+
|
|
|
store.dispatch('Logout').then(() => {
|
|
|
- next({ path: '/user/login', query: { redirect: to.fullPath } })
|
|
|
+ next({ path: loginRoutePath, query: { redirect: to.fullPath } })
|
|
|
})
|
|
|
})
|
|
|
} else {
|
|
@@ -59,7 +63,7 @@ router.beforeEach((to, from, next) => {
|
|
|
|
|
|
next()
|
|
|
} else {
|
|
|
- next({ path: '/user/login', query: { redirect: to.fullPath } })
|
|
|
+ next({ path: loginRoutePath, query: { redirect: to.fullPath } })
|
|
|
NProgress.done()
|
|
|
}
|
|
|
}
|