#
Junjie
6 天以前 32004d6bb7db528c151cca5bd78c4e557171a9ee
src/main/webapp/components/MapCanvas.js
@@ -13,6 +13,7 @@
      map: [],
      currentLev: 1,
      mapFps: 0,
      ws: null,
      pixiApp: null,
      pixiStageList: [],
      pixiStaMap: new Map(),
@@ -43,7 +44,16 @@
  mounted() {
    this.currentLev = this.lev || 1;
    this.createMap();
    this.ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
    this.ws.onopen = this.webSocketOnOpen;
    this.ws.onerror = this.webSocketOnError;
    this.ws.onmessage = this.webSocketOnMessage;
    this.ws.onclose = this.webSocketClose;
    setTimeout(() => {
    this.getMap(this.currentLev);
    }, 1000);
    this.timer = setInterval(() => {
      this.getCrnInfo();
      this.getSiteInfo();
@@ -187,16 +197,7 @@
      }
    },
    getMap() {
      $.ajax({
        url: baseUrl + "/basMap/lev/" + this.currentLev + "/auth",
        headers: { 'token': localStorage.getItem('token') },
        method: 'get',
        success: (res) => {
          const data = res.data;
          const mapData = JSON.parse(data);
          this.createMapData(mapData);
        }
      })
      this.sendWs(JSON.stringify({ url: "/basMap/lev/" + this.currentLev + "/auth", data: {} }));
    },
    changeFloor(lev) {
      this.currentLev = lev;
@@ -488,13 +489,19 @@
    },
    getCrnInfo() {
      if (this.isSwitchingFloor) { return; }
      $.ajax({
        url: baseUrl + "/console/latest/data/crn",
        headers: { 'token': localStorage.getItem('token') },
        method: 'POST',
        success: (res) => {
          if (res.code === 200) {
            var crns = res.data;
      this.sendWs(JSON.stringify({ url: "/console/latest/data/crn", data: {} }));
    },
    getSiteInfo() {
      if (this.isSwitchingFloor) { return; }
      this.sendWs(JSON.stringify({ url: "/console/latest/data/station", data: {} }));
    },
    getRgvInfo() {
      if (this.isSwitchingFloor) { return; }
      this.sendWs(JSON.stringify({ url: "/console/latest/data/rgv", data: {} }));
    },
    setCrnInfo(res) {
      let crns = Array.isArray(res) ? res : (res && res.code === 200 ? res.data : null);
      if (!crns) { return; }
            for (var i = 0; i < crns.length; i++) {
              const id = parseInt(crns[i].crnId);
              const sprite = this.pixiCrnMap.get(id);
@@ -541,29 +548,11 @@
                sprite.x = targetX;
              }
            }
          }
          this.scheduleAdjustLabels();
        }
      });
    },
    getSiteInfo() {
      if (this.isSwitchingFloor) { return; }
      $.ajax({
        url: baseUrl + "/console/latest/data/station",
        headers: { 'token': localStorage.getItem('token') },
        method: 'POST',
        success: (res) => { this.setSiteInfo(res); }
      });
    },
    getRgvInfo() {
      if (this.isSwitchingFloor) { return; }
      $.ajax({
        url: baseUrl + "/console/latest/data/rgv",
        headers: { 'token': localStorage.getItem('token') },
        method: 'POST',
        success: (res) => {
          if (res.code === 200) {
            const rgvs = res.data;
    setRgvInfo(res) {
      let rgvs = Array.isArray(res) ? res : (res && res.code === 200 ? res.data : null);
      if (!rgvs) { return; }
            for (let i = 0; i < rgvs.length; i++) {
              const id = parseInt(rgvs[i].rgvNo, 10);
              const sprite = this.pixiRgvMap.get(id);
@@ -601,10 +590,33 @@
                sprite.x = targetX;
              }
            }
          }
          this.scheduleAdjustLabels();
    },
    setMap(res) {
      this.createMapData(JSON.parse(res.data));
    },
    webSocketOnOpen(e) {
    },
    webSocketOnError(e) {
    },
    webSocketOnMessage(e) {
      const result = JSON.parse(e.data);
      if (result.url === "/console/latest/data/station" || result.url === "/console/latest/data/site") {
        this.setSiteInfo(JSON.parse(result.data));
      } else if (result.url === "/console/latest/data/crn") {
        this.setCrnInfo(JSON.parse(result.data));
      } else if (result.url === "/console/latest/data/rgv") {
        this.setRgvInfo(JSON.parse(result.data));
      } else if (typeof result.url === "string" && result.url.indexOf("/basMap/lev/") === 0) {
        this.setMap(JSON.parse(result.data));
        }
      });
    },
    webSocketClose(e) {
    },
    sendWs(message) {
      if (this.ws && this.ws.readyState === WebSocket.OPEN) {
        this.ws.send(message);
      }
    },
    createShelfSprite(width, height) {
      let idx = width + "-" + height;