initApi.js 4.97 KB
import axios from 'axios'
import * as API  from './api'
import store from '../store/index.js'
class api {
  constructor() {
    this.instance = null;
  }

  static getInstance() {
    if (!this.instance) {
      this.instance = new api();
    }
    return this.instance;
  }
  /**@augments
   * 获取库相关信息
   */
  getCarDbData() {
    return new Promise((reslove, reject) => {
      axios.get(API.url + "/alarm/traffic/vehicle_libs")
        .then(response => {
          reslove(response.data);
        });
    })
  }
  /**@augments
   * 获取布控类别
   */
  getMonitor() {
    return new Promise((reslove, reject) => {
      axios.get(API.url + "/alarm/traffic/monitor_cates")
        .then(response => {
          reslove(response.data.list_data);
        });
    })
  }
  /**
   * @argument
   * 获取城市
   */
  getProvince() {
    return new Promise((reslove, reject) => {
      axios.get(API.url + "/codes/countries/0E229CD043/provinces?depth=1").then(res => {
        store.commit('SET_PROVINCE', res.data.list_data)
        reslove(res);
      });
    });
  }
  /**
   * @argument
   * 获取人员库
   */
  getFaceDbData() {
    return new Promise((reslove, reject) => {
      axios.get(API.url + "/codes/custom/cates/4DD23AF66E/codes")
        .then(response => {
          store.commit('SET_FACEDB', response.data.list_data)
          reslove(response.data);
        });
    })
  }

  /**@augments
   * 初始化地点
   */
  getOrg() {
    return new Promise((reslove, reject) => {
      axios.get(API.url + '/org/list', {
        params: {
          org_type: 'org',
        }
      }).then(response => {
        store.commit('SET_ORG', response.data.list_data);
        reslove(response.data);
      })
    })
  }
  /**@argument
   * 列出所有地点
   */
  getAddress() {
    return new Promise((reslove, reject) => {
      axios.get(API.url + '/org/list', {
        params: {
          org_type: 'address',
        }
      }).then(response => {
        store.commit('SET_ADDRESS', response.data.list_data);
        reslove(response.data);
      })
    })
  }

  /**@argument
   * 获取地点值
   */
  getSite() {
    return new Promise((reslove, reject) => {
      axios.get(API.url + '/codes/custom/cates/630A634844/codes').then(response => {
        reslove(response.data);
      })
    });

  }
  /**@augments
   * 上传图片
   */
  uploadImg() {
    return new Promise((reslove, reject) => {
      axios.post("http://192.168.9.225:8080/FACE-DETECT-WEB/api/v1/face_web/search_src_pics/", data)
        .then(function (response) {
          reslove(response.data);
        });
    })
  }

  /**@argument
   * 获取推送服务websocket连接地址
   */
  getPushWebsocketUrl() {
    return new Promise((reslove, reject) => {
      axios.post("http://192.168.9.225:8080/FACE-DETECT-WEB/api/v1/face_web/search_src_pics/", data)
        .then(function (response) {
          reslove(response.data);
        });
    })
  }

  /**@argument
   * 获取人脸websocket连接地址
   */
  getFaceWebsocketUrl() {
    return new Promise((reslove, reject) => {
      var userName = localStorage.getItem("user_id");
      var timer = new Date();
      this.axios.get("http://192.168.9.225:8080/FACE-DETECT-WEB/api/v1/face_web/ws_url?src_type=user&user_unid=" + userName + "&client_unid=" + timer.getTime()).then((response) => {
        this.openWs(response.data.ws_url);
      });
    });
  }

  /**@argument
   * 获取设备信息
   */
  getVchanList() {
    return new Promise((reslove, reject) => {
      let externList = {},
        cameraList = {}
      axios.get(IP + "/api/v1/org/vchans/list", {
        params: {
          limit: 1000,
        }
      }).then(function (response) {
        reslove(response.data);
      });
    });
  }

  /**@argument
   * websocket心跳
   */
  wsclock(command) {
    var date = new Date();
    var datatimes = date.getTime();
    var wsMessage = {
      "type": "request",
      "id": datatimes,
      // command: "get /wsapi/v1/dtid/"+wsIP+"/keep_alive",//推送服务
      command: command,
      mts: datatimes
    };
    Ws.send(JSON.stringify(wsMessage));
  }

  // 获取code编码
  getCodeName() {
    axios.get(IP + '/api/v1/codes/traffic/cates').then(m => {
      m.data.list_data.forEach(ele => {
        this.setCodeLocalStorage(ele)
      })
    })
  }
  setCodeLocalStorage(res) {
    axios.get(IP + '/api/v1/codes/traffic/cates/' + res.cate_unid + '/codes').then(response => {
      if (response.data.list_data) {
        response.data.list_data.forEach(ele => {
          let codeKey = res.name + '-' + ele.code;
          window.localStorage.setItem(codeKey, ele.name);
        })
      }
    })
  }
  // behavior
  setBehaviorLocal() {
    axios.get(IP + '/api/v1/codes/event_types').then(m => {
      if (m.data.list_data) {
        m.data.list_data.forEach(ele => {
          let behaviorKey = '安防事件-' + ele.code;
          window.localStorage.setItem(behaviorKey, ele.name);
        })
      }
    })
  }
}

const faceapi = api.getInstance();
export {
  faceapi
}