Files
mini-programs/src/services/listApi.ts
juguohong 4e68db2476 列表
2025-08-31 20:24:42 +08:00

97 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import httpService from "./httpService";
// 模拟网络延迟
const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
// 模拟API响应格式
interface ApiResponse<T> {
code: number;
message: string;
data: T;
timestamp: number;
}
/**
* 获取网球比赛列表
* @param params 查询参数
* @returns Promise<TennisMatch[]>
*/
export const getTennisMatches = async (params?: {
page?: number;
pageSize?: number;
location?: string;
skillLevel?: string;
}) => {
try {
return httpService.post('/venues/list', params, { showLoading: false })
} catch (error) {
console.error("列表数据获取失败:", error);
throw error;
}
};
/**
* 刷新网球比赛数据
* @returns Promise<TennisMatch[]>
*/
export const refreshTennisMatches = async (params) => {
try {
// 生成新的动态数据
const matches = generateDynamicData(params);
return matches;
} catch (error) {
console.error("API刷新失败:", error);
throw error;
}
};
/**
* 获取搜索历史记录的异步函数
* @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;
}
}