From 232cdf071bfe3bd2b77ba05accba89b67fcc1edc Mon Sep 17 00:00:00 2001
From: Zhang-Hong-Lin <a3219986988@163.com>
Date: 星期四, 26 六月 2025 18:51:14 +0800
Subject: [PATCH] 优化bug与添加一键删除按钮

---
 项目代码/WCS/WIDESEAWCS_Client/src/views/Index.vue |   53 ++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 38 insertions(+), 15 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Client/src/views/Index.vue" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Client/src/views/Index.vue"
index 30ccf3d..5c2eb65 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Client/src/views/Index.vue"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Client/src/views/Index.vue"
@@ -203,6 +203,8 @@
 import store from "../store/index";
 import http from "@/../src/api/http.js";
 import { ElNotification } from "element-plus";
+import { useStore } from "vuex";
+
 export default defineComponent({
   components: {
     VolMenu,
@@ -217,8 +219,8 @@
       rightTabs: true,
       otherTabs: true,
       menuLeft: 0,
-      menuTop: 0,
-      client: null
+      menuTop: 0
+
       //  contextMenuVisible: false, // 鍙抽敭鍏抽棴鏄�/闅�
     };
   },
@@ -296,26 +298,44 @@
         toggleLeft();
       }
     };
+    const Store = useStore();
+    const s = ref(null);
 
     const handleMessage = e => {
-      let data = JSON.parse(e.data);
-      messageList.push(data);
-      ElNotification({
-        title: data.title,
-        message: h("i", { style: "color: teal" }, data.message),
-        position: "bottom-right"
-      });
+      if (e) {
+        s.value = e.data;
+        console.log("WebSocket 鏀跺埌娑堟伅: ", e.data);
+        store.dispatch("sethomedata", s.value);
+        let data = JSON.parse(e.data);
+        messageList.push(data);
+        ElNotification({
+          title: data.title,
+          message: h("i", { style: "color: teal" }, data.message),
+          position: "bottom-right"
+        });
+      }
     };
 
     const createSocket = url => {
-      // 鍒涘缓WebSocket杩炴帴
-      //"ws://127.0.0.1:9295/admin"
-      client = new WebSocket(url);
+      //console.log(url);
 
+      //鍒涘缓WebSocket杩炴帴
+      //"ws://127.0.0.1:9295/admin"
+      //client = new WebSocket("ws://192.168.0.250:9260/");
+      client = new WebSocket("ws:localhost:9260/");
       client.onopen = function() {
-        client.onmessage = handleMessage;
-        store.commit("setWebsocket", client);
+        //client.onmessage = handleMessage;
+        // store.commit("setWebsocket", client);
         console.log("WebSocket 杩炴帴鎴愬姛");
+      };
+
+      client.onmessage = function(event) {
+        // console.log("WebSocket 鏀跺埌娑堟伅: ", event);
+
+        if (event != undefined) {
+          store.dispatch("sethomedata", JSON.parse(event.data));
+        }
+        // handleMessage(event);
       };
 
       client.onclose = function() {
@@ -323,7 +343,10 @@
         setTimeout(createSocket, 10000);
       };
 
-      client.onerror = function() {};
+      client.onerror = function(err) {
+        console.log("WebSocket 杩炴帴閿欒: ", err);
+      };
+      client.onmessage();
     };
 
     const changeTheme = name => {

--
Gitblit v1.9.3