From 08220d98b61cc18bd5ec5bf0a5ae8a0cce92a061 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期一, 30 三月 2026 14:37:49 +0800
Subject: [PATCH] fix: 添加 Warehouse.GetAll 接口并修复前端数据解析

---
 Code/WMS/WIDESEA_WMSClient/src/views/stock/stockChat.vue |   56 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 46 insertions(+), 10 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSClient/src/views/stock/stockChat.vue b/Code/WMS/WIDESEA_WMSClient/src/views/stock/stockChat.vue
index 0f7402e..2f210cb 100644
--- a/Code/WMS/WIDESEA_WMSClient/src/views/stock/stockChat.vue
+++ b/Code/WMS/WIDESEA_WMSClient/src/views/stock/stockChat.vue
@@ -59,8 +59,12 @@
 import { ref, reactive, onMounted, onUnmounted, watch, getCurrentInstance } from 'vue'
 import * as THREE from 'three'
 import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
+import * as signalR from '@microsoft/signalr'
 
 const { proxy } = getCurrentInstance()
+
+// SignalR 杩炴帴
+let connection = null
 
 // 棰滆壊甯搁噺
 const COLOR_MAP = {
@@ -101,6 +105,39 @@
 let locationMesh = null
 let locationData = []
 let animationId = null
+
+// SignalR 鍒濆鍖�
+function initSignalR() {
+  proxy.http.post('api/User/GetCurrentUserInfo').then((result) => {
+    connection = new signalR.HubConnectionBuilder()
+      .withAutomaticReconnect()
+      .withUrl(`${proxy.http.ipAddress}stockHub?userName=${result.data.userName}`)
+      .build();
+
+    connection.start().catch((err) => console.log('SignalR杩炴帴澶辫触:', err));
+
+    connection.on('StockUpdated', (update) => {
+      // 鏇存柊瀵瑰簲璐т綅鐨勬暟鎹�
+      const idx = locationData.findIndex(x => x.locationId === update.locationId);
+      if (idx !== -1) {
+        locationData[idx].stockQuantity = update.stockQuantity;
+        locationData[idx].stockStatus = update.stockStatus;
+        // 閲嶆柊娓叉煋鍗曚釜璐т綅棰滆壊
+        updateInstanceColor(idx, update.stockStatus);
+      }
+    });
+  });
+}
+
+// 鏇存柊鍗曚釜璐т綅棰滆壊
+function updateInstanceColor(instanceId, stockStatus) {
+  if (!locationMesh) return;
+  const loc = locationData[instanceId];
+  if (!loc) return;
+  const color = getLocationColor(loc);
+  locationMesh.setColorAt(instanceId, new THREE.Color(color));
+  locationMesh.instanceColor.needsUpdate = true;
+}
 
 // 鑾峰彇璐т綅棰滆壊
 function getLocationColor(location) {
@@ -148,16 +185,11 @@
   try {
     const res = await proxy.http.get(`/api/StockInfo/Get3DLayout?warehouseId=${warehouseId}`)
     if (res.Status && res.Data) {
-      locationData = res.Data
-      // 鎻愬彇鐗╂枡缂栧彿鍜屾壒娆″垪琛�
-      const codes = new Set()
-      const batches = new Set()
-      res.Data.forEach(loc => {
-        if (loc.materielCode) codes.add(loc.materielCode)
-        if (loc.batchNo) batches.add(loc.batchNo)
-      })
-      materielCodeList.value = Array.from(codes)
-      batchNoList.value = Array.from(batches)
+      const data = res.Data
+      locationData = data.Locations || []
+      // 浣跨敤鍚庣杩斿洖鐨勭瓫閫夊垪琛�
+      materielCodeList.value = data.MaterielCodeList || []
+      batchNoList.value = data.BatchNoList || []
       // 娓叉煋璐т綅
       renderLocations()
     }
@@ -386,6 +418,7 @@
 onMounted(() => {
   initThreeJS()
   loadWarehouseList()
+  initSignalR()
   window.addEventListener('resize', onWindowResize)
 })
 
@@ -401,6 +434,9 @@
   if (renderer) {
     renderer.dispose()
   }
+  if (connection) {
+    connection.stop()
+  }
 })
 </script>
 

--
Gitblit v1.9.3