From 17fe923ffb4e05f4fe64d78fd50be5f007f674c3 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期三, 13 十一月 2024 17:24:03 +0800
Subject: [PATCH] g6 改造

---
 src/utils/util.ts |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/utils/util.ts b/src/utils/util.ts
index 72d1e41..b378009 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -1,11 +1,11 @@
 import { ElMessage, ElMessageBox } 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)锛�
@@ -168,9 +168,9 @@
 export const convertListToTree = (
 	data: any[],
 	defaultProps = {
-		ID: 'ID',
-		Children: 'Children',
-		ParentID: 'ParentID',
+		ID: 'id',
+		Children: 'children',
+		ParentID: 'parent',
 	}
 ) => {
 	if (!data || data?.length === 0) return [];
@@ -210,11 +210,10 @@
 	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;
-
 	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;
 			}
@@ -258,7 +257,7 @@
  * @param tableData
  * @returns
  */
-export const flatten = (tableData: any[], removeChild?: boolean, children = 'Children'): any[] => {
+export const flatten = (tableData: any[], removeChild?: boolean, children = 'children'): any[] => {
 	const flattenedData: any[] = [];
 
 	for (const item of tableData) {
@@ -464,7 +463,8 @@
  * 鏈�杩� 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();
@@ -706,9 +706,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;
@@ -734,3 +735,12 @@
 	document.body.removeChild(spanEle);
 	return width;
 }
+
+export function decodeFormData(formDataString) {
+	const params = new URLSearchParams(formDataString);
+	const decodedData = {};
+	for (const [key, value] of params) {
+		decodedData[key] = decodeURIComponent(value);
+	}
+	return decodedData;
+}

--
Gitblit v1.9.3