From 243bb59c1d3553ecdbf1f3b2d1be1a8b34ffaf75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Mon, 9 Mar 2026 15:48:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=9D=9E=E6=95=B4=E6=95=B0=E5=B0=8F=E6=97=B6=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/components/GameInfo/index.tsx | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/game_pages/detail/components/GameInfo/index.tsx b/src/game_pages/detail/components/GameInfo/index.tsx index 1d2075b..6a967b2 100644 --- a/src/game_pages/detail/components/GameInfo/index.tsx +++ b/src/game_pages/detail/components/GameInfo/index.tsx @@ -12,14 +12,28 @@ function genGameLength(startTime: Dayjs, endTime: Dayjs) { if (!startTime || !endTime) { return ""; } - const hours = endTime.diff(startTime, "hour"); - if (Math.floor(hours / 24) >= 1) { - const leftHours = Math.floor(hours % 24); - return `${Math.floor(hours / 24)}天${ - leftHours !== 0 ? `${leftHours}小时` : "" - }`; + const totalMinutes = endTime.diff(startTime, "minute"); + const totalHours = totalMinutes / 60; + + if (totalHours >= 24) { + const days = Math.floor(totalHours / 24); + const remainingHours = totalHours % 24; + + if (remainingHours === 0) { + return `${days}天`; + } + + // 保留一位小数 + const displayHours = parseFloat(remainingHours.toFixed(1)); + return `${days}天${displayHours}小时`; } - return `${hours}小时`; + + // 如果是整数小时,不显示小数点 + if (Number.isInteger(totalHours)) { + return `${totalHours}小时`; + } + // 保留一位小数,去除末尾的0 + return `${parseFloat(totalHours.toFixed(1))}小时`; } function genGameRange(startTime: Dayjs, endTime: Dayjs) {