From 01930bfaefa3761e9cd995ee64fa3f8c837cb2ec Mon Sep 17 00:00:00 2001
From: wuyouming666 <2265557248@qq.com>
Date: 星期三, 27 三月 2024 17:02:34 +0800
Subject: [PATCH] 后端推送数据落架指示

---
 UI-Project/src/views/UnLoadGlass/Landingindication.vue |   57 ++++++++++++++++++++++++++++
 UI-Project/src/utils/webSocket.js                      |    2 
 UI-Project/src/views/HomeView.vue                      |   28 +++++++-------
 3 files changed, 72 insertions(+), 15 deletions(-)

diff --git a/UI-Project/src/utils/webSocket.js b/UI-Project/src/utils/webSocket.js
index 779990b..51e5ede 100644
--- a/UI-Project/src/utils/webSocket.js
+++ b/UI-Project/src/utils/webSocket.js
@@ -6,7 +6,7 @@
 
 
 var serverPort = "/ws"; // webSocket杩炴帴绔彛
-var wsuri = "ws://127.0.0.1:12345/ws";
+var wsuri = "ws://localhost:8081/mesModuleTools";
 
 function createWebSocket(callback) {
 
diff --git a/UI-Project/src/views/HomeView.vue b/UI-Project/src/views/HomeView.vue
index 075c71e..6285749 100644
--- a/UI-Project/src/views/HomeView.vue
+++ b/UI-Project/src/views/HomeView.vue
@@ -3,21 +3,21 @@
 
 import { sendSock, createWebSocket, closeSock } from "@/utils/webSocket"
 
-function global_callback(msg) {
-  console.log("websocket鐨勫洖璋冨嚱鏁版敹鍒版湇鍔″櫒淇℃伅锛�" + JSON.stringify(msg));
-  // console.log("鏀跺埌鏈嶅姟鍣ㄤ俊鎭細" + msg);
-}
-function close(){
- closeSock();
+// function global_callback(msg) {
+//   console.log("websocket鐨勫洖璋冨嚱鏁版敹鍒版湇鍔″櫒淇℃伅锛�" + JSON.stringify(msg));
+//   // console.log("鏀跺埌鏈嶅姟鍣ㄤ俊鎭細" + msg);
+// }
+// function close(){
+//  closeSock();
 
-}
-function sendMessage(){
-  sendSock("123")
-}
-function createSocket(){
-  createWebSocket(global_callback);
-}
-</script>
+// }
+// function sendMessage(){
+//   sendSock("123")
+// }
+// function createSocket(){
+//   createWebSocket(global_callback);
+// }
+// </script>
 
 
 <template>
diff --git a/UI-Project/src/views/UnLoadGlass/Landingindication.vue b/UI-Project/src/views/UnLoadGlass/Landingindication.vue
index 62fd6f9..425f4a5 100644
--- a/UI-Project/src/views/UnLoadGlass/Landingindication.vue
+++ b/UI-Project/src/views/UnLoadGlass/Landingindication.vue
@@ -30,6 +30,7 @@
 </template>
 
 <script>
+let socket;
 export default {
   data() {
     return {
@@ -41,6 +42,9 @@
         { x: 95, y: 420, height: 60, width: 110, fillColor: '#6a6da9', item: { height: 30, width: 100, fillColor: 'yellow', content: 'NG1234561454' } }
       ]
     };
+  },
+  activated() {
+    this.initWebSocket();
   },
   methods: {
     // 璁$畻鍐呴儴鐗╁搧鐨� x 鍧愭爣浣嶇疆
@@ -62,8 +66,61 @@
       } else {
         return rack.y + rack.height - item.height;  // 杩斿洖搴曢儴瀵归綈鐨� y 鍧愭爣
       }
+    },
+    initWebSocket() {
+      let viewname = "Landingindication";
+
+      if (typeof WebSocket === "undefined") {
+        console.log("鎮ㄧ殑娴忚鍣ㄤ笉鏀寔WebSocket");
+      } else {
+        let socketUrl = "ws://" + "localhost:8081" + "/mesModuleTools/api/talk/" + viewname;
+
+        if (socket != null) {
+          socket.close();
+          socket = null;
+        }
+
+        // 寮�鍚竴涓獁ebsocket鏈嶅姟
+        socket = new WebSocket(socketUrl);
+
+        // 鎵撳紑浜嬩欢
+        socket.onopen = function () {
+          console.log("websocket宸叉墦寮�");
+        };
+
+        // 鏀跺埌娑堟伅
+        socket.onmessage = (msg) => {
+          if (!msg.data) {
+            return; // 濡傛灉鏀跺埌绌烘暟鎹紝鍒欑洿鎺ヨ繑鍥烇紝涓嶆墽琛屽悗缁�昏緫
+          }
+   
+
+          let obj = JSON.parse(msg.data);
+
+          console.log(obj);
+
+        
+
+        // 鍏抽棴浜嬩欢
+        socket.onclose = function () {
+          console.log("websocket宸插叧闂�");
+        };
+
+        // 鍙戠敓閿欒浜嬩欢
+        socket.onerror = function () {
+          console.log("websocket鍙戠敓浜嗛敊璇�");
+        };
+
+        this.$router.afterEach(function () {
+          socket.close();
+        });
+      }
     }
   }
+
+
+
+  }
 };
 </script>
 

--
Gitblit v1.8.0