li.shaoyi 2 年之前
父節點
當前提交
d8782ae04f
共有 2 個文件被更改,包括 24 次插入22 次删除
  1. 21 15
      src/hooks/echarts/candlestick/index.ts
  2. 3 7
      src/hooks/echarts/candlestick/options.ts

+ 21 - 15
src/hooks/echarts/candlestick/index.ts

@@ -113,6 +113,26 @@ export function useCandlestickChart(goodscode: string) {
     }
 
     /**
+     * 格式化日期
+     * @param value 
+     * @returns 
+     */
+    const formatDate = (value: string) => {
+        switch (options.cycleType) {
+            case ChartCycleType.Day: {
+                return moment(value).format('YYYY-MM-DD')
+            }
+            case ChartCycleType.Hours2:
+            case ChartCycleType.Hours4: {
+                return moment(value).format('YYYY-MM-DD HH:00:00')
+            }
+            default: {
+                return moment(value).format('YYYY-MM-DD HH:mm:00')
+            }
+        }
+    }
+
+    /**
      * 更新图表数据
      */
     const updateChart = () => {
@@ -147,21 +167,7 @@ export function useCandlestickChart(goodscode: string) {
             // } else {
             // 判断时间差是否大于周期时间
             if (lastIndex === -1 || diffTime > cycleMilliseconds) {
-                const newtime = (() => {
-                    switch (options.cycleType) {
-                        case ChartCycleType.Day: {
-                            return moment(lasttime).format('YYYY-MM-DD')
-                        }
-                        case ChartCycleType.Hours2:
-                        case ChartCycleType.Hours4: {
-                            return moment(lasttime).format('YYYY-MM-DD HH:00:00')
-                        }
-                        default: {
-                            return moment(lasttime).format('YYYY-MM-DD HH:mm:00')
-                        }
-                    }
-                })()
-
+                const newtime = formatDate(lasttime)
                 // 新增K线数据
                 candlestick.source.push({
                     date: newtime,

+ 3 - 7
src/hooks/echarts/candlestick/options.ts

@@ -89,12 +89,8 @@ export function useOptions(dataset: EchartsDataset) {
                                 case ChartCycleType.Day: {
                                     return moment(params.value).format('YYYY-MM-DD')
                                 }
-                                case ChartCycleType.Hours2:
-                                case ChartCycleType.Hours4: {
-                                    return moment(params.value).format('YYYY-MM-DD HH:00:00')
-                                }
                                 default: {
-                                    return moment(params.value).format('YYYY-MM-DD HH:mm:00')
+                                    return moment(params.value).format('YYYY-MM-DD HH:mm:ss')
                                 }
                             }
                         },
@@ -352,7 +348,7 @@ export function useOptions(dataset: EchartsDataset) {
     }
 
     // 动态更新数据
-    const updateOptions = timerInterceptor.setThrottle(() => {
+    const updateOptions = () => {
         const { candlestick, macd, vol, kdj, cci } = dataset;
 
         options.candlestick = {
@@ -392,7 +388,7 @@ export function useOptions(dataset: EchartsDataset) {
                 source: cci.source,
             },
         }
-    }, 50)
+    }
 
     // 监听主题变化
     watch(appTheme, () => {