From cb78cb10939dc95b55e26b68cd805f2717ea48f0 Mon Sep 17 00:00:00 2001 From: gaoluyang <2820782392@qq.com> Date: 星期一, 28 七月 2025 17:55:13 +0800 Subject: [PATCH] 1.首页联调 --- src/components/Echarts/echarts.vue | 63 ++++++++++++++++++------------- 1 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/components/Echarts/echarts.vue b/src/components/Echarts/echarts.vue index 15e74d8..2c51ace 100644 --- a/src/components/Echarts/echarts.vue +++ b/src/components/Echarts/echarts.vue @@ -51,15 +51,15 @@ }, lineColors: { type: Array, - default: () => ['#A4EEDA', '#86C1F4', '#91A0FC', '#F6C18B', '#F09595'] + default: () => [] }, barColors: { type: Array, - default: () => ['#A4EEDA', '#86C1F4', '#91A0FC', '#F6C18B', '#F09595'] + default: () => [] }, pieColors: { type: Array, - default: () => ['#A4EEDA', '#86C1F4', '#91A0FC', '#F6C18B', '#F09595'] + default: () => [] }, loadingOption: { type: Object, @@ -70,8 +70,18 @@ maskColor: 'rgba(255, 255, 255, 0.8)', zlevel: 0 }) - } + }, + color: { + type: Array, + default: () => [] + }, + option: { + type: Object, + default: () => ({}) + }, }) + +import { watch } from 'vue' // Refs const chartRef = ref(null) @@ -79,28 +89,28 @@ // Methods function generateChart(option) { - if (option.series && option.series.length > 0) { - option.series.forEach((s, index) => { - if (s.type === 'line') { - s.itemStyle = { - color: props.lineColors[index] || props.lineColors[0] - } - s.lineStyle = { - color: props.lineColors[index] || props.lineColors[0] - } - } else if (s.type === 'bar') { - s.itemStyle = { - color: props.barColors[index] || props.barColors[0] - } + const copiedOption = JSON.parse(JSON.stringify(option)) // 鉁� 娣辨嫹璐� + + if (copiedOption.series && copiedOption.series.length > 0) { + copiedOption.series.forEach((s, index) => { + if (s.type === 'line' && props.lineColors.length) { + s.itemStyle = s.itemStyle || {} + s.lineStyle = s.lineStyle || {} + s.itemStyle.color = props.lineColors[index] || props.lineColors[0] + s.lineStyle.color = props.lineColors[index] || props.lineColors[0] + } else if (s.type === 'bar' && props.barColors.length) { + s.itemStyle = s.itemStyle || {} + s.itemStyle.color = props.barColors[index] || props.barColors[0] } }) } - chartInstance.setOption(option) + chartInstance.setOption(copiedOption) } function renderChart() { const option = { + color: props.color.length ? props.color : undefined, backgroundColor: props.options.backgroundColor || '#fff', xAxis: props.xAxis, yAxis: props.yAxis, @@ -136,12 +146,13 @@ }) // Watch all reactive props that affect the chart -watchEffect(() => { - // 閬垮厤鍦� mounted 鍓嶈Е鍙� - if (chartInstance) { - renderChart() - } -}, { - flush: 'post' -}) +watch( + () => [props.xAxis, props.series], + () => { + if (chartInstance) { + renderChart() + } + }, + { deep: true, immediate: true } +) </script> \ No newline at end of file -- Gitblit v1.9.3