mirror of https://gitee.com/pnoker/dc3-web.git
pull/1/head
parent
d21ed8b660
commit
fdd70d1829
@ -1,35 +0,0 @@
|
|||||||
import router from '@/router/router'
|
|
||||||
import store from '@/store/store'
|
|
||||||
import NProgress from 'nprogress'
|
|
||||||
import 'nprogress/nprogress.css'
|
|
||||||
import {getToken} from '@/util/auth'
|
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
|
||||||
NProgress.start();
|
|
||||||
const meta = to.meta || {};
|
|
||||||
if (getToken()) {
|
|
||||||
if (to.path === '/login') { //如果登录成功访问登录页跳转到主页
|
|
||||||
next({path: '/'})
|
|
||||||
} else {
|
|
||||||
//如果用户信息为空则获取用户信息,获取用户信息失败,跳转到登录页
|
|
||||||
if (store.getters.token.length === 0) {
|
|
||||||
store.dispatch('FedLogOut').then(() => {
|
|
||||||
next({path: '/login'})
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//判断是否需要认证,没有登录访问去登录页
|
|
||||||
if (meta.isAuth === false) {
|
|
||||||
next()
|
|
||||||
} else {
|
|
||||||
next('/login')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
router.afterEach(() => {
|
|
||||||
NProgress.done();
|
|
||||||
});
|
|
Loading…
Reference in new issue