Skip to content

Commit

Permalink
fix: useEcharts return invalid instance
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetfan committed Jan 12, 2025
1 parent 6719e26 commit 3837b27
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/effects/plugins/src/echarts/use-echarts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { EChartsOption } from 'echarts';

import type { Ref } from 'vue';

import type { Nullable } from '@vben/types';

import type EchartsUI from './echarts-ui.vue';

import { computed, nextTick, watch } from 'vue';
Expand Down Expand Up @@ -50,17 +52,19 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
return chartInstance;
};

const renderEcharts = (options: EChartsOption, clear = true) => {
const renderEcharts = (
options: EChartsOption,
clear = true,
): Promise<Nullable<echarts.ECharts>> => {
cacheOptions = options;
const currentOptions = {
...options,
...getOptions.value,
};
return new Promise((resolve) => {
if (chartRef.value?.offsetHeight === 0) {
useTimeoutFn(() => {
renderEcharts(currentOptions);
resolve(null);
useTimeoutFn(async () => {
resolve(await renderEcharts(currentOptions));
}, 30);
return;
}
Expand All @@ -72,7 +76,7 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
}
clear && chartInstance?.clear();
chartInstance?.setOption(currentOptions);
resolve(null);
resolve(chartInstance);
}, 30);
});
});
Expand Down Expand Up @@ -109,7 +113,7 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
return {
renderEcharts,
resize,
chartInstance,
getChartInstance: () => chartInstance,
};
}

Expand Down

0 comments on commit 3837b27

Please sign in to comment.