You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tanghe-report/report-ui/src/permission.js

38 lines
943 B
JavaScript

3 years ago
import router from './router'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken, getAccessUser } from "@/utils/auth";
3 years ago
export default router
const whiteList = ['/login', '/aj/**', '/el/**', '/bigscreen/viewer', '/excelreport/viewer']
3 years ago
// 判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {
3 years ago
NProgress.start()
let token = getToken();
let gaeaUser = getAccessUser();
3 years ago
if (token) {
if (to.path == '/login') {
next('/index')
NProgress.done()
}else{
next()
}
}else {
if (whiteList.includes(to.path)) {
3 years ago
next()
}else {
if ((token == null || token == '' || token ==undefined || gaeaUser == {}) && (to.meta != null && to.meta.requireAuth == true)) {
next(`/login?redirect=${to.path}`);
NProgress.done();
} else {
next();
}
3 years ago
}
3 years ago
}
})
router.afterEach(() => {
NProgress.done()
3 years ago
})