接入统计进度

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

@@ -26,6 +26,54 @@ export function StatsCard({ match, isDark }: StatsCardProps) {
const [cardSwitch, setCardSwitch] = useState(true);
const [showInfo, setShowInfo] = useState(false);
// 实时时间与进度计算
const getInitialMinutes = () => {
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;
if (!isNaN(statusIdx) && /^\d+$/.test(match.event_status)) {
return { min: Math.max(0, statusIdx - tMin), sec: tSec };
}
return { min: tMin, sec: tSec };
};
const initial = getInitialMinutes();
const [minutes, setMinutes] = useState(initial.min);
const [seconds, setSeconds] = useState(initial.sec);
React.useEffect(() => {
const updated = getInitialMinutes();
setMinutes(updated.min);
setSeconds(updated.sec);
}, [match.event_time, match.event_status]);
React.useEffect(() => {
const statusStr = match.event_status?.toLowerCase() || "";
const isLive =
String(match.event_live) === "1" ||
statusStr.includes("live") ||
(parseInt(statusStr) > 0 && parseInt(statusStr) < 120);
if (!isLive || statusStr.includes("ht")) return;
const interval = setInterval(() => {
setSeconds((s) => {
if (s >= 59) {
setMinutes((m) => m + 1);
return 0;
}
return s + 1;
});
}, 1000);
return () => clearInterval(interval);
}, [match.event_key, match.event_live, match.event_status]);
const displayTime = `${minutes}:${seconds.toString().padStart(2, "0")}`;
const totalSeconds = minutes * 60 + seconds;
const progressPercent = Math.min(100, (totalSeconds / (90 * 60)) * 100);
// 从 statistics 中提取数据
const stats = match.statistics || [];
const getStatValue = (type: string) => {
@@ -194,12 +242,23 @@ export function StatsCard({ match, isDark }: StatsCardProps) {
{/* Time Progress Slider */}
<View style={styles.sliderContainer}>
<ThemedText style={styles.currentTime}>46:53</ThemedText>
<ThemedText style={styles.currentTime}>{displayTime}</ThemedText>
<View style={styles.trackContainer}>
<View style={[styles.track, isDark && { backgroundColor: "#333" }]} />
<View style={[styles.filledTrack, { width: "55%" }]} />
<View
style={[styles.filledTrack, { width: `${progressPercent}%` }]}
/>
<View style={[styles.thumb, { left: "0%" }]} />
<View style={[styles.thumb, { left: "55%" }]} />
<View
style={[
styles.thumb,
{
left: `${progressPercent}%`,
backgroundColor: "#FFAB00",
borderColor: "#FFF",
},
]}
/>
<View
style={[
styles.thumb,