This commit is contained in:
juguohong
2025-08-30 18:20:50 +08:00
parent 1cb303b86d
commit d92419f3c5
23 changed files with 456 additions and 266 deletions

View File

@@ -63,25 +63,6 @@ const mockTennisMatches: TennisMatch[] = [
},
];
// 模拟数据变化
const generateDynamicData = (): TennisMatch[] => {
Promise.resolve((res) => {
setTimeout(res, 3000);
});
return mockTennisMatches.map((match) => ({
...match,
// 随机更新注册人数
registeredCount: Math.min(
match.maxCount,
Math.max(0, match.registeredCount + Math.floor(Math.random() * 3) - 1)
),
// 随机更新距离
distance: `${(Math.random() * 5 + 1).toFixed(1)}km`,
// 随机更新时间
dateTime: Math.random() > 0.5 ? match.dateTime : "今天下午3点 2小时",
}));
};
/**
* 获取网球比赛列表
* @param params 查询参数
@@ -116,47 +97,3 @@ export const refreshTennisMatches = async (): Promise<TennisMatch[]> => {
}
};
/**
* 获取比赛详情
* @param id 比赛ID
* @returns Promise<TennisMatch | null>
*/
export const getTennisMatchDetail = async (
id: string
): Promise<TennisMatch | null> => {
try {
console.log("API调用: getTennisMatchDetail", id);
// 模拟网络延迟
await delay(600 + Math.random() * 400);
// 模拟网络错误
if (simulateNetworkError()) {
throw new Error("获取详情失败,请稍后重试");
}
const match = mockTennisMatches.find((m) => m.id === id);
if (!match) {
throw new Error("比赛不存在");
}
console.log("API获取详情成功:", match.title);
return match;
} catch (error) {
console.error("API获取详情失败:", error);
throw error;
}
};
/**
* 模拟API统计信息
*/
export const getApiStats = () => {
return {
totalCalls: 0,
successRate: 0.95,
averageResponseTime: 800,
lastCallTime: new Date().toISOString(),
};
};