gaosp
2024-03-10 7e48785473e01e85b8313f918ea0b28bdbf99acc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * @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
})