From 7fc6bfe900790ec7c92bce85d5b20a95fbc06e65 Mon Sep 17 00:00:00 2001
From: 李凌 <344137771@qq.com>
Date: Wed, 15 Oct 2025 10:29:30 +0800
Subject: [PATCH] 其他人改的版本

---
 src/components/Transform/kline-charts/index.vue |   56 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/src/components/Transform/kline-charts/index.vue b/src/components/Transform/kline-charts/index.vue
index 4a289ac..f15c073 100644
--- a/src/components/Transform/kline-charts/index.vue
+++ b/src/components/Transform/kline-charts/index.vue
@@ -9,12 +9,12 @@
         </template>
         <template v-else>
           <template v-if="isNight">
-            <li v-for="item in timeList" :key="item.id" class="mr-10" :class="{ 'text-white': item.id === timeValue.id }"
-              @click="choiceTime(item)">{{ item.text }}</li>
+            <li v-for="item in timeList" :key="item.id" class="mr-10"
+              :class="{ 'text-white': item.id === timeValue.id }" @click="choiceTime(item)">{{ item.text }}</li>
           </template>
           <template v-if="!isNight">
-            <li v-for="item in timeList" :key="item.id" class="mr-10" :class="{ 'text-black': item.id === timeValue.id }"
-              @click="choiceTime(item)">{{ item.text }}</li>
+            <li v-for="item in timeList" :key="item.id" class="mr-10"
+              :class="{ 'text-black': item.id === timeValue.id }" @click="choiceTime(item)">{{ item.text }}</li>
           </template>
         </template>
       </ul>
@@ -49,6 +49,7 @@
 <script>
 import { init, dispose } from 'klinecharts'
 let chart = null
+let timer = null
 import { _getKline } from "@/service/trade.api";
 import config from './config'
 import { Loading } from 'vant';
@@ -69,7 +70,6 @@
       chartLoading: true, //加载动画
       paneId: '',
       chartData: [], // 图表数据
-      timer: null
     }
   },
   computed: {
@@ -135,7 +135,6 @@
       this.fetchData()
     },
     updateKey() { // 更新charts
-
       const dataList = chart.getDataList()
       if (dataList.length > 0) {
         const lastData = dataList[dataList.length - 1]
@@ -191,25 +190,27 @@
         chart.applyNewData(data);
         this.$emit('updataLine', false)
       })
+      
       // TODO:轮询,删掉上面那段,添加到定时器中
-      // this.timer = setInterval(() => {
-      //   _getKline(this.symbol, this.timeValue.time || time).then(data => {
-      //     this.chartLoading = false
-      //     data.map(item => {
-      //       item.timestamp = item.ts
-      //     })
-      //     let str = data[0] ? data[0].close.toString() : ''
-      //     let length = 2
-      //     if (str.indexOf('.') != -1) {
-      //       length = str.split('.')[1].length
-      //     }
-      //     //let length = data[0] ? data[0].close.toString().split('.')[1].length : 4
-      //     chart.setPriceVolumePrecision(length, 2)
-      //     this.setChartType()
-      //     chart.applyNewData(data);
-      //     this.$emit('updataLine', false)
-      //   })
-      // }, 1000);
+      this.clearTimer()
+      timer = setInterval(() => {
+        _getKline(this.symbol, this.timeValue.time || time).then(data => {
+          this.chartLoading = false
+          data.map(item => {
+            item.timestamp = item.ts
+          })
+          let str = data[0] ? data[0].close.toString() : ''
+          let length = 2
+          if (str.indexOf('.') != -1) {
+            length = str.split('.')[1].length
+          }
+          //let length = data[0] ? data[0].close.toString().split('.')[1].length : 4
+          chart.setPriceVolumePrecision(length, 2)
+          this.setChartType()
+          chart.applyNewData(data);
+          this.$emit('updataLine', false)
+        })
+      }, 30000);
     },
     setChartType() {
       let type = 'area'
@@ -234,8 +235,8 @@
       chart.createTechnicalIndicator(type, false, { id: this.paneId })
     },
     clearTimer() {
-      clearInterval(this.timer)
-      this.timer = null
+      clearInterval(timer)
+      timer = null
     },
   },
   deactivated() {
@@ -248,5 +249,4 @@
 // #kline {
 //   // min-height: 828px;
 //   height: 1200px;
-// }
-</style>
+// }</style>

--
Gitblit v1.9.3