#
Junjie
3 天以前 08cd84454ec525569c606e81a643fa8dc5759a35
src/main/webapp/components/MapCanvas.js
@@ -14,6 +14,10 @@
      currentLev: 1,
      mapFps: 0,
      ws: null,
      wsReconnectTimer: null,
      wsReconnectAttempts: 0,
      wsReconnectBaseDelay: 1000,
      wsReconnectMaxDelay: 15000,
      pixiApp: null,
      pixiStageList: [],
      pixiStaMap: new Map(),
@@ -46,11 +50,7 @@
    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;
    this.connectWs();
    
    setTimeout(() => {
      this.getMap(this.currentLev);
@@ -67,6 +67,8 @@
    if (this.timer) { clearInterval(this.timer); }
    if (this.pixiApp) { this.pixiApp.destroy(true, { children: true }); }
    window.removeEventListener('resize', this.resizeToContainer);
    if (this.wsReconnectTimer) { clearTimeout(this.wsReconnectTimer); this.wsReconnectTimer = null; }
    if (this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING)) { try { this.ws.close(); } catch (e) {} }
  },
  watch: {
    lev(newLev) {
@@ -221,9 +223,25 @@
      this.getMap();
    },
    createMapData(map) {
      this.pixiStageList = [map.length];
      this.pixiStaMap = new Map();
      if (window.gsap) {
        this.pixiStaMap && this.pixiStaMap.forEach((s) => { try { window.gsap.killTweensOf(s); } catch (e) {} });
        this.pixiCrnMap && this.pixiCrnMap.forEach((s) => { try { window.gsap.killTweensOf(s); } catch (e) {} });
        this.pixiDualCrnMap && this.pixiDualCrnMap.forEach((s) => { try { window.gsap.killTweensOf(s); } catch (e) {} });
        this.pixiRgvMap && this.pixiRgvMap.forEach((s) => { try { window.gsap.killTweensOf(s); } catch (e) {} });
      }
      this.objectsContainer.removeChildren();
      this.objectsContainer2.removeChildren();
      if (this.tracksContainer) { this.tracksContainer.removeChildren(); }
      if (this.shelvesContainer) { this.shelvesContainer.removeChildren(); }
      this.crnList = [];
      this.dualCrnList = [];
      this.rgvList = [];
      this.pixiCrnMap = new Map();
      this.pixiDualCrnMap = new Map();
      this.pixiRgvMap = new Map();
      this.pixiStaMap = new Map();
      this.pixiStageList = [];
      this.pixiStageList = [map.length];
      const bayHeightList = this.initHeight(map);
      const bayWidthList = this.initWidth(map);
      map.forEach((item, index) => {
@@ -692,8 +710,12 @@
      this.createMapData(JSON.parse(res.data));
    },
    webSocketOnOpen(e) {
      if (this.wsReconnectTimer) { clearTimeout(this.wsReconnectTimer); this.wsReconnectTimer = null; }
      this.wsReconnectAttempts = 0;
      this.getMap(this.currentLev);
    },
    webSocketOnError(e) {
      this.scheduleReconnect();
    },
    webSocketOnMessage(e) {
      const result = JSON.parse(e.data);
@@ -710,12 +732,32 @@
      }
    },
    webSocketClose(e) {
      this.scheduleReconnect();
    },
    sendWs(message) {
      if (this.ws && this.ws.readyState === WebSocket.OPEN) {
        this.ws.send(message);
      }
    },
    connectWs() {
      if (this.ws && (this.ws.readyState === WebSocket.OPEN || this.ws.readyState === WebSocket.CONNECTING)) { return; }
      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;
    },
    scheduleReconnect() {
      if (this.wsReconnectTimer) { return; }
      const attempt = this.wsReconnectAttempts + 1;
      const jitter = Math.floor(Math.random() * 300);
      const delay = Math.min(this.wsReconnectMaxDelay, this.wsReconnectBaseDelay * Math.pow(2, this.wsReconnectAttempts)) + jitter;
      this.wsReconnectTimer = setTimeout(() => {
        this.wsReconnectTimer = null;
        this.wsReconnectAttempts = attempt;
        this.connectWs();
      }, delay);
    },
    createShelfSprite(width, height) {
      let idx = width + "-" + height;
      let texture = this.pixiShelfMap.get(idx);