From 9674db6afd3283fea116a0bb91a339fa096feee7 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期日, 29 九月 2024 14:21:19 +0800
Subject: [PATCH] 提示请求优化

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

diff --git a/src/utils/util.ts b/src/utils/util.ts
index 5e60f34..c449200 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -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,7 +210,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;
@@ -708,3 +708,39 @@
 	if (num == null) return '';
 	return num.toFixed(precision).replace(/\.?0+$/, '');
 };
+
+
+type GetTextWidthOption = {
+	size?: string;
+	family?: string;
+};
+
+export function getTextWidth(text: string, option: GetTextWidthOption) {
+	if (!text) return 0;
+	const { size = '14px', family = 'Microsoft YaHei' } = option;
+	const spanEle = document.createElement('span');
+	document.body.appendChild(spanEle);
+
+	spanEle.style.font = 'times new roman';
+	spanEle.style.fontSize = size;
+	spanEle.style.height = 'auto';
+	spanEle.style.width = 'auto';
+	spanEle.style.position = 'absolute';
+	spanEle.style.whiteSpace = 'no-wrap';
+	spanEle.innerHTML = text;
+
+	const width = spanEle.clientWidth;
+
+	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;
+  }
\ No newline at end of file

--
Gitblit v1.9.3