添加搜索接口

This commit is contained in:
xianyi
2026-01-15 10:03:50 +08:00
parent 5c98436a66
commit 0dbc5aa11b
3 changed files with 150 additions and 7 deletions

View File

@@ -8,6 +8,7 @@ import {
Match,
MatchDetailData,
OddsData,
SearchResult,
Sport,
UpcomingMatch,
} from "@/types/api";
@@ -146,9 +147,9 @@ export const fetchLiveScore = async (
): Promise<LiveScoreMatch[]> => {
try {
const params: { sport_id: number; league_id?: number; timezone?: string } =
{
sport_id: sportId,
};
{
sport_id: sportId,
};
if (leagueId) {
params.league_id = leagueId;
@@ -227,3 +228,30 @@ export const fetchOdds = async (
throw error;
}
};
// 搜索联赛、球队或球员
export const fetchSearch = async (
query: string,
sportId?: number
): Promise<SearchResult> => {
try {
const params: { q: string; sportId?: number } = { q: query };
if (sportId) {
params.sportId = sportId;
}
const response = await apiClient.get<ApiResponse<SearchResult>>(
API_ENDPOINTS.SEARCH,
{ params }
);
if (response.data.code === 0) {
return response.data.data;
}
throw new Error(response.data.message);
} catch (error) {
console.error("Fetch search error:", error);
throw error;
}
};