Browse Source

fix: next to login when token is not right

Pan 7 years ago
parent
commit
576e37762a
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/permission.js

+ 6 - 0
src/permission.js

@@ -2,6 +2,7 @@ import router from './router'
2 2
 import store from './store'
3 3
 import NProgress from 'nprogress' // Progress 进度条
4 4
 import 'nprogress/nprogress.css'// Progress 进度条样式
5
+import { Message } from 'element-ui'
5 6
 import { getToken } from '@/utils/auth' // 验权
6 7
 
7 8
 const whiteList = ['/login'] // 不重定向白名单
@@ -14,6 +15,11 @@ router.beforeEach((to, from, next) => {
14 15
       if (store.getters.roles.length === 0) {
15 16
         store.dispatch('GetInfo').then(res => { // 拉取用户信息
16 17
           next()
18
+        }).catch(() => {
19
+          store.dispatch('FedLogOut').then(() => {
20
+            Message.error('验证失败,请重新登录')
21
+            next({ path: '/login' })
22
+          })
17 23
         })
18 24
       } else {
19 25
         next()