支持时间选择器

This commit is contained in:
xianyi
2026-01-14 14:19:05 +08:00
parent 7bdbdbaa18
commit 98717b0716
2 changed files with 24 additions and 4 deletions

View File

@@ -134,8 +134,7 @@ export default function HomeScreen() {
const loadMatches = async (sportId: number) => { const loadMatches = async (sportId: number) => {
setLoading(true); setLoading(true);
try { try {
// Pass selectedDate if API supported it const list = await fetchTodayMatches(sportId, selectedDate);
const list = await fetchTodayMatches(sportId);
setMatches(list); setMatches(list);
} catch (e) { } catch (e) {
console.error(e); console.error(e);

View File

@@ -74,12 +74,33 @@ export const fetchLeagues = async (
} }
}; };
export const fetchTodayMatches = async (sportId: number): Promise<Match[]> => { export const fetchTodayMatches = async (
sportId: number,
date?: Date | string
): Promise<Match[]> => {
try { try {
const params: { sport_id: number; date?: string } = {
sport_id: sportId,
};
// 如果提供了日期,格式化为 YYYY-MM-DD 格式
if (date) {
let dateStr: string;
if (date instanceof Date) {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
dateStr = `${year}-${month}-${day}`;
} else {
dateStr = date;
}
params.date = dateStr;
}
const response = await apiClient.get<ApiResponse<ApiListResponse<Match>>>( const response = await apiClient.get<ApiResponse<ApiListResponse<Match>>>(
API_ENDPOINTS.MATCHES_TODAY, API_ENDPOINTS.MATCHES_TODAY,
{ {
params: { sport_id: sportId }, params,
} }
); );
if (response.data.code === 0) { if (response.data.code === 0) {