From 925b485e661682a2fcfc8b8a47a8148d16ec818e Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期六, 11 十月 2025 13:08:54 +0800
Subject: [PATCH] 新增最终数据产品月度巡查简报

---
 src/utils/echart-util.js |   42 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/src/utils/echart-util.js b/src/utils/echart-util.js
index 7f907dd..85d2841 100644
--- a/src/utils/echart-util.js
+++ b/src/utils/echart-util.js
@@ -1,3 +1,5 @@
+import * as echarts from 'echarts';
+
 function pieChartOption() {
   return {
     color: [
@@ -97,7 +99,7 @@
     legend: {
       show: true,
       orient: 'horizontal',
-      bottom: '0%', // 鍥句緥搴曢儴姘村钩鎺掑垪
+      bottom: '0%' // 鍥句緥搴曢儴姘村钩鎺掑垪
     },
     grid: {
       // left: '3%',
@@ -114,7 +116,7 @@
         alignWithLabel: true
       },
       axisLabel: {
-        rotate: 45,
+        rotate: 45
       }
     },
     yAxis: {
@@ -165,4 +167,38 @@
   document.body.removeChild(link);
 }
 
-export { pieChartOption, barChartOption, downloadChartImage };
+function getChartUrl(option) {
+  // 1. 鍒涘缓涓存椂DOM鍏冪礌
+  const div = document.createElement('div');
+  // div.style.width = '330px';
+  // div.style.height = '160px';
+  div.style.width = '800px';
+  div.style.height = '400px';
+  document.body.appendChild(div);
+
+  // 2. 鍒濆鍖杄charts瀹炰緥
+  const myChart = echarts.init(div);
+
+  // 4. 璁剧疆鍥捐〃閰嶇疆椤�
+  myChart.setOption(option);
+
+  return new Promise((resolve, reject) => {
+    // 寤惰繜鎵ц纭繚缁樺埗瀹屾垚
+    setTimeout(() => {
+      // 5. 灏嗗浘琛ㄨ浆鎹负base64鍥剧墖
+      const imageBase64 = myChart.getDataURL({
+        type: 'png',
+        pixelRatio: 2, // 鎻愰珮鍥剧墖娓呮櫚搴�
+        backgroundColor: '#fff',
+        excludeComponents: ['toolbox']
+      });
+
+      // 6. 閿�姣佸疄渚嬪苟绉婚櫎涓存椂DOM
+      myChart.dispose();
+      document.body.removeChild(div);
+      resolve(imageBase64);
+    }, 1000);
+  });
+}
+
+export { pieChartOption, barChartOption, downloadChartImage, getChartUrl };

--
Gitblit v1.9.3