From 98717b07165ddee979dac85ba32c33acbd5c4587 Mon Sep 17 00:00:00 2001 From: xianyi Date: Wed, 14 Jan 2026 14:19:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=97=B6=E9=97=B4=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(tabs)/index.tsx | 3 +-- lib/api.ts | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) 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) {