From 3d73e09184bf70bdeca223cdd1f7f2599756abb3 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 07 三月 2025 14:09:51 +0800
Subject: [PATCH] 请勾选下方的业务表,按条件筛选数据

---
 src/utils/util.ts |   35 ++++++++++++++++++++++++++++++-----
 1 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/utils/util.ts b/src/utils/util.ts
index 80f11c4..8c3aeff 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -10,6 +10,7 @@
 import FileSaver from 'file-saver';
 import * as XLSX from 'xlsx';
 import { MAIN_URL } from '../constants';
+import { saveAs } from 'file-saver';
 
 /**
  * 鏅�氬璞¤浆涓� formData
@@ -284,7 +285,7 @@
 	callback: (value: T, index?, array?, parent?) => any,
 	parent: any = null,
 	markParent = false,
-	childrenKey = 'Children'
+	childrenKey = 'children'
 ) => {
 	if (!treeData || treeData.length === 0) return;
 	if (!parent) parent = treeData;
@@ -547,7 +548,7 @@
 	const endDate = new Date();
 	const startDate = new Date();
 	startDate.setTime(startDate.getTime() - 3600 * 1000 * 24 * dates);
-	endDate.setHours(23,59,59,59)
+	endDate.setHours(23, 59, 59, 59);
 	startDate.setHours(0, 0, 0, 0);
 	return [startDate, endDate];
 };
@@ -629,8 +630,6 @@
 	}
 	return percent;
 };
-
-
 
 /**
  * 淇濈暀鎸囧畾绮惧害灏忔暟浣嶏紝涓斾笉琛ラ浂
@@ -751,7 +750,6 @@
 	return decodedData;
 }
 
-
 /**
  * 浼戠湢鎸囧畾绉掓暟
  * @param seconds 浼戠湢绉掓暟
@@ -762,3 +760,30 @@
 		setTimeout(resolve, seconds * 1000);
 	});
 };
+
+
+/**
+ * 涓嬭浇鏂囦欢
+ * @param url 鏂囦欢鍦板潃
+ * [{
+		绫诲瀷: item.OTYPE,
+		鍚嶇О: item.ONAME,
+		浣嶇疆: item.WKT,
+}]
+ * @param fileName 鏂囦欢鍚�
+ */
+export const downloadExcel = (tableData: any[], fileName: string) => {
+	// 鍒涘缓宸ヤ綔绨�
+	const wb = XLSX.utils.book_new();
+	// 鍒涘缓宸ヤ綔琛�
+	const ws = XLSX.utils.json_to_sheet(tableData);
+	// 灏嗗伐浣滆〃娣诲姞鍒板伐浣滅翱
+	XLSX.utils.book_append_sheet(wb, ws, '鏌ヨ缁撴灉');
+
+	// 鐢熸垚 Excel 鏂囦欢
+	const excelBuffer = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
+	const blob = new Blob([excelBuffer], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
+
+	// 涓嬭浇鏂囦欢
+	saveAs(blob, `${fileName}_${new Date().toLocaleDateString()}.xlsx`);
+};

--
Gitblit v1.9.3