Browse Source

图表update

li.shaoyi 4 years ago
parent
commit
5f9eb085a0

+ 1 - 1
src/common/components/echart/echart-kline/index.vue

@@ -91,7 +91,7 @@ export default defineComponent({
             return result;
         };
 
-        // 监听周期变化
+        // 监听周期选项变化
         watchEffect(() => {
             loading.value = true;
             const params: QueryHistoryDatas = {

+ 3 - 5
src/common/components/echart/echart-kline/setup.ts

@@ -1,5 +1,6 @@
 import { ref, watch } from "vue";
 import { getTheme, ThemeEnum } from '@/common/config/theme';
+import { deepMerge } from '@/utils/objHandle'
 import { EChartsOption } from 'echarts';
 
 // 命名待优化
@@ -42,7 +43,7 @@ export function handleEchart() {
     // 初始化图表配置
     const initOptions = () => {
         const { datas, times, last, ma5, ma10, ma15 } = chartData.value;
-        options.value = {
+        const option: EChartsOption = {
             legend: {
                 //图例控件,点击图例控制哪些系列不显示
                 type: 'scroll',
@@ -173,10 +174,7 @@ export function handleEchart() {
             ],
         };
 
-        // 先用 setTimeout 处理,待优化深度合并
-        setTimeout(() => {
-            options.value = getColors(theme.value);
-        }, 0);
+        options.value = deepMerge(option, getColors(theme.value));
     };
 
     // 动态更新数据

+ 3 - 5
src/common/components/echart/echart-timeline/setup.ts

@@ -1,6 +1,7 @@
 import { ref, watch } from "vue";
 import { toDecimalFull } from '@/utils/number';
 import { getTheme, ThemeEnum } from '@/common/config/theme';
+import { deepMerge } from '@/utils/objHandle'
 import { EChartsOption } from 'echarts';
 import * as echarts from 'echarts';
 
@@ -58,7 +59,7 @@ export function handleEchart() {
     // 初始化图表配置
     const initOptions = () => {
         const { datas, times, yestclose, last, min, max, ma5, decimal } = chartData.value;
-        options.value = {
+        const option: EChartsOption = {
             legend: {
                 //图例控件,点击图例控制哪些系列不显示
                 type: 'scroll',
@@ -190,10 +191,7 @@ export function handleEchart() {
             ],
         };
 
-        // 先用 setTimeout 处理,待优化深度合并
-        setTimeout(() => {
-            options.value = getColors(theme.value);
-        }, 0);
+        options.value = deepMerge(option, getColors(theme.value));
     };
 
     // 动态更新数据

+ 1 - 1
src/utils/objHandle/index.ts

@@ -74,7 +74,7 @@ export function objectToUint8Array(data: object | string) {
  * 对象深度合并
  * @param target 目标对象
  * @param source 源对象
- * @returns T
+ * @returns
  */
 export const deepMerge = <T>(target: T, source: T): T => {
     for (const key in source) {