From 0dbc5aa11baf11664e930345558767dcf0f1f933 Mon Sep 17 00:00:00 2001 From: xianyi Date: Thu, 15 Jan 2026 10:03:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=90=9C=E7=B4=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- constants/api.ts | 1 + lib/api.ts | 34 +++++++++++-- types/api.ts | 122 +++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 150 insertions(+), 7 deletions(-) diff --git a/constants/api.ts b/constants/api.ts index 39aba38..8289a31 100644 --- a/constants/api.ts +++ b/constants/api.ts @@ -12,4 +12,5 @@ export const API_ENDPOINTS = { UPCOMING_MATCHES: "/v1/api/matches/upcoming", MATCH_DETAIL: (id: string) => `/v1/api/matches/${id}`, ODDS: "/v1/api/odds", + SEARCH: "/v1/api/search", }; diff --git a/lib/api.ts b/lib/api.ts index e0470cf..4687368 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -8,6 +8,7 @@ import { Match, MatchDetailData, OddsData, + SearchResult, Sport, UpcomingMatch, } from "@/types/api"; @@ -146,9 +147,9 @@ export const fetchLiveScore = async ( ): Promise => { 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 => { + try { + const params: { q: string; sportId?: number } = { q: query }; + if (sportId) { + params.sportId = sportId; + } + + const response = await apiClient.get>( + 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; + } +}; diff --git a/types/api.ts b/types/api.ts index d2b731b..2edda57 100644 --- a/types/api.ts +++ b/types/api.ts @@ -71,11 +71,11 @@ export interface LiveScoreMatch { substitutes?: { time: string; home_scorer: - | { in: string; out: string; in_id: number; out_id: number } - | any[]; + | { in: string; out: string; in_id: number; out_id: number } + | any[]; away_scorer: - | { in: string; out: string; in_id: number; out_id: number } - | any[]; + | { in: string; out: string; in_id: number; out_id: number } + | any[]; info: string; info_time: string; score: string; @@ -287,3 +287,117 @@ export interface OddsData { 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[]; +}