From 08cd84454ec525569c606e81a643fa8dc5759a35 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期四, 25 十二月 2025 14:01:30 +0800
Subject: [PATCH] #
---
src/main/webapp/views/watch/console.html | 38 +++++++++++++++++++++++++++++++++-----
1 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/src/main/webapp/views/watch/console.html b/src/main/webapp/views/watch/console.html
index 223b9bd..453bba4 100644
--- a/src/main/webapp/views/watch/console.html
+++ b/src/main/webapp/views/watch/console.html
@@ -82,12 +82,20 @@
rgvParam: {
rgvNo: 0
},
- locMastData: []//搴撲綅鏁版嵁
+ locMastData: [],//搴撲綅鏁版嵁
+ wsReconnectTimer: null,
+ wsReconnectAttempts: 0,
+ wsReconnectBaseDelay: 1000,
+ wsReconnectMaxDelay: 15000
},
created() {
this.init()
},
mounted() {
+ },
+ beforeDestroy() {
+ if (this.wsReconnectTimer) { clearTimeout(this.wsReconnectTimer); this.wsReconnectTimer = null; }
+ if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) { try { ws.close(); } catch (e) {} }
},
watch: {
@@ -100,12 +108,17 @@
},
webSocketOnOpen() {
console.log("WebSocket杩炴帴鎴愬姛");
+ if (this.wsReconnectTimer) { clearTimeout(this.wsReconnectTimer); this.wsReconnectTimer = null; }
+ this.wsReconnectAttempts = 0;
+ this.getMap();
},
webSocketOnError() {
console.log("WebSocket杩炴帴鍙戠敓閿欒");
+ this.scheduleWsReconnect();
},
webSocketClose() {
console.log("WebSocket杩炴帴鍏抽棴");
+ this.scheduleWsReconnect();
},
webSocketOnMessage(e) {
const result = JSON.parse(e.data);
@@ -140,15 +153,30 @@
}))
},
init() {
+ this.connectWs();
+
+ this.getSystemRunningStatus() //鑾峰彇绯荤粺杩愯鐘舵��
+ this.getLevList() //鑾峰彇鍦板浘灞傜骇鍒楄〃
+ this.getLocMastData() //鑾峰彇搴撲綅鏁版嵁
+ },
+ connectWs() {
+ if (ws && (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING)) { return; }
ws = new WebSocket("ws://" + window.location.host + baseUrl + "/console/websocket");
ws.onopen = this.webSocketOnOpen;
ws.onerror = this.webSocketOnError;
ws.onmessage = this.webSocketOnMessage;
ws.onclose = this.webSocketClose;
-
- this.getSystemRunningStatus() //鑾峰彇绯荤粺杩愯鐘舵��
- this.getLevList() //鑾峰彇鍦板浘灞傜骇鍒楄〃
- this.getLocMastData() //鑾峰彇搴撲綅鏁版嵁
+ },
+ scheduleWsReconnect() {
+ if (this.wsReconnectTimer) { return; }
+ const attempt = this.wsReconnectAttempts + 1;
+ const jitter = Math.floor(Math.random() * 300);
+ const delay = Math.min(this.wsReconnectMaxDelay, this.wsReconnectBaseDelay * Math.pow(2, this.wsReconnectAttempts)) + jitter;
+ this.wsReconnectTimer = setTimeout(() => {
+ this.wsReconnectTimer = null;
+ this.wsReconnectAttempts = attempt;
+ this.connectWs();
+ }, delay);
},
getLevList() {
let that = this;
--
Gitblit v1.9.1