添加卡牌设置功能,更新状态管理和界面显示逻辑

This commit is contained in:
yuchenglong
2026-01-20 10:12:12 +08:00
parent 97f61e68bd
commit 08d05df8be
7 changed files with 242 additions and 38 deletions

View File

@@ -41,12 +41,12 @@ apiClient.interceptors.request.use(async (config) => {
});
const refreshTokenApi = async (
request: RefreshTokenRequest
request: RefreshTokenRequest,
): Promise<RefreshTokenResponse> => {
try {
const response = await apiClient.post<ApiResponse<RefreshTokenResponse>>(
API_ENDPOINTS.REFRESH_TOKEN,
request
request,
);
if (response.data.code === 0) {
@@ -81,13 +81,13 @@ apiClient.interceptors.response.use(
}
}
return Promise.reject(error);
}
},
);
export const fetchSports = async (): Promise<Sport[]> => {
try {
const response = await apiClient.get<ApiResponse<ApiListResponse<Sport>>>(
API_ENDPOINTS.SPORTS
API_ENDPOINTS.SPORTS,
);
if (response.data.code === 0) {
return response.data.data.list;
@@ -103,7 +103,7 @@ export const fetchSports = async (): Promise<Sport[]> => {
export const fetchCountries = async (): Promise<Country[]> => {
try {
const response = await apiClient.get<ApiResponse<ApiListResponse<Country>>>(
API_ENDPOINTS.COUNTRIES
API_ENDPOINTS.COUNTRIES,
);
if (response.data.code === 0) {
return response.data.data.list;
@@ -127,7 +127,7 @@ export const fetchLeagues = async (params: {
try {
const response = await apiClient.get<ApiResponse<ApiListResponse<League>>>(
API_ENDPOINTS.LEAGUES,
{ params }
{ params },
);
if (response.data.code === 0) {
return response.data.data;
@@ -179,7 +179,7 @@ export const fetchTodayMatches = async (options: {
const response = await apiClient.get<ApiResponse<ApiListResponse<Match>>>(
API_ENDPOINTS.MATCHES_TODAY,
{ params }
{ params },
);
if (response.data.code === 0) {
return response.data.data;
@@ -192,11 +192,11 @@ export const fetchTodayMatches = async (options: {
};
export const fetchMatchDetail = async (
id: string
id: string,
): Promise<MatchDetailData> => {
try {
const response = await apiClient.get<ApiResponse<MatchDetailData>>(
API_ENDPOINTS.MATCH_DETAIL(id)
API_ENDPOINTS.MATCH_DETAIL(id),
);
if (response.data.code === 0) {
return response.data.data;
@@ -211,7 +211,7 @@ export const fetchMatchDetail = async (
export const fetchLiveScore = async (
sportId: number,
leagueId?: number,
timezone?: string
timezone?: string,
): Promise<LiveScoreMatch[]> => {
// console.log("Fetching live scores with params:", {
// sportId,
@@ -220,9 +220,9 @@ export const fetchLiveScore = async (
// });
try {
const params: { sport_id: number; league_id?: number; timezone?: string } =
{
sport_id: sportId,
};
{
sport_id: sportId,
};
if (leagueId) {
params.league_id = leagueId;
@@ -234,10 +234,11 @@ export const fetchLiveScore = async (
const response = await apiClient.get<ApiResponse<LiveScoreMatch[]>>(
API_ENDPOINTS.LIVESCORE,
{ params }
{ params },
);
if (response.data.code === 0) {
// console.log("Live score data:", JSON.stringify(response.data.data));
return response.data.data;
}
@@ -251,7 +252,7 @@ export const fetchLiveScore = async (
export const fetchUpcomingMatches = async (
sportId: number,
leagueKey: string,
limit: number = 50
limit: number = 50,
): Promise<UpcomingMatch[]> => {
try {
const response = await apiClient.get<
@@ -278,7 +279,7 @@ export const fetchUpcomingMatches = async (
// 获取实时赔率(足球/网球使用 LiveOdds篮球/板球使用 Odds
export const fetchOdds = async (
sportId: number,
matchId: number
matchId: number,
): Promise<OddsData> => {
try {
const response = await apiClient.get<ApiResponse<OddsData>>(
@@ -288,7 +289,7 @@ export const fetchOdds = async (
sport_id: sportId,
match_id: matchId,
},
}
},
);
if (response.data.code === 0) {
@@ -305,7 +306,7 @@ export const fetchOdds = async (
// 搜索联赛、球队或球员
export const fetchSearch = async (
query: string,
sportId?: number
sportId?: number,
): Promise<SearchResult> => {
try {
const params: { q: string; sportId?: number } = { q: query };
@@ -315,7 +316,7 @@ export const fetchSearch = async (
const response = await apiClient.get<ApiResponse<SearchResult>>(
API_ENDPOINTS.SEARCH,
{ params }
{ params },
);
if (response.data.code === 0) {
@@ -338,7 +339,7 @@ export const fetchH2H = async (
firstPlayerId?: number;
secondPlayerId?: number;
timezone?: string;
}
},
): Promise<H2HData> => {
try {
const params: {
@@ -370,7 +371,7 @@ export const fetchH2H = async (
const response = await apiClient.get<ApiResponse<H2HData>>(
API_ENDPOINTS.H2H,
{ params }
{ params },
);
if (response.data.code === 0) {
@@ -385,12 +386,12 @@ export const fetchH2H = async (
};
export const appleSignIn = async (
request: AppleSignInRequest
request: AppleSignInRequest,
): Promise<AppleSignInResponse> => {
try {
const response = await apiClient.post<ApiResponse<AppleSignInResponse>>(
API_ENDPOINTS.APPLE_SIGNIN,
request
request,
);
if (response.data.code === 0) {
@@ -407,7 +408,7 @@ export const appleSignIn = async (
export const logout = async (): Promise<string> => {
try {
const response = await apiClient.post<ApiResponse<string>>(
API_ENDPOINTS.LOGOUT
API_ENDPOINTS.LOGOUT,
);
if (response.data.code === 0) {
@@ -426,7 +427,7 @@ export const refreshToken = refreshTokenApi;
export const fetchUserProfile = async (): Promise<UserProfile> => {
try {
const response = await apiClient.get<ApiResponse<UserProfile>>(
API_ENDPOINTS.USER_PROFILE
API_ENDPOINTS.USER_PROFILE,
);
if (response.data.code === 0) {
@@ -450,7 +451,7 @@ export const addFavorite = async (request: FavoriteRequest): Promise<any> => {
// console.log("Adding favorite with request:", request);
const response = await apiClient.post<ApiResponse<any>>(
API_ENDPOINTS.FAVORITES,
request
request,
);
if (response.data.code === 0) {
return response.data.data;
@@ -475,7 +476,7 @@ export const removeFavorite = async (request: {
console.log("Removing favorite with request:", request);
const response = await apiClient.delete<ApiResponse<any>>(
API_ENDPOINTS.FAVORITES,
{ data: request }
{ data: request },
);
if (response.data.code === 0) {
return response.data.data;
@@ -489,14 +490,14 @@ export const removeFavorite = async (request: {
export const checkFavorite = async (
type: string,
typeId: string
typeId: string,
): Promise<FavoriteCheckResponse> => {
try {
const response = await apiClient.get<ApiResponse<FavoriteCheckResponse>>(
API_ENDPOINTS.CHECK_FAVORITE,
{
params: { type, typeId },
}
},
);
if (response.data.code === 0) {
return response.data.data;
@@ -511,14 +512,14 @@ export const checkFavorite = async (
export const fetchFavorites = async (
type: string,
page: number = 1,
pageSize: number = 20
pageSize: number = 20,
): Promise<FavoriteListResponse> => {
try {
const response = await apiClient.get<ApiResponse<FavoriteListResponse>>(
API_ENDPOINTS.FAVORITES,
{
params: { type, page, pageSize },
}
},
);
if (response.data.code === 0) {
console.log("Fetched favorites:", JSON.stringify(response.data.data));