/*
|
* @Date: 2022-11-09 12:37:25
|
* @LastEditors: Sneed
|
* @LastEditTime: 2024-01-17 23:06:22
|
* @FilePath: /belleson-frontend/Users/mache/Documents/demo/mdc/src/permission.js
|
*/
|
import router from './router'
|
import store from './store'
|
import NProgress from 'nprogress' // Progress 进度条
|
import 'nprogress/nprogress.css'// Progress 进度条样式
|
import { getToken } from '@/utils/auth' // 验权
|
import { Message } from 'element-ui'
|
import { initApplicationCfg } from './api/MdcApi'
|
if (process.env.NODE_ENV !== 'development') {
|
if (window.console) {
|
window.console.log = function() {}
|
} else if (console) {
|
console.log = function() {}
|
}
|
}
|
const whiteList = ['/'] // 不重定向白名单
|
router.beforeEach((to, from, next) => {
|
NProgress.start()
|
initApplicationCfg().then(res => {
|
console.log(to.path,getToken().value)
|
if (getToken().value) {
|
next()
|
} else {
|
if (whiteList.indexOf(to.path) !== -1) {
|
next()
|
} else {
|
next('/')
|
NProgress.done()
|
}
|
}
|
})
|
})
|
router.afterEach((to) => {
|
if (to.path.indexOf('workshop') > -1) {
|
// 车间
|
// const [{ roomName = '' }] = store.getters.workshopList.filter((item) => item.workshopId === to.params.pid)
|
// console.log(roomName)
|
// to.matched[to.matched.length - 1].meta.title = roomName
|
} else if (to.path.indexOf('device') > -1) {
|
// 设备
|
// const [{ remark = '' }] = store.getters.deviceCategories.filter((item) => item.type === to.params.did)
|
// to.matched[to.matched.length - 1].meta.title = remark
|
}
|
NProgress.done() // 结束Progress
|
})
|