From 325f57d62dbe1ee85a037d60049cf870672c25e8 Mon Sep 17 00:00:00 2001 From: gerson <1405270578@qq.com> Date: 星期二, 21 一月 2025 13:24:48 +0800 Subject: [PATCH] onmessage: --- src/utils/util.ts | 41 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 40 insertions(+), 1 deletions(-) diff --git a/src/utils/util.ts b/src/utils/util.ts index 093d5d7..80f11c4 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -547,6 +547,7 @@ const endDate = new Date(); const startDate = new Date(); startDate.setTime(startDate.getTime() - 3600 * 1000 * 24 * dates); + endDate.setHours(23,59,59,59) startDate.setHours(0, 0, 0, 0); return [startDate, endDate]; }; @@ -620,11 +621,28 @@ export const toPercent = (num: number, havePercentSymbol = true, decimalPlaces = 1, defaultValue = '-') => { if (num == null) return `${defaultValue} %`; - let percent = Number(num * 100).toFixed(decimalPlaces); + const factor = Math.pow(10, decimalPlaces); + + let percent = Math.round(Number(num) * 100 * factor) / factor + ''; if (havePercentSymbol) { percent += '%'; } return percent; +}; + + + +/** + * 淇濈暀鎸囧畾绮惧害灏忔暟浣嶏紝涓斾笉琛ラ浂 + * @param num + * @param precision + * @returns + */ +export const toMyFixed = (num, precision) => { + if (num == null) return ''; + if (!precision) return num + ''; + const factor = Math.pow(10, precision); + return Math.round(Number(num) * factor) / factor + ''; }; /** @@ -723,3 +741,24 @@ 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; +} + + +/** + * 浼戠湢鎸囧畾绉掓暟 + * @param seconds 浼戠湢绉掓暟 + * @returns Promise + */ +export const sleep = (seconds: number): Promise<void> => { + return new Promise((resolve) => { + setTimeout(resolve, seconds * 1000); + }); +}; -- Gitblit v1.9.3