From 7e59b188fb37d48d39e8c35b8bbced3836f4dd6d Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期二, 11 二月 2025 16:30:42 +0800
Subject: [PATCH] python code node

---
 src/utils/util.ts |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/utils/util.ts b/src/utils/util.ts
index 3f95fee..a317c29 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -1,11 +1,11 @@
-import { ElMessage, ElMessageBox } from 'element-plus';
+import { ElMessage, ElMessageBox, ElMessageBoxOptions } from 'element-plus';
 import JSONbig from 'json-bigint';
+
 import { storeToRefs } from 'pinia';
 import { unref, type Ref } from 'vue';
 import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
 import { useThemeConfig } from '/@/stores/themeConfig';
 import request from '/@/utils/request';
-
 /**
  * @description 褰撶鍒� JSON 涓瓨鍦ㄨ繃闀跨殑鏁板瓧鏃讹紝浣跨敤 JSONbigString 瑙f瀽锛屾暟瀛椾細杞负瀛楃涓插鐞�
  * 鐢ㄦ硶锛欽SONbigString.parse(jsonStr)锛�
@@ -110,8 +110,8 @@
 
 export const getImg = (name) => `src/assets/images/${name}`;
 
-export const downloadJSON = (jsonData: Object, fileName: String) => {
-	const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(JSON.stringify(jsonData));
+export const downloadJSON = (jsonData: string, fileName: String) => {
+	const dataStr = 'data:text/json;charset=utf-8,' + encodeURIComponent(jsonData);
 	const downloadAnchorNode = document.createElement('a');
 	downloadAnchorNode.setAttribute('href', dataStr);
 	downloadAnchorNode.setAttribute('download', fileName + '.json');
@@ -214,7 +214,6 @@
 ) => {
 	if (!treeData || treeData.length === 0) return;
 	if (!parent) parent = treeData;
-
 	for (let index = 0; index < treeData.length; index++) {
 		const value = treeData[index] as any;
 		if (markParent) {
@@ -233,7 +232,7 @@
 
 		if (value[childrenKey] && value[childrenKey].length !== 0) {
 			// 閫掑綊璺冲嚭
-			const callResult = travelTree(value[childrenKey], callback, value, markParent);
+			const callResult = travelTree(value[childrenKey], callback, value, markParent, childrenKey);
 			if (callResult) {
 				return true;
 			}
@@ -464,12 +463,14 @@
  * 鏈�杩� n 澶╃殑 startDate銆乪ndDate
  * @param dates
  */
-export const getRecentDateRange = (dates: number) => {
+export const getRecentDateRange = (dates: number, includesCurrent = true) => {
+	dates = includesCurrent ? dates - 1 : dates;
 	// 鑾峰彇褰撳墠鏃ユ湡
 	const endDate = new Date();
 	const startDate = new Date();
 	startDate.setTime(startDate.getTime() - 3600 * 1000 * 24 * dates);
 	startDate.setHours(0, 0, 0, 0);
+	endDate.setHours(23, 59, 59, 59);
 	return [startDate, endDate];
 };
 
@@ -706,9 +707,10 @@
  */
 export const toMyFixed = (num, precision) => {
 	if (num == null) return '';
-	return num.toFixed(precision).replace(/\.?0+$/, '');
+	if (!precision) return num + '';
+	const factor = Math.pow(10, precision);
+	return Math.round(Number(num) * factor) / factor + '';
 };
-
 
 type GetTextWidthOption = {
 	size?: string;
@@ -735,12 +737,26 @@
 	return width;
 }
 
-
 export function decodeFormData(formDataString) {
 	const params = new URLSearchParams(formDataString);
 	const decodedData = {};
 	for (const [key, value] of params) {
-	  decodedData[key] = decodeURIComponent(value);
+		decodedData[key] = decodeURIComponent(value);
 	}
 	return decodedData;
-  }
\ No newline at end of file
+}
+
+export const elConfirm = (
+	message,
+	options: ElMessageBoxOptions = {
+		confirmButtonText: '纭畾',
+		cancelButtonText: '鍙栨秷',
+		type: 'warning',
+	}
+) => {
+	return new Promise((resolve, reject) => {
+		ElMessageBox.confirm(message, '鎻愮ず', options)
+			.then(() => resolve(true))
+			.catch(() => reject(false));
+	});
+};

--
Gitblit v1.9.3