正在显示
1 个修改的文件
包含
2 行增加
和
15 行删除
| 1 | -/* eslint-disable no-tabs */ | ||
| 2 | import router from './router' | 1 | import router from './router' |
| 3 | import store from './store' | 2 | import store from './store' |
| 4 | -import { Message } from 'element-ui' | ||
| 5 | import Performance from '@/tools/performance' | 3 | import Performance from '@/tools/performance' |
| 6 | 4 | ||
| 7 | -const whiteList = ['/login'] // 不重定向白名单 | ||
| 8 | var end = null | 5 | var end = null |
| 9 | - | 6 | +const whiteList = ['/login'] // 不重定向白名单 |
| 10 | router.beforeEach((to, from, next) => { | 7 | router.beforeEach((to, from, next) => { |
| 11 | end = Performance.startExecute(`${from.path} => ${to.path} 路由耗时`) /// 路由性能监控 | 8 | end = Performance.startExecute(`${from.path} => ${to.path} 路由耗时`) /// 路由性能监控 |
| 9 | + | ||
| 12 | if (store.getters.token) { | 10 | if (store.getters.token) { |
| 13 | if (to.path === '/login') { | 11 | if (to.path === '/login') { |
| 14 | next({ path: '/' }) | 12 | next({ path: '/' }) |
| 15 | } else { | 13 | } else { |
| 16 | - if (store.getters.roles.length === 0) { | ||
| 17 | - store.dispatch('GetInfo').then(res => { // 拉取用户信息 | ||
| 18 | next() | 14 | next() |
| 19 | - }).catch((err) => { | ||
| 20 | - store.dispatch('FedLogOut').then(() => { | ||
| 21 | - Message.error(err || 'Verification failed, please login again') | ||
| 22 | - next({ path: '/' }) | ||
| 23 | - }) | ||
| 24 | - }) | ||
| 25 | - } else { | ||
| 26 | - next() | ||
| 27 | - } | ||
| 28 | } | 15 | } |
| 29 | } else { | 16 | } else { |
| 30 | if (whiteList.indexOf(to.path) !== -1) { | 17 | if (whiteList.indexOf(to.path) !== -1) { | ... | ... |
-
请 注册 或 登录 后发表评论