From 60a50d7a976f33a172421546fd891f33a21043e5 Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期三, 29 十月 2025 11:50:22 +0800
Subject: [PATCH] 优化

---
 新建文件夹/WMS/src/views/Index.vue |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WMS/src/views/Index.vue" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WMS/src/views/Index.vue"
index a087196..86268bf 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WMS/src/views/Index.vue"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WMS/src/views/Index.vue"
@@ -315,16 +315,21 @@
     };
 
     const handleMessage = (e) => {
+    //   console.log("WebSocket 杩炴帴鎴愬姛");
+    // console.log("WebSocket 鎴愬姛:"+e.data);
       let data = JSON.parse(e.data);
       messageList.push(data);
       ElNotification({
         title: data.title,
-        message: h("i", { style: "color: teal" }, data.message),
+        message: h("i", { style: "color: red" }, data.message),
         position: "bottom-right",
       });
     };
 
     const createSocket = (url) => {
+      if (client && client.readyState === WebSocket.OPEN) {
+        return; // 閬垮厤閲嶅鍒涘缓杩炴帴
+      }
       // 鍒涘缓WebSocket杩炴帴
       //"ws://127.0.0.1:9295/admin"
       client = new WebSocket(url);
@@ -333,6 +338,7 @@
         client.onmessage = handleMessage;
         store.commit("setWebsocket", client);
         console.log("WebSocket 杩炴帴鎴愬姛");
+        // client.send("鍙戦�佹暟鎹�");
       };
 
       client.onclose = function () {
@@ -340,7 +346,7 @@
         setTimeout(createSocket, 10000);
       };
 
-      client.onerror = function () {};
+      client.onerror = function (error) {console.error("WebSocket閿欒:", error);};
     };
 
     const changeTheme = (name) => {

--
Gitblit v1.9.3