permission 1.25 KB
/**
 * 权限模块
 * 模块功能
 * 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()
});