From e60b190dffaa73eae9156fcef0b2a4bf9eb98dc5 Mon Sep 17 00:00:00 2001 From: yuchenglong Date: Thu, 15 Jan 2026 11:34:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=9B=B4=E6=92=AD=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E9=A1=B5=E6=97=B6=E9=97=B4=E6=98=BE=E7=A4=BA=E5=92=8C?= =?UTF-8?q?=E7=A7=92=E7=BA=A7=E8=87=AA=E5=A2=9E=E8=AE=A1=E6=97=B6=E5=99=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/live-detail/live-score-header.tsx | 67 +++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/components/live-detail/live-score-header.tsx b/components/live-detail/live-score-header.tsx index df2c719..9dbdb31 100644 --- a/components/live-detail/live-score-header.tsx +++ b/components/live-detail/live-score-header.tsx @@ -14,6 +14,50 @@ interface LiveScoreHeaderProps { export function LiveScoreHeader({ match, topInset }: LiveScoreHeaderProps) { const router = useRouter(); + const parseMin = (t: string) => parseInt(t?.match(/(\d+)/)?.[1] || "0"); + + const [minutes, setMinutes] = React.useState(parseMin(match.event_time)); + const [seconds, setSeconds] = React.useState(0); + const lastServerMinRef = React.useRef(parseMin(match.event_time)); + + // 服务器时间同步 + React.useEffect(() => { + const serverMin = parseMin(match.event_time); + // 只有当服务器分钟数变化时,才同步并重置秒数 + if (serverMin !== lastServerMinRef.current) { + setMinutes(serverMin); + setSeconds(0); + lastServerMinRef.current = serverMin; + } + }, [match.event_time]); + + // 本地秒级自增计时器 + React.useEffect(() => { + const status = match.event_status?.toLowerCase() || ""; + const isLive = + String(match.event_live) === "1" || + status.includes("live") || + status.includes("play") || + /^[12][h]$/.test(status) || + (parseInt(status) > 0 && parseInt(status) < 120); + + if (!isLive || status.includes("ht") || status.includes("half")) return; + + const interval = setInterval(() => { + setSeconds((prevSeconds) => { + if (prevSeconds >= 59) { + setMinutes((prevMinutes) => prevMinutes + 1); + return 0; + } + return prevSeconds + 1; + }); + }, 1000); + + return () => clearInterval(interval); + }, [match.event_key, match.event_live, match.event_status]); + + const displayTime = `${minutes}:${seconds.toString().padStart(2, "0")}`; + return ( - {match.event_time} + + + {match.event_status && + match.event_status.toLowerCase() !== + displayTime?.toLowerCase().replace("'", "") && ( + + {match.event_status} + + )} + {displayTime} + + {match.goalscorers && match.goalscorers.length > 0 && ( @@ -185,8 +240,18 @@ const styles = StyleSheet.create({ color: "#FF4444", fontWeight: "700", fontSize: 14, + }, + timeInfoRow: { + flexDirection: "row", + alignItems: "center", marginBottom: 4, }, + statusLabel: { + color: "#FFF", + fontWeight: "700", + fontSize: 14, + marginRight: 6, + }, lastGoalContainer: { flexDirection: "row", alignItems: "center",