From 5270308151082506e0e6df2c72d278d2976ec860 Mon Sep 17 00:00:00 2001
From: liulijun <liulijun@hnkhzn.com>
Date: 星期三, 29 四月 2026 10:28:58 +0800
Subject: [PATCH] WCS设备监控
---
项目代码/WCS/WCSClient/src/uitils/websocket.js | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSClient/src/uitils/websocket.js" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSClient/src/uitils/websocket.js"
index d15ff7f..82c33fc 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSClient/src/uitils/websocket.js"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WCSClient/src/uitils/websocket.js"
@@ -1,7 +1,7 @@
import { ref, reactive } from 'vue';
export const useWebSocket = (protocols) => {
- const ws = new WebSocket("ws://localhost:9260/", protocols);
+ let ws = null;
const messages = ref([]);
const status = reactive({
isConnected: false,
@@ -10,6 +10,8 @@
// 浜嬩欢鐩戝惉
const connect = () => {
+ // 鍒涘缓鏂扮殑WebSocket瀹炰緥锛屼娇鐢ㄩ厤缃枃浠朵腑閰嶇疆鐨勭鍙�
+ ws = new WebSocket("ws://localhost:9260/", protocols);
ws.onopen = () => {
status.isConnected = true;
console.log('WebSocket 杩炴帴鎴愬姛');
@@ -41,7 +43,7 @@
// 鍙戦�佹秷鎭柟娉�
const send = (data) => {
- if (status.isConnected) {
+ if (status.isConnected && ws) {
ws.send(JSON.stringify(data));
}
};
@@ -51,6 +53,7 @@
messages,
status,
send,
- close: () => ws.close()
+ close: () => ws && ws.close(),
+ reconnect: connect
};
};
\ No newline at end of file
--
Gitblit v1.9.3