mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-26 21:14:32 +08:00
feat(effects-plugins): 添加 echarts 图表更新功能
新增 updateDate 方法用于更新 echarts 图表选项,支持合并配置、 完全替换和延迟更新等模式。该方法会在组件未初始化时自动执 行首次渲染,并能够合并全局配置如 backgroundColor 等选项。
This commit is contained in:
@@ -104,6 +104,36 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateDate = (
|
||||||
|
option: EChartsOption,
|
||||||
|
notMerge = false, // false = 合并(保留动画),true = 完全替换
|
||||||
|
lazyUpdate = false, // true 时不立即重绘,适合短时间内多次调用
|
||||||
|
): Promise<echarts.ECharts | null> => {
|
||||||
|
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() {
|
function resize() {
|
||||||
const el = getChartEl();
|
const el = getChartEl();
|
||||||
if (isElHidden(el)) {
|
if (isElHidden(el)) {
|
||||||
@@ -139,6 +169,7 @@ function useEcharts(chartRef: Ref<EchartsUIType>) {
|
|||||||
return {
|
return {
|
||||||
renderEcharts,
|
renderEcharts,
|
||||||
resize,
|
resize,
|
||||||
|
updateDate,
|
||||||
getChartInstance: () => chartInstance,
|
getChartInstance: () => chartInstance,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user