Files
mini-programs/src/services/listApi.ts
2025-09-06 22:08:34 +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 getGamesList = async (params?: {
page?: number;
pageSize?: number;
location?: string;
skillLevel?: string;
}) => {
try {
return httpService.post('/games/list', params, { showLoading: false })
} catch (error) {
console.error("列表数据获取失败:", error);
throw error;
}
};
export const getGamesIntegrateList = async (params?: {
page?: number;
pageSize?: number;
location?: string;
skillLevel?: string;
}) => {
try {
return httpService.post('/games/integrate_list', params, { showLoading: false })
} catch (error) {
console.error("列表数据获取失败:", 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('/search_history/delete_all')
} catch (error) {
// 捕获并打印错误信息
console.error("清除历史记录失败:", error);
// 抛出错误以便上层处理
throw error;
}
}
/**
* @description 获取联想
* @param params 查询参数
* @returns
*/
export const searchSuggestion = async (params) => {
try {
// 调用HTTP服务获取搜索建议
return httpService.get('/games/search_recommendations', params)
} catch (error) {
// 捕获并打印错误信息
console.error("搜索建议获取失败:", error);
// 抛出错误以便上层处理
throw error;
}
}