From b84c3bb409dd67caf495b2a163ae0aa88b459529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=9D=B0?= Date: Wed, 25 Mar 2026 06:03:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=97=B6=E9=97=B4=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../detail/components/GameInfo/index.tsx | 30 +----------------- .../detail/components/SharePopup/index.tsx | 23 ++++++++------ src/order_pages/orderDetail/index.tsx | 31 ++----------------- src/utils/helper.ts | 29 +++++++++++++++++ 4 files changed, 45 insertions(+), 68 deletions(-) diff --git a/src/game_pages/detail/components/GameInfo/index.tsx b/src/game_pages/detail/components/GameInfo/index.tsx index 6a967b2..a2a1827 100644 --- a/src/game_pages/detail/components/GameInfo/index.tsx +++ b/src/game_pages/detail/components/GameInfo/index.tsx @@ -1,41 +1,13 @@ import Taro from "@tarojs/taro"; import dayjs, { Dayjs } from "dayjs"; import "dayjs/locale/zh-cn"; -import { calculateDistance } from "@/utils"; +import { calculateDistance, genGameLength } from "@/utils"; import { View, Image, Text, Map } from "@tarojs/components"; import img from "@/config/images"; import styles from "./index.module.scss"; dayjs.locale("zh-cn"); -function genGameLength(startTime: Dayjs, endTime: Dayjs) { - if (!startTime || !endTime) { - return ""; - } - 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}小时`; - } - - // 如果是整数小时,不显示小数点 - if (Number.isInteger(totalHours)) { - return `${totalHours}小时`; - } - // 保留一位小数,去除末尾的0 - return `${parseFloat(totalHours.toFixed(1))}小时`; -} - function genGameRange(startTime: Dayjs, endTime: Dayjs) { if (!startTime || !endTime) { return ""; diff --git a/src/game_pages/detail/components/SharePopup/index.tsx b/src/game_pages/detail/components/SharePopup/index.tsx index 663d587..31fbbdf 100644 --- a/src/game_pages/detail/components/SharePopup/index.tsx +++ b/src/game_pages/detail/components/SharePopup/index.tsx @@ -1,7 +1,7 @@ import { forwardRef, useState, useEffect, useImperativeHandle } from "react"; import { View, Button, Image, Text } from "@tarojs/components"; import Taro, { useShareAppMessage } from "@tarojs/taro"; -import dayjs from "dayjs"; +import dayjs, { Dayjs } from "dayjs"; import "dayjs/locale/zh-cn"; import classnames from "classnames"; import { generateShareImage } from "@/utils"; @@ -12,7 +12,7 @@ import WechatLogo from "@/static/detail/wechat_icon.svg"; // import WechatTimeline from "@/static/detail/wechat_timeline.svg"; import LinkIcon from "@/static/detail/link.svg"; import CrossIcon from "@/static/detail/cross.svg"; -import { genNTRPRequirementText, navto } from "@/utils/helper"; +import { genNTRPRequirementText, navto, genGameLength } from "@/utils/helper"; import { waitForAuthInit } from "@/utils/authInit"; import { useUserActions } from "@/store/userStore"; import { OSS_BASE } from "@/config/api"; @@ -43,13 +43,12 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => { // const posterRef = useRef(); const { max_participants, participant_count } = detail || {}; - + // useEffect(() => { // if (id) { // changeMessageType(); // } // }, [id]); - async function changeMessageType() { try { @@ -65,11 +64,14 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => { activityId: res.data.activity_id, // 动态消息的活动 id templateInfo: { parameterList: [ - { name: 'member_count', value: (participant_count ?? 0).toString() }, - { name: 'room_limit', value: (max_participants ?? 0).toString() }, + { + name: "member_count", + value: (participant_count ?? 0).toString(), + }, + { name: "room_limit", value: (max_participants ?? 0).toString() }, ], - templateId: '666F374D69D16C932E45D7E7D9F10CEF6177F5F5' - } + templateId: "666F374D69D16C932E45D7E7D9F10CEF6177F5F5", + }, }); } } catch (e) { @@ -162,7 +164,8 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => { const startTime = dayjs(start_time); const endTime = dayjs(end_time); const dayofWeek = DayOfWeekMap.get(startTime.day()); - const gameLength = `${endTime.diff(startTime, "hour")}小时`; + // const gameLength = `${endTime.diff(startTime, "hour")}小时`; + const game_length = genGameLength(startTime, endTime); let qrCodeUrl = ""; try { const qrCodeUrlRes = await DetailService.getQrCodeUrl({ @@ -190,7 +193,7 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => { title, locationName: location_name, date: `${startTime.format("M月D日")} (${dayofWeek})`, - time: `${startTime.format("ah")}点 ${gameLength}`, + time: `${startTime.format("ah")}点 ${game_length}`, qrCodeUrl, }); } catch (e) { diff --git a/src/order_pages/orderDetail/index.tsx b/src/order_pages/orderDetail/index.tsx index 9f697d0..6022295 100644 --- a/src/order_pages/orderDetail/index.tsx +++ b/src/order_pages/orderDetail/index.tsx @@ -21,6 +21,7 @@ import { getOrderStatus, generateOrderActions, isPhoneNumber, + genGameLength, } from "@/utils"; import { getStorage, setStorage } from "@/store/storage"; import { useGlobalStore } from "@/store/global"; @@ -75,34 +76,6 @@ function genGameNotice(order_status, start_time) { return gameNoticeMap.get(key) || {}; } -function genGameLength(startTime: Dayjs, endTime: Dayjs) { - if (!startTime || !endTime) { - return ""; - } - 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}小时`; - } - - // 如果是整数小时,不显示小数点 - if (Number.isInteger(totalHours)) { - return `${totalHours}小时`; - } - // 保留一位小数,去除末尾的0 - return `${parseFloat(totalHours.toFixed(1))}小时`; -} - function genGameRange(startTime: Dayjs, endTime: Dayjs) { if (!startTime || !endTime) { return ""; @@ -318,7 +291,7 @@ function GameInfo(props) { {startDate} - {gameRange} ({game_length}小时) + {gameRange} ({game_length}) diff --git a/src/utils/helper.ts b/src/utils/helper.ts index 16380bc..372e293 100644 --- a/src/utils/helper.ts +++ b/src/utils/helper.ts @@ -1,6 +1,7 @@ import Taro from "@tarojs/taro"; import { check_login_status, get_user_info } from "@/services/loginService"; import { useUser } from "@/store/userStore"; +import { Dayjs } from "dayjs"; // 普通函数,不调用 useLoad export const sceneRedirectLogic = (options, defaultPage: string) => { @@ -135,3 +136,31 @@ export function genNTRPRequirementText(min, max) { export function isPhoneNumber(str) { return /^1[3-9]\d{9}$/.test(str); } + +export function genGameLength(startTime: Dayjs, endTime: Dayjs) { + if (!startTime || !endTime) { + return ""; + } + 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}小时`; + } + + // 如果是整数小时,不显示小数点 + if (Number.isInteger(totalHours)) { + return `${totalHours}小时`; + } + // 保留一位小数,去除末尾的0 + return `${parseFloat(totalHours.toFixed(1))}小时`; +}