From fe1bcf67dfd3c59aedadf770ee5cec7f7ebcdce0 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Mon, 27 Jul 2026 15:29:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=87=8D=E5=91=BD=E5=90=8D=20utils.ts?= =?UTF-8?q?=20=E4=B8=BA=20detailUtils.ts=20=E9=81=BF=E5=85=8D=E4=B8=8E=20u?= =?UTF-8?q?tils/=20=E7=9B=AE=E5=BD=95=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/src/pages/products/detailUtils.ts | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 apps/web/src/pages/products/detailUtils.ts diff --git a/apps/web/src/pages/products/detailUtils.ts b/apps/web/src/pages/products/detailUtils.ts new file mode 100644 index 000000000..52d11b67a --- /dev/null +++ b/apps/web/src/pages/products/detailUtils.ts @@ -0,0 +1,27 @@ +/** 格式化时长(秒 → "MM:SS") */ +export const formatDuration = (seconds: number): string => { + if (!seconds || seconds <= 0) return "00:00" + const m = Math.floor(seconds / 60) + const s = Math.floor(seconds % 60) + return `${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}` +} + +/** 格式化文件大小(MB) */ +export const formatFileSize = (mb: number): string => { + if (!mb || mb <= 0) return "-" + if (mb < 1024) return `${mb.toFixed(1)} MB` + return `${(mb / 1024).toFixed(2)} GB` +} + +/** 格式化日期 */ +export const formatDate = (dateStr: string): string => { + if (!dateStr) return "-" + const d = new Date(dateStr) + return d.toLocaleDateString("zh-CN", { + year: "numeric", + month: "2-digit", + day: "2-digit", + hour: "2-digit", + minute: "2-digit", + }) +}