From 32004d6bb7db528c151cca5bd78c4e557171a9ee Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期二, 23 十二月 2025 14:09:54 +0800
Subject: [PATCH] #

---
 src/main/webapp/components/MapCanvas.js |  250 ++++++++++++++++++++++++++-----------------------
 1 files changed, 131 insertions(+), 119 deletions(-)

diff --git a/src/main/webapp/components/MapCanvas.js b/src/main/webapp/components/MapCanvas.js
index 0b3705a..63b695b 100644
--- a/src/main/webapp/components/MapCanvas.js
+++ b/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.getMap(this.currentLev);
+    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,123 +489,134 @@
     },
     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;
-            for (var i = 0; i < crns.length; i++) {
-              const id = parseInt(crns[i].crnId);
-              const sprite = this.pixiCrnMap.get(id);
-              if (!sprite) { continue; }
-              const taskNo = crns[i].taskNo;
-              if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); }
-              const status = crns[i].crnStatus;
-              const statusColor = this.getCrnStatusColor(status);
-              this.updateCrnTextureColor(sprite, statusColor);
-              let bay = parseInt(crns[i].bay, 10);
-              if (isNaN(bay) || bay < 1 || bay === -2) { bay = 1; }
-              let rowIndex = (sprite.rowIndex != null) ? sprite.rowIndex : -1;
-              if (rowIndex === -1) {
-                for (let r = 0; r < this.map.length; r++) {
-                  if (this.map[r].length > 0) {
-                    const rowY = this.map[r][0].posY;
-                    if (Math.abs(rowY - sprite.y) < 0.5) { rowIndex = r; break; }
-                  }
-                }
-                if (rowIndex === -1) { rowIndex = 0; }
-              }
-              let targetCell = null;
-              let crnCount = 0;
-              for (let c = 0; c < this.map[rowIndex].length; c++) {
-                const cell = this.map[rowIndex][c];
-                if (cell && cell.type === 'crn') { crnCount++; if (crnCount === bay) { targetCell = cell; break; } }
-              }
-              if (!targetCell) {
-                for (let c = this.map[rowIndex].length - 1; c >= 0; c--) {
-                  const cell = this.map[rowIndex][c];
-                  if (cell && cell.type === 'crn') { targetCell = cell; break; }
-                }
-              }
-              if (!targetCell) { continue; }
-              const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2;
-              const dx = Math.abs(targetX - sprite.x);
-              if (dx < 1) {
-              } else if (dx < 5) {
-                sprite.x = targetX;
-              } else if (window.gsap) {
-                window.gsap.killTweensOf(sprite);
-                window.gsap.to(sprite, { x: targetX, duration: 0.3, ease: "power1.inOut" });
-              } else {
-                sprite.x = targetX;
-              }
-            }
-          }
-          this.scheduleAdjustLabels();
-        }
-      });
+      this.sendWs(JSON.stringify({ url: "/console/latest/data/crn", data: {} }));
     },
     getSiteInfo() {
       if (this.isSwitchingFloor) { return; }
-      $.ajax({
-        url: baseUrl + "/console/latest/data/station",
-        headers: { 'token': localStorage.getItem('token') },
-        method: 'POST',
-        success: (res) => { this.setSiteInfo(res); }
-      });
+      this.sendWs(JSON.stringify({ url: "/console/latest/data/station", data: {} }));
     },
     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;
-            for (let i = 0; i < rgvs.length; i++) {
-              const id = parseInt(rgvs[i].rgvNo, 10);
-              const sprite = this.pixiRgvMap.get(id);
-              if (!sprite) { continue; }
-              const taskNo = rgvs[i].taskNo;
-              if (sprite.textObj) { if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); } }
-              const statusColor = this.getRgvStatusColor(rgvs[i].rgvStatus);
-              this.updateRgvTextureColor(sprite, statusColor);
-              let trackSiteNo = parseInt(rgvs[i].trackSiteNo, 10);
-              if (!trackSiteNo || trackSiteNo <= 0) { continue; }
-              let rowIndex = (sprite.rowIndex != null) ? sprite.rowIndex : 0;
-              let targetCell = null;
-              for (let c = 0; c < this.map[rowIndex].length; c++) {
-                const cell = this.map[rowIndex][c];
-                if (!cell || cell.type !== 'rgv') { continue; }
-                const ts = this.getTrackSiteNo(cell.value);
-                if (ts === trackSiteNo) { targetCell = cell; break; }
-              }
-              if (!targetCell) {
-                for (let c = this.map[rowIndex].length - 1; c >= 0; c--) {
-                  const cell = this.map[rowIndex][c];
-                  if (cell && cell.type === 'rgv') { targetCell = cell; break; }
-                }
-              }
-              if (!targetCell) { continue; }
-              const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2;
-              const dx = Math.abs(targetX - sprite.x);
-              if (dx < 1) {
-              } else if (dx < 5) {
-                sprite.x = targetX;
-              } else if (window.gsap) {
-                window.gsap.killTweensOf(sprite);
-                window.gsap.to(sprite, { x: targetX, duration: 0.3, ease: "power1.inOut" });
-              } else {
-                sprite.x = targetX;
-              }
+      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);
+        if (!sprite) { continue; }
+        const taskNo = crns[i].taskNo;
+        if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); }
+        const status = crns[i].crnStatus;
+        const statusColor = this.getCrnStatusColor(status);
+        this.updateCrnTextureColor(sprite, statusColor);
+        let bay = parseInt(crns[i].bay, 10);
+        if (isNaN(bay) || bay < 1 || bay === -2) { bay = 1; }
+        let rowIndex = (sprite.rowIndex != null) ? sprite.rowIndex : -1;
+        if (rowIndex === -1) {
+          for (let r = 0; r < this.map.length; r++) {
+            if (this.map[r].length > 0) {
+              const rowY = this.map[r][0].posY;
+              if (Math.abs(rowY - sprite.y) < 0.5) { rowIndex = r; break; }
             }
           }
-          this.scheduleAdjustLabels();
+          if (rowIndex === -1) { rowIndex = 0; }
         }
-      });
+        let targetCell = null;
+        let crnCount = 0;
+        for (let c = 0; c < this.map[rowIndex].length; c++) {
+          const cell = this.map[rowIndex][c];
+          if (cell && cell.type === 'crn') { crnCount++; if (crnCount === bay) { targetCell = cell; break; } }
+        }
+        if (!targetCell) {
+          for (let c = this.map[rowIndex].length - 1; c >= 0; c--) {
+            const cell = this.map[rowIndex][c];
+            if (cell && cell.type === 'crn') { targetCell = cell; break; }
+          }
+        }
+        if (!targetCell) { continue; }
+        const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2;
+        const dx = Math.abs(targetX - sprite.x);
+        if (dx < 1) {
+        } else if (dx < 5) {
+          sprite.x = targetX;
+        } else if (window.gsap) {
+          window.gsap.killTweensOf(sprite);
+          window.gsap.to(sprite, { x: targetX, duration: 0.3, ease: "power1.inOut" });
+        } else {
+          sprite.x = targetX;
+        }
+      }
+      this.scheduleAdjustLabels();
+    },
+    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);
+        if (!sprite) { continue; }
+        const taskNo = rgvs[i].taskNo;
+        if (sprite.textObj) { if (taskNo != null && taskNo > 0) { sprite.textObj.text = id + "(" + taskNo + ")"; } else { sprite.textObj.text = String(id); } }
+        const statusColor = this.getRgvStatusColor(rgvs[i].rgvStatus);
+        this.updateRgvTextureColor(sprite, statusColor);
+        let trackSiteNo = parseInt(rgvs[i].trackSiteNo, 10);
+        if (!trackSiteNo || trackSiteNo <= 0) { continue; }
+        let rowIndex = (sprite.rowIndex != null) ? sprite.rowIndex : 0;
+        let targetCell = null;
+        for (let c = 0; c < this.map[rowIndex].length; c++) {
+          const cell = this.map[rowIndex][c];
+          if (!cell || cell.type !== 'rgv') { continue; }
+          const ts = this.getTrackSiteNo(cell.value);
+          if (ts === trackSiteNo) { targetCell = cell; break; }
+        }
+        if (!targetCell) {
+          for (let c = this.map[rowIndex].length - 1; c >= 0; c--) {
+            const cell = this.map[rowIndex][c];
+            if (cell && cell.type === 'rgv') { targetCell = cell; break; }
+          }
+        }
+        if (!targetCell) { continue; }
+        const targetX = targetCell.posX + (targetCell.width - sprite.width) / 2;
+        const dx = Math.abs(targetX - sprite.x);
+        if (dx < 1) {
+        } else if (dx < 5) {
+          sprite.x = targetX;
+        } else if (window.gsap) {
+          window.gsap.killTweensOf(sprite);
+          window.gsap.to(sprite, { x: targetX, duration: 0.3, ease: "power1.inOut" });
+        } else {
+          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;

--
Gitblit v1.9.1