You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

/*
* @Author: your name
* @Date: 2021-10-08 09:26:42
* @LastEditTime: 2022-02-11 09:53:01
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /data-show/src/permission.js
*/
import store from '@/store'
import router from "@/router"
import NProgress from "nprogress"
import "nprogress/nprogress.css"
const whitePath = ['/', '/login', '/industryDataExport','/index']
router.beforeEach((to, from, next) => {
NProgress.start()
const token = store.getters.getToken;
if(!token && !whitePath.includes(to.path)) {
next('/login');
} else {
checkMenu(to.path, next);
}
})
router.afterEach(() => {
NProgress.done()
})
// 检查菜单权限
function checkMenu(path, next) {
let menuStr = store.getters.getMenu || [];
let arr = ['/modelInsight', '/eventInsight', '/marketingAnalysis'];
let n = menuStr.findIndex(ele => ele.link === path);
if(arr.includes(path) && n === -1) next('/index')
else next()
}
export default router