优化详情显示
This commit is contained in:
@@ -9,10 +9,11 @@ interface FootballScoreTableProps {
|
||||
isDark: boolean;
|
||||
}
|
||||
|
||||
// 解析足球比分字符串,例如 "2-1" 或 "1-0"
|
||||
// 解析足球比分字符串,例如 "2 - 1" 或 "1-0"
|
||||
function parseFootballScore(scoreString: string): number[] {
|
||||
if (!scoreString || scoreString === "-") return [0, 0];
|
||||
const parts = scoreString.split("-");
|
||||
if (!scoreString || scoreString === "-" || scoreString.trim() === "") return [0, 0];
|
||||
// 处理 "2 - 1" 或 "2-1" 格式
|
||||
const parts = scoreString.replace(/\s+/g, "").split("-");
|
||||
if (parts.length === 2) {
|
||||
return [parseInt(parts[0]) || 0, parseInt(parts[1]) || 0];
|
||||
}
|
||||
@@ -25,27 +26,42 @@ export function FootballScoreTable({ data, isDark }: FootballScoreTableProps) {
|
||||
const bgColor = isDark ? "#1C1C1E" : "#FFF";
|
||||
const headerTextColor = isDark ? "#666" : "#999";
|
||||
|
||||
// 解析足球比分
|
||||
// 解析各种比分
|
||||
const finalScore = parseFootballScore(match.eventFinalResult || "-");
|
||||
const halftimeScore = parseFootballScore(match.eventHalftimeResult || "-");
|
||||
const ftScore = parseFootballScore(match.eventFtResult || "-");
|
||||
const penaltyScore = parseFootballScore(match.eventPenaltyResult || "-");
|
||||
|
||||
const headers = [
|
||||
t("detail.score_table.team"),
|
||||
t("detail.score_table.total"),
|
||||
t("detail.score_table.halftime"),
|
||||
];
|
||||
// 判断是否有加时赛或点球
|
||||
const hasExtraTime = ftScore[0] !== finalScore[0] || ftScore[1] !== finalScore[1];
|
||||
const hasPenalty = penaltyScore[0] > 0 || penaltyScore[1] > 0;
|
||||
|
||||
// 动态生成表头
|
||||
const headers = [t("detail.score_table.team")];
|
||||
if (hasPenalty) {
|
||||
headers.push(t("detail.score_table.penalty"));
|
||||
}
|
||||
if (hasExtraTime) {
|
||||
headers.push(t("detail.score_table.extra_time"));
|
||||
}
|
||||
headers.push(t("detail.score_table.full_time"));
|
||||
headers.push(t("detail.score_table.halftime"));
|
||||
|
||||
const rows = [
|
||||
{
|
||||
logo: match.homeTeamLogo,
|
||||
name: match.eventHomeTeam,
|
||||
total: finalScore[0],
|
||||
penalty: hasPenalty ? penaltyScore[0] : null,
|
||||
extraTime: hasExtraTime ? finalScore[0] : null,
|
||||
fullTime: hasExtraTime ? ftScore[0] : finalScore[0],
|
||||
halftime: halftimeScore[0],
|
||||
},
|
||||
{
|
||||
logo: match.awayTeamLogo,
|
||||
name: match.eventAwayTeam,
|
||||
total: finalScore[1],
|
||||
penalty: hasPenalty ? penaltyScore[1] : null,
|
||||
extraTime: hasExtraTime ? finalScore[1] : null,
|
||||
fullTime: hasExtraTime ? ftScore[1] : finalScore[1],
|
||||
halftime: halftimeScore[1],
|
||||
},
|
||||
];
|
||||
@@ -78,7 +94,17 @@ export function FootballScoreTable({ data, isDark }: FootballScoreTableProps) {
|
||||
{row.name}
|
||||
</ThemedText>
|
||||
</View>
|
||||
<ThemedText style={styles.cellText}>{row.total}</ThemedText>
|
||||
{hasPenalty && (
|
||||
<ThemedText style={styles.cellText}>
|
||||
{row.penalty !== null ? row.penalty : "-"}
|
||||
</ThemedText>
|
||||
)}
|
||||
{hasExtraTime && (
|
||||
<ThemedText style={styles.cellText}>
|
||||
{row.extraTime !== null ? row.extraTime : "-"}
|
||||
</ThemedText>
|
||||
)}
|
||||
<ThemedText style={styles.cellText}>{row.fullTime}</ThemedText>
|
||||
<ThemedText style={styles.cellText}>{row.halftime}</ThemedText>
|
||||
</View>
|
||||
))}
|
||||
|
||||
Reference in New Issue
Block a user