From 05b2cd59596baebaebe1773c4ca3ba45deacf2e8 Mon Sep 17 00:00:00 2001
From: zzzz <690498789@qq.com>
Date: Sun, 21 Apr 2024 17:40:41 +0800
Subject: [PATCH] first

---
 src/components/trade-deep-data/index.vue |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/components/trade-deep-data/index.vue b/src/components/trade-deep-data/index.vue
index 091255a..2daf554 100644
--- a/src/components/trade-deep-data/index.vue
+++ b/src/components/trade-deep-data/index.vue
@@ -7,7 +7,7 @@
       </div>
       <div class="text-right items-end justify-end">
         <div class="">{{ $t("数量") }}</div>
-        <div class="mt-5">({{ symbol.toUpperCase() || "--" }})</div>
+        <div class="mt-5">({{ symbol | _symbolName }})</div>
       </div>
     </div>
     <div
@@ -118,7 +118,13 @@
     this.getHomeList();
   },
   watch: {
-    symbol(val) {
+    symbol() {
+      const init = [];
+      for (let i = 0; i < DEEP_LENGTH; i++) {
+        init.push({ amount: "", price: "" });
+      }
+      this.greenData = init;
+      this.redData = init;
       this.startDeepSocket();
       this.getHomeList();
     },
@@ -185,11 +191,17 @@
         this.$emit("getList", dataObj);
       });
     },
+
     startDeepSocket() {
       // 开启socket链接
       this.closeSocket();
-      console.log("start deep");
+
       this.socket = new WebSocket(`${WS_URL}/3/${this.symbol}`);
+
+      this.socket.onopen = () => {
+        console.log("WebSocket connection established");
+      };
+
       this.socket.onmessage = (evt) => {
         const { data } = evt;
         const { code, data: _data } = JSON.parse(data);
@@ -197,9 +209,23 @@
           this.handleDeep(_data);
         }
       };
+
+      this.socket.onerror = (error) => {
+        console.error("WebSocket error:", error);
+        setTimeout(this.startDeepSocket, 5000); // 5秒后尝试重新连接
+      };
+
+      this.socket.onclose = (event) => {
+        console.log("WebSocket connection closed:", event);
+        // 重新连接,可以根据需求添加重连的逻辑,这里只是简单的示例
+      };
     },
     handleDeep(data) {
       // 格式化数据
+      // console.log(this.symbol, data.symbol);
+      if (this.symbol !== data.symbol) {
+        return;
+      }
       this.deepData = data;
       if (this.selectValue >= 1) {
         this.deepData.asks.map((item) => {

--
Gitblit v1.9.3