permission.js 1 KB
/**
 * 权限模块
 * 模块功能
 * 1.获取菜单权限
 * 2.获取设备信息
 * 3.获取websocket信息
 * 4.初始化加载所需api
 */

import router from '../router'
import store from '../store'
import {faceapi} from './initApi'
import {pushws} from './socket'
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);
          pushws();
         /**
         * 初始化页面所需api
         **/
        faceapi.setBehaviorLocal();
        faceapi.getCodeName();
        faceapi.getSite();
        faceapi.getOrg();
        faceapi.getAddress();
        faceapi.getFaceDbData();
        faceapi.getProvince();

      }).catch(() => {

      })
    } else {

    }
    // if (store.getters.dev_unid === ""){ //获取设备信息
    //   store.dispatch('GetDev')
    // }
  }
  next()
});