update permission

qianlishi 3 years ago
parent 8416dbc502
commit 1107013ce5

@ -1,17 +1,15 @@
import router from './router' import router from './router'
import store from './store' import NProgress from 'nprogress'
import NProgress from 'nprogress' // Progress 进度条 import 'nprogress/nprogress.css'
import 'nprogress/nprogress.css'// Progress 进度条样式
import { getToken, getAccessUser } from "@/utils/auth"; import { getToken, getAccessUser } from "@/utils/auth";
export default router export default router
var whiteList = ['/login', '/aj/**', '/bigscreen/viewer'] const whiteList = ['/login', '/aj/**', '/bigscreen/viewer']
// 判断是否需要登录权限 以及是否登录 // 判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()
var token = getToken(); let token = getToken();
var gaeaUser = getAccessUser(); let gaeaUser = getAccessUser();
// 如果有token
if (token) { if (token) {
if (to.path == '/login') { if (to.path == '/login') {
next('/index') next('/index')
@ -20,13 +18,11 @@ router.beforeEach((to, from, next) => {
next() next()
} }
}else { }else {
console.log(to.path)
if (whiteList.includes(to.path)) { if (whiteList.includes(to.path)) {
next() next()
}else { }else {
// 如果没有token if ((token == null || token == '' || token ==undefined || gaeaUser == {}) && (to.meta != null && to.meta.requireAuth == true)) {
if ((token == null || token == '' || token ==undefined || gaeaUser == {}) && (to.meta != null && to.meta.requireAuth == true)) {// 在免登录白名单,直接进入 next(`/login?redirect=${to.path}`);
next(`/login?redirect=${to.path}`); // 否则全部重定向到登录页
NProgress.done(); NProgress.done();
} else { } else {
next(); next();
@ -37,5 +33,5 @@ router.beforeEach((to, from, next) => {
}) })
router.afterEach(() => { router.afterEach(() => {
NProgress.done() // 结束Progress NProgress.done()
}) })

Loading…
Cancel
Save