接入统计进度

This commit is contained in:
yuchenglong
2026-01-16 10:09:58 +08:00
parent cc88c283ce
commit 5bf27755f3
2 changed files with 95 additions and 20 deletions

View File

@@ -16,20 +16,38 @@ export function LiveScoreHeader({ match, topInset }: LiveScoreHeaderProps) {
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));
// 解析初始时间逻辑:(event_status 分钟 - event_time 分钟) : event_time 秒
const getInitialTime = () => {
const statusIdx = parseInt(match.event_status) || 0;
const timeParts = match.event_time?.split(":") || [];
const tMin = parseInt(timeParts[0]) || 0;
const tSec = parseInt(timeParts[1]) || 0;
// 如果 event_status 是纯数字分钟数
if (!isNaN(statusIdx) && /^\d+$/.test(match.event_status)) {
return { min: Math.max(0, statusIdx - tMin), sec: tSec };
}
// 回退到解析 event_time 中的数字
return { min: tMin || parseMin(match.event_time), sec: tSec };
};
const initial = getInitialTime();
const [minutes, setMinutes] = React.useState(initial.min);
const [seconds, setSeconds] = React.useState(initial.sec);
const lastServerMatchRef = React.useRef(
`${match.event_status}-${match.event_time}`
);
// 服务器时间同步
React.useEffect(() => {
const serverMin = parseMin(match.event_time);
// 只有当服务器分钟数变化时,才同步并重置秒数
if (serverMin !== lastServerMinRef.current) {
setMinutes(serverMin);
setSeconds(0);
lastServerMinRef.current = serverMin;
const currentKey = `${match.event_status}-${match.event_time}`;
if (currentKey !== lastServerMatchRef.current) {
const updated = getInitialTime();
setMinutes(updated.min);
setSeconds(updated.sec);
lastServerMatchRef.current = currentKey;
}
}, [match.event_time]);
}, [match.event_time, match.event_status]);
// 本地秒级自增计时器
React.useEffect(() => {
@@ -114,13 +132,11 @@ export function LiveScoreHeader({ match, topInset }: LiveScoreHeaderProps) {
</View>
<View style={styles.timeInfoRow}>
{match.event_status &&
match.event_status.toLowerCase() !==
displayTime?.toLowerCase().replace("'", "") && (
<ThemedText style={styles.statusLabel}>
{match.event_status}
</ThemedText>
)}
{match.event_status && (
<ThemedText style={styles.statusLabel}>
{match.event_status}
</ThemedText>
)}
<ThemedText style={styles.timeText}>{displayTime}</ThemedText>
</View>