import httpService from "./httpService"; // 模拟网络延迟 const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); // 模拟API响应格式 interface ApiResponse { code: number; message: string; data: T; timestamp: number; } /** * 获取列表 * @param params 查询参数 * @returns Promise */ export const getGamesList = async (params?: Record) => { try { /** * 判断请求哪个接口 * 筛选智能排序:/games/integrate_list * 常规搜索:/games/list */ // const isIntegrate = params?.order === '0'; // const fetchApi = isIntegrate ? '/games/integrate_list' : '/games/list' return httpService.post('/games/list', params, { showLoading: false }) } catch (error) { console.error("列表数据获取失败:", error); throw error; } }; /** * 获取列表 * @param params 查询参数 * @returns Promise */ export const getGamesIntegrateList = async (params?: Record) => { try { return httpService.post('/games/integrate_list', params, { showLoading: false }) } catch (error) { console.error("列表数据获取失败:", error); throw error; } }; /** * 获取列表数量 * @param params * @returns */ export const getGamesCount = async (params?: Record) => { try { return httpService.post('/games/count', 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.post('/games/search_history', params, { showLoading: false }) } catch (error) { // 捕获并打印错误信息 console.error("历史记录获取失败:", error); // 抛出错误以便上层处理 throw error; } } /** * @description 清除搜索历史 * @returns */ export const clearHistory = async (params) => { try { // 调用HTTP服务清除搜索历史记录 return httpService.post('/games/search_history/delete_all', params, { showLoading: false }) } catch (error) { // 捕获并打印错误信息 console.error("清除历史记录失败:", error); // 抛出错误以便上层处理 throw error; } } /** * @description 获取联想 * @param params 查询参数 * @returns */ export const searchSuggestion = async (params) => { try { // 调用HTTP服务获取搜索建议 return httpService.post('/games/search_recommendations', params) } catch (error) { // 捕获并打印错误信息 console.error("搜索建议获取失败:", error); // 抛出错误以便上层处理 throw error; } } export const getCities = async () => { try { // 调用HTTP服务获取城市列表 return httpService.post('/cities/tree', {}) } catch (error) { // 捕获并打印错误信息 console.error("城市列表获取失败:", error); // 抛出错误以便上层处理 throw error; } } export const getCityQrCode = async () => { try { // 调用HTTP服务获取城市二维码 return httpService.post('/hot_city_qr/list', {}) } catch (error) { // 捕获并打印错误信息 console.error("城市二维码获取失败:", error); // 抛出错误以便上层处理 throw error; } } // 获取行政区列表 export const getDistricts = async (params: { province: string; city: string }) => { try { // 调用HTTP服务获取行政区列表 return httpService.post('/cities/cities', params) } catch (error) { // 捕获并打印错误信息 console.error("行政区列表获取失败:", error); // 抛出错误以便上层处理 throw error; } }