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 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-) 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