接口添加时间与时区&赔率

This commit is contained in:
xianyi
2026-01-14 15:14:09 +08:00
parent 1bd10694bf
commit 8dc87c9b29
7 changed files with 149 additions and 13 deletions

View File

@@ -6,6 +6,7 @@ import {
League,
Match,
MatchDetailData,
OddsData,
Sport,
UpcomingMatch,
} from "@/types/api";
@@ -76,11 +77,12 @@ export const fetchLeagues = async (
export const fetchTodayMatches = async (
sportId: number,
date?: Date | string
date?: Date | string,
timezone?: string
): Promise<Match[]> => {
try {
const params: { sport_id: number; date?: string } = {
sport_id: sportId,
const params: { sportId: number; date?: string; timezone?: string } = {
sportId,
};
// 如果提供了日期,格式化为 YYYY-MM-DD 格式
@@ -97,6 +99,11 @@ export const fetchTodayMatches = async (
params.date = dateStr;
}
// 如果提供了时区,传给后端;不传则由后端使用本地时区
if (timezone) {
params.timezone = timezone;
}
const response = await apiClient.get<ApiResponse<ApiListResponse<Match>>>(
API_ENDPOINTS.MATCHES_TODAY,
{
@@ -159,3 +166,30 @@ export const fetchUpcomingMatches = async (
throw error;
}
};
// 获取实时赔率(足球/网球使用 LiveOdds篮球/板球使用 Odds
export const fetchOdds = async (
sportId: number,
matchId: number
): Promise<OddsData> => {
try {
const response = await apiClient.get<ApiResponse<OddsData>>(
API_ENDPOINTS.ODDS,
{
params: {
sport_id: sportId,
match_id: matchId,
},
}
);
if (response.data.code === 0) {
return response.data.data;
}
throw new Error(response.data.message);
} catch (error) {
console.error("Fetch odds error:", error);
throw error;
}
};