fix: 时间展示修复

This commit is contained in:
2026-03-25 06:03:07 +08:00
parent fa41842e75
commit b84c3bb409
4 changed files with 45 additions and 68 deletions

View File

@@ -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 "";

View File

@@ -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";
@@ -50,7 +50,6 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
// }
// }, [id]);
async function changeMessageType() {
try {
const res = await DetailService.getActivityId({
@@ -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) {

View File

@@ -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) {
<View className={styles.gameInfoDateWeatherCalendarDateDate}>
<View className={styles.date}>{startDate}</View>
<View className={styles.venueTime}>
{gameRange} {game_length}
{gameRange} {game_length}
</View>
</View>
</View>

View File

@@ -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))}小时`;
}