permission
1.25 KB
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
51
52
53
54
55
56
/**
 * 权限模块
 * 模块功能
 * 1.获取菜单权限
 * 2.获取设备信息
 * 3.获取websocket信息
 * 4.初始化加载所需api
 */
import router from './router'
import store from './store'
import {pushws, facews,devws} from './util/websocket'
import {faceapi} from './util/api.js'
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next()
  } else {
    if (store.getters.permission_routers.length === 0) { //判断当前用户是否拉取了路由
      store.dispatch('GetMenuRole').then(res => { //获取菜单
        router.addRoutes(res);
        if( !PushWs ){ //菜单拉取成功连接 websocket
          pushws();
        } 
        
        if(!FaceWs) {
          facews();
        }
        if(!DevWs) {
          devws();
        }
        /**
         * 初始化页面所需api
         **/        
        faceapi.setBehaviorLocal();
        faceapi.getCodeName();
        faceapi.getSite();
        faceapi.getOrg();
        faceapi.getAddress();
        faceapi.getFaceDbData();
        faceapi.getProvince();
      }).catch(() => {
        next({
          path: '/'
        })
      })
    } else {
    }
    if (store.getters.dev_unid === ""){ //获取设备信息
      store.dispatch('GetDev')
    } 
  }
  next()
});