From 3f3e2d5977787b0c6e09cd5cba7b41e5fb7d3fd0 Mon Sep 17 00:00:00 2001
From: zzzz <690498789@qq.com>
Date: Sun, 21 Apr 2024 15:59:28 +0800
Subject: [PATCH] first

---
 src/page/perpetualContract/index.vue |   66 +++++++++++++++-----------------
 1 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/src/page/perpetualContract/index.vue b/src/page/perpetualContract/index.vue
index 24dea2c..4ba2dfc 100644
--- a/src/page/perpetualContract/index.vue
+++ b/src/page/perpetualContract/index.vue
@@ -84,9 +84,9 @@
     </div>
     <div class="fixed w-full shadow z-10 tabBackground1">
       <div class="flex justify-between px-30 py-10">
-        <span class="font-24 textColor2"
-          >{{ symbol.toUpperCase() }}/USDT&nbsp;{{ $t("k线图表") }}</span
-        >
+        <span class="font-24 textColor2">
+          {{ symbol | _symbolName(1) }}&nbsp;{{ $t("k线图表") }}
+        </span>
         <van-icon
           class="textColor"
           @click.stop="showCharts = !showCharts"
@@ -207,6 +207,8 @@
   },
   methods: {
     ...mapActions("home", [SET_COIN_LIST]),
+    ...mapActions("user", ["GET_UERS_KYC"]),
+
     onUpdate(symbol) {
       // 更新
       this.symbol = symbol;
@@ -309,6 +311,9 @@
       });
     },
     handleDeep(data) {
+      if (this.symbol !== data.symbol) {
+        return;
+      }
       this.deepData = data;
       const { asks, bids } = data;
       this.asks = asks.sort((a, b) => a.price - b.price).slice(0, showLength);
@@ -330,15 +335,34 @@
       };
     },
     startDeepSocket() {
-      this.sockets.deep = new WebSocket(`${WS_URL}/3/${this.symbol}`);
-      this.sockets.deep.onmessage = (evt) => {
+      // 开启socket链接
+      this.closeSocket();
+
+      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);
         if (code / 1 === 0) {
           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);
+        // 重新连接,可以根据需求添加重连的逻辑,这里只是简单的示例
+      };
     },
+
     initParam(symbol, type) {
       // 初始化参数
       if (type === "open" || type === "long" || type === "short" || !type) {
@@ -514,6 +538,7 @@
     },
   },
   mounted() {
+    this.GET_UERS_KYC();
     let symbol = this.$route.params.symbol;
     let catchSymbol = getStorage("symbol");
     if (!symbol && catchSymbol) {
@@ -541,36 +566,7 @@
     this.symbol = symbol;
     this.init(symbol);
   },
-  // beforeRouteEnter(to, from, next) {
-  //     let { params: { symbol }, query: { selectIndex } } = to
-  //     // if(this.$route.query.selectIndex) {
-  //     //   this.selectIndex = this.$route.query.selectIndex
-  //     // }
-  //     let catchSymbol = getStorage('symbol')
-  //     if (!symbol && catchSymbol) {
-  //         symbol = catchSymbol
-  //     }
-  //     if (symbol) {
-  //         next(vm => {
-  //             if (selectIndex) {
-  //                 vm.selectIndex = selectIndex
-  //                 if (vm.selectIndex / 1 === 2) {
-  //                     vm.curTab = 'fetchFutrueHoldList'
-  //                 } else {
-  //                     //vm.curTab = 'fetchOrderListCur'
-  //                     vm.curTab = 'fetchOrderListHold'
-  //                 }
-  //             } else {
-  //                 //vm.curTab = 'fetchOrderListCur'
-  //                 vm.curTab = 'fetchOrderListHold'
-  //             }
-  //             vm.symbol = symbol
-  //             vm.init(symbol)
-  //         })
-  //     } else {
-  //         next()
-  //     }
-  // },
+
   deactivated() {
     this.closeSocket();
     this.clearTimer();

--
Gitblit v1.9.3