From 08cd84454ec525569c606e81a643fa8dc5759a35 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 25 十二月 2025 14:01:30 +0800
Subject: [PATCH] #

---
 src/main/webapp/components/MapCanvas.js  |   56 ++++++++++++++++++++++++---
 src/main/webapp/views/watch/console.html |   38 ++++++++++++++++--
 2 files changed, 82 insertions(+), 12 deletions(-)

diff --git a/src/main/webapp/components/MapCanvas.js b/src/main/webapp/components/MapCanvas.js
index c650120..736e276 100644
--- a/src/main/webapp/components/MapCanvas.js
+++ b/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);
diff --git a/src/main/webapp/views/watch/console.html b/src/main/webapp/views/watch/console.html
index 223b9bd..453bba4 100644
--- a/src/main/webapp/views/watch/console.html
+++ b/src/main/webapp/views/watch/console.html
@@ -82,12 +82,20 @@
 					rgvParam: {
 						rgvNo: 0
 					},
-					locMastData: []//搴撲綅鏁版嵁
+					locMastData: [],//搴撲綅鏁版嵁
+					wsReconnectTimer: null,
+					wsReconnectAttempts: 0,
+					wsReconnectBaseDelay: 1000,
+					wsReconnectMaxDelay: 15000
 				},
 				created() {
 					this.init()
 				},
 				mounted() {
+				},
+				beforeDestroy() {
+					if (this.wsReconnectTimer) { clearTimeout(this.wsReconnectTimer); this.wsReconnectTimer = null; }
+					if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) { try { ws.close(); } catch (e) {} }
 				},
 				watch: {
 
@@ -100,12 +108,17 @@
                     },
                     webSocketOnOpen() {
                         console.log("WebSocket杩炴帴鎴愬姛");
+                        if (this.wsReconnectTimer) { clearTimeout(this.wsReconnectTimer); this.wsReconnectTimer = null; }
+                        this.wsReconnectAttempts = 0;
+                        this.getMap();
                     },
                     webSocketOnError() {
                         console.log("WebSocket杩炴帴鍙戠敓閿欒");
+                        this.scheduleWsReconnect();
                     },
                     webSocketClose() {
                         console.log("WebSocket杩炴帴鍏抽棴");
+                        this.scheduleWsReconnect();
                     },
                     webSocketOnMessage(e) {
                         const result = JSON.parse(e.data);
@@ -140,15 +153,30 @@
                         }))
                     },
 					init() {
+						this.connectWs();
+
+						this.getSystemRunningStatus() //鑾峰彇绯荤粺杩愯鐘舵��
+						this.getLevList() //鑾峰彇鍦板浘灞傜骇鍒楄〃
+						this.getLocMastData() //鑾峰彇搴撲綅鏁版嵁
+					},
+					connectWs() {
+						if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) { return; }
 						ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
 						ws.onopen = this.webSocketOnOpen;
 						ws.onerror = this.webSocketOnError;
 						ws.onmessage = this.webSocketOnMessage;
 						ws.onclose = this.webSocketClose;
-
-						this.getSystemRunningStatus() //鑾峰彇绯荤粺杩愯鐘舵��
-						this.getLevList() //鑾峰彇鍦板浘灞傜骇鍒楄〃
-						this.getLocMastData() //鑾峰彇搴撲綅鏁版嵁
+					},
+					scheduleWsReconnect() {
+						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);
 					},
 					getLevList() {
 						let that = this;

--
Gitblit v1.9.1