添加搜索接口
This commit is contained in:
@@ -12,4 +12,5 @@ export const API_ENDPOINTS = {
|
|||||||
UPCOMING_MATCHES: "/v1/api/matches/upcoming",
|
UPCOMING_MATCHES: "/v1/api/matches/upcoming",
|
||||||
MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`,
|
MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`,
|
||||||
ODDS: "/v1/api/odds",
|
ODDS: "/v1/api/odds",
|
||||||
|
SEARCH: "/v1/api/search",
|
||||||
};
|
};
|
||||||
|
|||||||
34
lib/api.ts
34
lib/api.ts
@@ -8,6 +8,7 @@ import {
|
|||||||
Match,
|
Match,
|
||||||
MatchDetailData,
|
MatchDetailData,
|
||||||
OddsData,
|
OddsData,
|
||||||
|
SearchResult,
|
||||||
Sport,
|
Sport,
|
||||||
UpcomingMatch,
|
UpcomingMatch,
|
||||||
} from "@/types/api";
|
} from "@/types/api";
|
||||||
@@ -146,9 +147,9 @@ export const fetchLiveScore = async (
|
|||||||
): Promise<LiveScoreMatch[]> => {
|
): Promise<LiveScoreMatch[]> => {
|
||||||
try {
|
try {
|
||||||
const params: { sport_id: number; league_id?: number; timezone?: string } =
|
const params: { sport_id: number; league_id?: number; timezone?: string } =
|
||||||
{
|
{
|
||||||
sport_id: sportId,
|
sport_id: sportId,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (leagueId) {
|
if (leagueId) {
|
||||||
params.league_id = leagueId;
|
params.league_id = leagueId;
|
||||||
@@ -227,3 +228,30 @@ export const fetchOdds = async (
|
|||||||
throw error;
|
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;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
122
types/api.ts
122
types/api.ts
@@ -71,11 +71,11 @@ export interface LiveScoreMatch {
|
|||||||
substitutes?: {
|
substitutes?: {
|
||||||
time: string;
|
time: string;
|
||||||
home_scorer:
|
home_scorer:
|
||||||
| { in: string; out: string; in_id: number; out_id: number }
|
| { in: string; out: string; in_id: number; out_id: number }
|
||||||
| any[];
|
| any[];
|
||||||
away_scorer:
|
away_scorer:
|
||||||
| { in: string; out: string; in_id: number; out_id: number }
|
| { in: string; out: string; in_id: number; out_id: number }
|
||||||
| any[];
|
| any[];
|
||||||
info: string;
|
info: string;
|
||||||
info_time: string;
|
info_time: string;
|
||||||
score: string;
|
score: string;
|
||||||
@@ -287,3 +287,117 @@ export interface OddsData {
|
|||||||
data: OddsItem[];
|
data: OddsItem[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 搜索结果 - 联赛
|
||||||
|
export interface SearchLeague {
|
||||||
|
ID: number;
|
||||||
|
CreatedAt: string;
|
||||||
|
UpdatedAt: string;
|
||||||
|
DeletedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
countryKey: string;
|
||||||
|
countryName: string;
|
||||||
|
countryLogo: string;
|
||||||
|
sportId: number;
|
||||||
|
logo: string;
|
||||||
|
description: string;
|
||||||
|
isActive: boolean;
|
||||||
|
key: string;
|
||||||
|
surface: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索结果 - 球员
|
||||||
|
export interface SearchPlayer {
|
||||||
|
ID: number;
|
||||||
|
CreatedAt: string;
|
||||||
|
UpdatedAt: string;
|
||||||
|
DeletedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
countryKey: string;
|
||||||
|
countryName: string;
|
||||||
|
countryLogo: string;
|
||||||
|
teamKey: string;
|
||||||
|
teamName: string;
|
||||||
|
teamLogo: string;
|
||||||
|
leagueKey: string;
|
||||||
|
leagueName: string;
|
||||||
|
position: string;
|
||||||
|
photo: string;
|
||||||
|
key: string;
|
||||||
|
isActive: boolean;
|
||||||
|
playerNumber: string;
|
||||||
|
playerAge: string;
|
||||||
|
playerMatchPlayed: string;
|
||||||
|
playerGoals: string;
|
||||||
|
playerYellowCards: string;
|
||||||
|
playerRedCards: string;
|
||||||
|
playerMinutes: string;
|
||||||
|
playerInjured: string;
|
||||||
|
playerSubstituteOut: string;
|
||||||
|
playerSubstitutesOnBench: string;
|
||||||
|
playerAssists: string;
|
||||||
|
playerIsCaptain: string;
|
||||||
|
playerShotsTotal: string;
|
||||||
|
playerGoalsConceded: string;
|
||||||
|
playerFoulsCommited: string;
|
||||||
|
playerTackles: string;
|
||||||
|
playerBlocks: string;
|
||||||
|
playerCrossesTotal: string;
|
||||||
|
playerInterceptions: string;
|
||||||
|
playerClearances: string;
|
||||||
|
playerDispossesed: string;
|
||||||
|
playerSaves: string;
|
||||||
|
playerInsideBoxSaves: string;
|
||||||
|
playerDuelsTotal: string;
|
||||||
|
playerDuelsWon: string;
|
||||||
|
playerDribbleAttempts: string;
|
||||||
|
playerDribbleSucc: string;
|
||||||
|
playerPenComm: string;
|
||||||
|
playerPenWon: string;
|
||||||
|
playerPenScored: string;
|
||||||
|
playerPenMissed: string;
|
||||||
|
playerPasses: string;
|
||||||
|
playerPassesAccuracy: string;
|
||||||
|
playerKeyPasses: string;
|
||||||
|
playerRating: string;
|
||||||
|
sportId: number;
|
||||||
|
playerPoints: string;
|
||||||
|
playerRebounds: string;
|
||||||
|
playerSteals: string;
|
||||||
|
playerRank: string;
|
||||||
|
playerTitles: string;
|
||||||
|
playerBday: string;
|
||||||
|
playerRuns: string;
|
||||||
|
playerWickets: string;
|
||||||
|
playerOvers: string;
|
||||||
|
stats: any;
|
||||||
|
tournaments: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索结果 - 球队
|
||||||
|
export interface SearchTeam {
|
||||||
|
ID: number;
|
||||||
|
CreatedAt: string;
|
||||||
|
UpdatedAt: string;
|
||||||
|
DeletedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
countryKey: string;
|
||||||
|
countryName: string;
|
||||||
|
countryLogo: string;
|
||||||
|
leagueKey: string;
|
||||||
|
leagueName: string;
|
||||||
|
leagueLogo: string;
|
||||||
|
logo: string;
|
||||||
|
description: string;
|
||||||
|
founded: number;
|
||||||
|
key: string;
|
||||||
|
isActive: boolean;
|
||||||
|
sportId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索结果
|
||||||
|
export interface SearchResult {
|
||||||
|
leagues: SearchLeague[];
|
||||||
|
players: SearchPlayer[];
|
||||||
|
teams: SearchTeam[];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user