支持时间选择器
This commit is contained in:
25
lib/api.ts
25
lib/api.ts
@@ -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 {
|
||||
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>>>(
|
||||
API_ENDPOINTS.MATCHES_TODAY,
|
||||
{
|
||||
params: { sport_id: sportId },
|
||||
params,
|
||||
}
|
||||
);
|
||||
if (response.data.code === 0) {
|
||||
|
||||
Reference in New Issue
Block a user