This commit is contained in:
juguohong
2025-08-31 20:24:42 +08:00
parent d92419f3c5
commit 4e68db2476
28 changed files with 921 additions and 206 deletions

View File

@@ -1,4 +1,3 @@
import { TennisMatch } from "../store/listStore";
import httpService from "./httpService";
// 模拟网络延迟
@@ -12,57 +11,6 @@ interface ApiResponse<T> {
timestamp: number;
}
// 模拟网球比赛数据
const mockTennisMatches: TennisMatch[] = [
{
id: "1",
title: "周一晚场浦东新区单打约球",
dateTime: "明天(周五)下午5点 2小时",
location: "仁恒河滨花园网球场",
distance: "3.5km",
shinei: "室内",
registeredCount: 3,
maxCount: 4,
skillLevel: "2.0 至 2.5",
matchType: "双打",
images: [
"https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center",
"https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=200&h=200&fit=crop&crop=center",
"https://images.unsplash.com/photo-1551698618-1dfe5d97d256?w=200&h=200&fit=crop&crop=center",
],
},
{
id: "2",
title: "浦东新区单打约球",
dateTime: "明天(周五)下午5点 2小时",
location: "仁恒河滨花园网球场",
distance: "3.5km",
shinei: "室外",
registeredCount: 2,
maxCount: 4,
skillLevel: "2.0 至 2.5",
matchType: "双打",
images: [
"https://images.unsplash.com/photo-1571019613454-1cb2f99b2d8b?w=200&h=200&fit=crop&crop=center",
"https://images.unsplash.com/photo-1551698618-1dfe5d97d256?w=200&h=200&fit=crop&crop=center",
],
},
{
id: "3",
title: "黄浦区双打约球",
dateTime: "7月20日(周日)下午6点 2小时",
location: "仁恒河滨花园网球场",
distance: "3.5km",
registeredCount: 3,
maxCount: 4,
skillLevel: "2.0 至 2.5",
matchType: "双打",
images: [
"https://images.unsplash.com/photo-1554068865-24cecd4e34b8?w=200&h=200&fit=crop&crop=center",
],
},
];
/**
* 获取网球比赛列表
* @param params 查询参数
@@ -86,10 +34,10 @@ export const getTennisMatches = async (params?: {
* 刷新网球比赛数据
* @returns Promise<TennisMatch[]>
*/
export const refreshTennisMatches = async (): Promise<TennisMatch[]> => {
export const refreshTennisMatches = async (params) => {
try {
// 生成新的动态数据
const matches = generateDynamicData();
const matches = generateDynamicData(params);
return matches;
} catch (error) {
console.error("API刷新失败:", error);
@@ -97,3 +45,52 @@ export const refreshTennisMatches = async (): Promise<TennisMatch[]> => {
}
};
/**
* 获取搜索历史记录的异步函数
* @param {Object} params - 查询参数对象
* @returns {Promise} - 返回一个Promise对象包含获取到的搜索历史数据
*/
export const getSearchHistory = async (params) => {
try {
// 调用HTTP服务获取搜索历史记录
return httpService.get('/games/search_history', params)
} catch (error) {
// 捕获并打印错误信息
console.error("历史记录获取失败:", error);
// 抛出错误以便上层处理
throw error;
}
}
/**
* @description 清除搜索历史
* @returns
*/
export const clearHistory = async () => {
try {
// 调用HTTP服务清除搜索历史记录
return httpService.post('/games/clear_history')
} catch (error) {
// 捕获并打印错误信息
console.error("清除历史记录失败:", error);
// 抛出错误以便上层处理
throw error;
}
}
/**
* @description 获取联想
* @param params 查询参数
* @returns
*/
export const searchSuggestion = async (params) => {
try {
// 调用HTTP服务获取搜索建议
return httpService.get('/games/search_suggestion', params)
} catch (error) {
// 捕获并打印错误信息
console.error("搜索建议获取失败:", error);
// 抛出错误以便上层处理
throw error;
}
}