|
|
|
@ -3,6 +3,7 @@ import store from './store'
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
Message
|
|
|
|
Message
|
|
|
|
} from 'element-ui'
|
|
|
|
} from 'element-ui'
|
|
|
|
|
|
|
|
import { deepCopy } from '@/utils'
|
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
|
|
import 'nprogress/nprogress.css' // progress bar style
|
|
|
|
import 'nprogress/nprogress.css' // progress bar style
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
@ -29,7 +30,6 @@ router.beforeEach(async (to, from, next) => {
|
|
|
|
if (hasToken) {
|
|
|
|
if (hasToken) {
|
|
|
|
if (to.path === '/login') {
|
|
|
|
if (to.path === '/login') {
|
|
|
|
// if is logged in, redirect to the home page
|
|
|
|
// if is logged in, redirect to the home page
|
|
|
|
console.log(to.fullPath)
|
|
|
|
|
|
|
|
await store.dispatch('user/resetToken')
|
|
|
|
await store.dispatch('user/resetToken')
|
|
|
|
|
|
|
|
|
|
|
|
next(to.fullPath)
|
|
|
|
next(to.fullPath)
|
|
|
|
@ -41,7 +41,7 @@ router.beforeEach(async (to, from, next) => {
|
|
|
|
// determine whether the user has obtained his permission roles through getInfo
|
|
|
|
// determine whether the user has obtained his permission roles through getInfo
|
|
|
|
const hasRoles = store.getters.roles && store.getters.roles.length > 0
|
|
|
|
const hasRoles = store.getters.roles && store.getters.roles.length > 0
|
|
|
|
if (hasRoles) {
|
|
|
|
if (hasRoles) {
|
|
|
|
next()
|
|
|
|
to.query.tourl ? next(to.query.tourl) : next()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// get user info
|
|
|
|
// get user info
|
|
|
|
@ -58,10 +58,11 @@ router.beforeEach(async (to, from, next) => {
|
|
|
|
|
|
|
|
|
|
|
|
// hack method to ensure that addRoutes is complete
|
|
|
|
// hack method to ensure that addRoutes is complete
|
|
|
|
// set the replace: true, so the navigation will not leave a history record
|
|
|
|
// set the replace: true, so the navigation will not leave a history record
|
|
|
|
next({
|
|
|
|
let resetTo = deepCopy(to)
|
|
|
|
...to,
|
|
|
|
resetTo.path = to.query.tourl || to.path
|
|
|
|
replace: true
|
|
|
|
resetTo.replace = true
|
|
|
|
})
|
|
|
|
console.log(resetTo)
|
|
|
|
|
|
|
|
next(resetTo)
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.log(error)
|
|
|
|
console.log(error)
|
|
|
|
// remove token and go to login page to re-login
|
|
|
|
// remove token and go to login page to re-login
|
|
|
|
@ -79,9 +80,22 @@ router.beforeEach(async (to, from, next) => {
|
|
|
|
// in the free login whitelist, go directly
|
|
|
|
// in the free login whitelist, go directly
|
|
|
|
next()
|
|
|
|
next()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// other pages that do not have permission to access are redirected to the login page.
|
|
|
|
if (to.query.token && to.query.tp) {
|
|
|
|
next(`/login?redirect=${to.path}`)
|
|
|
|
try {
|
|
|
|
NProgress.done()
|
|
|
|
await store.dispatch('user/loginskip', {
|
|
|
|
|
|
|
|
token: to.query.token,
|
|
|
|
|
|
|
|
tp: to.query.tp,
|
|
|
|
|
|
|
|
loginId: to.query.loginId
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
next(to.query.tourl || '/')
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
next('/login')
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// other pages that do not have permission to access are redirected to the login page.
|
|
|
|
|
|
|
|
next(`/login?redirect=${to.path}`)
|
|
|
|
|
|
|
|
NProgress.done()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|