From b0b31b379cfb6e57ffc14b3d8804256df25a1ac3 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期三, 09 十月 2024 16:01:01 +0800
Subject: [PATCH] metric -> metrics

---
 src/utils/util.ts |   84 +++++++++++++++++++++++++++++++++---------
 1 files changed, 66 insertions(+), 18 deletions(-)

diff --git a/src/utils/util.ts b/src/utils/util.ts
index ca816d4..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;
@@ -413,8 +413,8 @@
  */
 export const deleteCurrentRow = (
 	row: {
-		ID: string;
-		Name: string;
+		id: string;
+		title: string;
 		[key: string]: any;
 	},
 	label: String,
@@ -424,7 +424,7 @@
 	showRowName = true,
 	extraParams: Record<string, any> = {}
 ) => {
-	const tip = showRowName ? `纭畾鍒犻櫎${label}锛氥��${row.Name}銆戯紵` : `纭畾鍒犻櫎褰撳墠${label}锛焋;
+	const tip = showRowName ? `纭畾鍒犻櫎${label}锛氥��${row.title}銆戯紵` : `纭畾鍒犻櫎褰撳墠${label}锛焋;
 	ElMessageBox.confirm(tip, '鎻愮ず', {
 		confirmButtonText: '纭畾',
 		cancelButtonText: '鍙栨秷',
@@ -436,17 +436,13 @@
 		}
 		const res = await deleteApi(
 			{
-				ID: row.ID,
+				id: row.id,
 				...rawExtraParams,
 			},
 			req
 		);
-		if (res.Data) {
-			ElMessage.success(`鍒犻櫎${label}鎴愬姛`);
-			callback(row.ID);
-		} else {
-			ElMessage.error(`鍒犻櫎${label}澶辫触`);
-		}
+		ElMessage.success(`鍒犻櫎${label}鎴愬姛`);
+		callback(row.id);
 	});
 };
 
@@ -579,7 +575,23 @@
 		}, wait);
 	};
 };
-
+/**
+ * 鏂囦欢澶у皬瀛楄妭杞崲涓篨XX
+ * @param size 瀛楄妭澶у皬
+ * @returns {string|*}
+ */
+export const convertFileSize = (size) => {
+	if (!size && size !== 0) return '';
+	if (size < pow1024(1)) return size + ' B';
+	if (size < pow1024(2)) return (size / pow1024(1)).toFixed(2) + ' KB';
+	if (size < pow1024(3)) return (size / pow1024(2)).toFixed(2) + ' MB';
+	if (size < pow1024(4)) return (size / pow1024(3)).toFixed(2) + ' GB';
+	return (size / pow1024(4)).toFixed(2) + ' TB';
+};
+// 姹傛骞�
+function pow1024(num) {
+	return Math.pow(1024, num);
+}
 /**
  *
  * @param {*} func 鑺傛祦鍑芥暟
@@ -688,11 +700,47 @@
 
 /**
  * 淇濈暀鎸囧畾绮惧害灏忔暟浣嶏紝涓斾笉琛ラ浂
- * @param num 
- * @param precision 
- * @returns 
+ * @param num
+ * @param precision
+ * @returns
  */
 export const toMyFixed = (num, precision) => {
 	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