Browse Source

#670 历史健康趋势图-X轴有重复时间点

Mr. Robot 3 months ago
parent
commit
66018f5406
2 changed files with 11 additions and 4 deletions
  1. 4 0
      src/utils/webSocketClient.ts
  2. 7 4
      src/views/HealthStatusAnalysis/mock.vue

+ 4 - 0
src/utils/webSocketClient.ts

@@ -6,6 +6,10 @@ class WebSocketClient {
       this.url = url;
       this.ws = null;
     }
+
+    get readyState(): number {
+      return this.ws ? this.ws.readyState : WebSocket.CLOSED;
+    }
   
     // 连接 WebSocket
     connect(): void {

+ 7 - 4
src/views/HealthStatusAnalysis/mock.vue

@@ -888,9 +888,12 @@ const mockStart = async (state: boolean = false) => {
     },
   ];
   xAxisData.value = [];
-  wsMockClient.connect();
-  // 向服务器发送消息
-  wsMockClient.send("你好!");
+
+  if (wsMockClient.readyState === WebSocket.CLOSED) {
+    wsMockClient.connect();
+    // 向服务器发送消息
+    wsMockClient.send("你好!");
+  }
 
   handleDateRangeChange({
     start: queryParamsMock.value.sDate,
@@ -1019,7 +1022,7 @@ const saveAttr = () => {
   showModal.value = false;
 }
 onUnmounted(() => {
-  wsMockClient.onClose();
+  wsMockClient.close();
 });
 // 获取警告提示
 const getTip = () => {