From d5d4a5c5916257d088c0164fe769d2c6906a2ccd Mon Sep 17 00:00:00 2001 From: Sun Date: Fri, 23 Jan 2026 11:06:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(effects-plugins):=20=E6=B7=BB=E5=8A=A0=20e?= =?UTF-8?q?charts=20=E5=9B=BE=E8=A1=A8=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增 updateDate 方法用于更新 echarts 图表选项,支持合并配置、 完全替换和延迟更新等模式。该方法会在组件未初始化时自动执 行首次渲染,并能够合并全局配置如 backgroundColor 等选项。 --- .../plugins/src/echarts/use-echarts.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/effects/plugins/src/echarts/use-echarts.ts b/packages/effects/plugins/src/echarts/use-echarts.ts index 1a28fb125..b3c382852 100644 --- a/packages/effects/plugins/src/echarts/use-echarts.ts +++ b/packages/effects/plugins/src/echarts/use-echarts.ts @@ -104,6 +104,36 @@ function useEcharts(chartRef: Ref) { }); }; + const updateDate = ( + option: EChartsOption, + notMerge = false, // false = 合并(保留动画),true = 完全替换 + lazyUpdate = false, // true 时不立即重绘,适合短时间内多次调用 + ): Promise => { + return new Promise((resolve) => { + nextTick(() => { + if (!chartInstance) { + // 还没初始化 → 当作首次渲染 + renderEcharts(option).then(resolve); + return; + } + + // 合并你原有的全局配置(比如 backgroundColor) + const finalOption = { + ...option, + ...getOptions.value, + }; + + chartInstance.setOption(finalOption, { + notMerge, + lazyUpdate, + // silent: true, // 如果追求极致性能可开启(关闭所有事件) + }); + + resolve(chartInstance); + }); + }); + }; + function resize() { const el = getChartEl(); if (isElHidden(el)) { @@ -139,6 +169,7 @@ function useEcharts(chartRef: Ref) { return { renderEcharts, resize, + updateDate, getChartInstance: () => chartInstance, }; }