实现首页功能,添加体育项目和今日比赛数据的加载,更新国际化文本,新增选择和日历模态框组件

This commit is contained in:
yuchenglong
2026-01-12 15:49:52 +08:00
parent 34b89b54c4
commit 278ddf031a
10 changed files with 785 additions and 8 deletions

46
lib/api.ts Normal file
View File

@@ -0,0 +1,46 @@
import { API_CONFIG, API_ENDPOINTS } from "@/constants/api";
import { ApiResponse, Match, Sport } from "@/types/api";
import axios from "axios";
const apiClient = axios.create({
baseURL: API_CONFIG.BASE_URL,
timeout: API_CONFIG.TIMEOUT,
headers: {
"Content-Type": "application/json",
},
});
export const fetchSports = async (): Promise<Sport[]> => {
try {
const response = await apiClient.get<ApiResponse<Sport>>(
API_ENDPOINTS.SPORTS
);
if (response.data.code === 0) {
return response.data.data.list;
}
throw new Error(response.data.message);
} catch (error) {
console.error("Fetch sports error:", error);
// Do not return mock data here — rethrow to let caller handle the error
throw error;
}
};
export const fetchTodayMatches = async (sportId: number): Promise<Match[]> => {
try {
const response = await apiClient.get<ApiResponse<Match>>(
API_ENDPOINTS.MATCHES_TODAY,
{
params: { sport_id: sportId },
}
);
if (response.data.code === 0) {
return response.data.data.list;
}
throw new Error(response.data.message);
} catch (error) {
console.error("Fetch matches error:", error);
// Let the caller handle errors; rethrow the original error
throw error;
}
};