From 43521ebfcdd69b6e6efec4dae84959c3d793ab0a Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 11 十月 2024 11:39:53 +0800
Subject: [PATCH] 聊天项增加 key

---
 src/utils/util.ts |   37 ++++++++++++++++++++++++++++++++++++-
 1 files changed, 36 insertions(+), 1 deletions(-)

diff --git a/src/utils/util.ts b/src/utils/util.ts
index 13bfb8d..83c85ba 100644
--- a/src/utils/util.ts
+++ b/src/utils/util.ts
@@ -541,7 +541,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();
@@ -697,3 +698,37 @@
 export const arrayIsEmpty = (arr: any) => {
 	return !arr || arr.length === 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;
+}

--
Gitblit v1.9.3