From 75a462f8ee30491f05d29ccac1b65d31e835957b Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 20 八月 2025 15:57:14 +0800
Subject: [PATCH] 档案管理调整

---
 src/components/Echarts/echarts.vue |   68 ++++++++++++++++++++--------------
 1 files changed, 40 insertions(+), 28 deletions(-)

diff --git a/src/components/Echarts/echarts.vue b/src/components/Echarts/echarts.vue
index 15e74d8..d8264ad 100644
--- a/src/components/Echarts/echarts.vue
+++ b/src/components/Echarts/echarts.vue
@@ -1,6 +1,7 @@
 <template>
-  <div>
+  <div style="position: relative;">
     <div ref="chartRef" :style="chartStyle"></div>
+    <slot></slot>
   </div>
 </template>
 
@@ -51,15 +52,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 +71,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 +90,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 = 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,
@@ -108,7 +119,7 @@
     series: props.series,
     grid: props.grid,
     legend: props.legend,
-    tooltip: props.tooltip
+    tooltip: props.tooltip,
   }
   
   chartInstance.clear()
@@ -136,12 +147,13 @@
 })
 
 // Watch all reactive props that affect the chart
-watchEffect(() => {
-  // 閬垮厤鍦� mounted 鍓嶈Е鍙�
-  if (chartInstance) {
-    renderChart()
-  }
-}, {
-  flush: 'post'
-})
+watch(
+    () => [props.xAxis, props.series, props.legend, props.tooltip],
+    () => {
+      if (chartInstance) {
+        renderChart()
+      }
+    },
+    { deep: true, immediate: true }
+)
 </script>
\ No newline at end of file

--
Gitblit v1.9.3