更换jwtToken 为Bearer
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
import router from './router'
|
||||
import store from './store'
|
||||
import { Message } from 'element-ui'
|
||||
import {
|
||||
Message
|
||||
} from 'element-ui'
|
||||
import NProgress from 'nprogress'
|
||||
import 'nprogress/nprogress.css'
|
||||
import { getToken } from '@/utils/auth'
|
||||
import {
|
||||
getToken
|
||||
} from '@/utils/auth'
|
||||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
NProgress.configure({
|
||||
showSpinner: false
|
||||
})
|
||||
|
||||
const whiteList = ['/login', '/auth-redirect', '/bind', '/register', '/demo']
|
||||
|
||||
@@ -17,7 +23,9 @@ router.beforeEach((to, from, next) => {
|
||||
if (hasToken) {
|
||||
/* has token*/
|
||||
if (to.path === '/login') {
|
||||
next({ path: '/' })
|
||||
next({
|
||||
path: '/'
|
||||
})
|
||||
NProgress.done()
|
||||
} else {
|
||||
if (store.getters.roles.length === 0) {
|
||||
@@ -27,21 +35,28 @@ router.beforeEach((to, from, next) => {
|
||||
//console.log('拉取userInfo', JSON.stringify(res))
|
||||
// 拉取user_info
|
||||
const roles = res.data.roles
|
||||
store.dispatch('GenerateRoutes', { roles }).then(accessRoutes => {
|
||||
store.dispatch('GenerateRoutes', {
|
||||
roles
|
||||
}).then(accessRoutes => {
|
||||
|
||||
// 测试 默认静态页面
|
||||
// store.dispatch('permission/generateRoutes', { roles }).then(accessRoutes => {
|
||||
// 根据roles权限生成可访问的路由表
|
||||
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
||||
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
|
||||
next({
|
||||
...to,
|
||||
replace: true
|
||||
}) // hack方法 确保addRoutes已完成
|
||||
})
|
||||
next()
|
||||
}).catch(err => {
|
||||
console.error(err)
|
||||
//这部不能少,否则会出现死循环
|
||||
store.dispatch('FedLogOut').then(() => {
|
||||
Message.error(err)
|
||||
next({ path: '/' })
|
||||
Message.error(err != undefined ? err : '登录失败')
|
||||
next({
|
||||
path: '/'
|
||||
})
|
||||
})
|
||||
next(`/login?redirect=${to.path}`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user