diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index e9fad51..e8893b7 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -134,8 +134,7 @@ export default function HomeScreen() { const loadMatches = async (sportId: number) => { setLoading(true); try { - // Pass selectedDate if API supported it - const list = await fetchTodayMatches(sportId); + const list = await fetchTodayMatches(sportId, selectedDate); setMatches(list); } catch (e) { console.error(e); diff --git a/lib/api.ts b/lib/api.ts index 13ad268..e0e2df2 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -74,12 +74,33 @@ export const fetchLeagues = async ( } }; -export const fetchTodayMatches = async (sportId: number): Promise => { +export const fetchTodayMatches = async ( + sportId: number, + date?: Date | string +): Promise => { 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>>( API_ENDPOINTS.MATCHES_TODAY, { - params: { sport_id: sportId }, + params, } ); if (response.data.code === 0) {