From 304e6e94fc225a62176e43c7f5c10f58d110ab22 Mon Sep 17 00:00:00 2001 From: yvan <8574526@qq.com> Date: Fri, 5 Sep 2025 18:20:10 +0800 Subject: [PATCH] 1 --- http/api/pets.js | 228 +++++++++++++++++++++++++++++++---------------- 1 file changed, 149 insertions(+), 79 deletions(-) diff --git a/http/api/pets.js b/http/api/pets.js index 1de3bc5..d2a67e6 100644 --- a/http/api/pets.js +++ b/http/api/pets.js @@ -356,117 +356,187 @@ export const deletePet = (petId, config = {}) => { return executePetsDeleteRequest(`/pets/${petId}`, data, 'AUTHENTICATED_DELETE', PETS_LOADING_TEXTS.DELETE_PET, config) } +// ==================== 宠物记录管理API ==================== + /** * 获取宠物记录列表 - * @param {String|Number} petId 宠物ID - * @param {Object} params 查询参数 - * @param {Object} config 自定义配置 - * @returns {Promise} + * @description 获取指定宠物的所有记录,支持分页和筛选 + * @param {string|number} petId 宠物ID + * @param {Object} [params={}] 查询参数 + * @param {number} [params.page=1] 页码 + * @param {number} [params.pageSize=20] 每页数量 + * @param {string} [params.type] 记录类型筛选:'feeding' | 'health' | 'exercise' | 'grooming' | 'other' + * @param {string} [params.startDate] 开始日期 + * @param {string} [params.endDate] 结束日期 + * @param {string} [params.keyword] 关键词搜索 + * @param {string} [params.sortBy] 排序字段:'recordTime' | 'createTime' + * @param {string} [params.sortOrder] 排序方向:'asc' | 'desc' + * @param {Object} [config={}] 自定义请求配置 + * @returns {Promise} 返回记录列表和分页信息 + * @example + * // 获取所有记录 + * const records = await getPetRecords(123) + * + * // 获取指定类型的记录 + * const healthRecords = await getPetRecords(123, { + * type: 'health', + * page: 1, + * pageSize: 10 + * }) + * + * // 按日期范围查询 + * const recentRecords = await getPetRecords(123, { + * startDate: '2024-01-01', + * endDate: '2024-01-31', + * sortBy: 'recordTime', + * sortOrder: 'desc' + * }) */ export const getPetRecords = (petId, params = {}, config = {}) => { - return uni.$u.http.get(`/pets/${petId}/records`, { - params, - custom: { - auth: true, - loading: false, - ...config.custom - }, - ...config - }) + return executePetsGetRequest(`/pets/${petId}/records`, params, 'AUTHENTICATED_QUERY', config) } /** * 添加宠物记录 - * @param {String|Number} petId 宠物ID + * @description 为指定宠物添加一条新记录 + * @param {string|number} petId 宠物ID * @param {Object} recordData 记录数据 - * @param {Object} config 自定义配置 - * @returns {Promise} + * @param {string} recordData.type 记录类型:'feeding' | 'health' | 'exercise' | 'grooming' | 'other' + * @param {string} recordData.title 记录标题 + * @param {string} recordData.content 记录内容 + * @param {string} [recordData.recordTime] 记录时间,不传则使用当前时间 + * @param {string[]} [recordData.images] 相关图片URL数组 + * @param {Object} [recordData.metadata] 额外的元数据(如体重、体温等) + * @param {Object} [config={}] 自定义请求配置 + * @returns {Promise} 返回新添加的记录信息 + * @example + * // 添加喂食记录 + * const feedingRecord = await addPetRecord(123, { + * type: 'feeding', + * title: '晚餐', + * content: '吃了狗粮200g', + * recordTime: '2024-01-15 18:00:00' + * }) + * + * // 添加健康记录 + * const healthRecord = await addPetRecord(123, { + * type: 'health', + * title: '体重测量', + * content: '今日体重测量结果', + * images: ['https://example.com/weight.jpg'], + * metadata: { + * weight: 25.5, + * temperature: 38.5 + * } + * }) */ export const addPetRecord = (petId, recordData, config = {}) => { - return uni.$u.http.post(`/pets/${petId}/records`, recordData, { - custom: { - auth: true, - loading: true, - loadingText: '正在添加记录...', - ...config.custom - }, - ...config - }) + return executePetsPostRequest(`/pets/${petId}/records`, recordData, 'AUTHENTICATED_UPDATE', PETS_LOADING_TEXTS.ADD_RECORD, config) } /** * 更新宠物记录 - * @param {String|Number} petId 宠物ID - * @param {String|Number} recordId 记录ID - * @param {Object} recordData 记录数据 - * @param {Object} config 自定义配置 - * @returns {Promise} + * @description 更新指定的宠物记录信息 + * @param {string|number} petId 宠物ID + * @param {string|number} recordId 记录ID + * @param {Object} recordData 要更新的记录数据 + * @param {string} [recordData.title] 记录标题 + * @param {string} [recordData.content] 记录内容 + * @param {string} [recordData.recordTime] 记录时间 + * @param {string[]} [recordData.images] 相关图片URL数组 + * @param {Object} [recordData.metadata] 额外的元数据 + * @param {Object} [config={}] 自定义请求配置 + * @returns {Promise} 返回更新后的记录信息 + * @example + * // 更新记录内容 + * const updatedRecord = await updatePetRecord(123, 456, { + * content: '更新后的记录内容', + * metadata: { weight: 26.0 } + * }) */ export const updatePetRecord = (petId, recordId, recordData, config = {}) => { - return uni.$u.http.put(`/pets/${petId}/records/${recordId}`, recordData, { - custom: { - auth: true, - loading: true, - loadingText: '正在更新记录...', - ...config.custom - }, - ...config - }) + return executePetsPutRequest(`/pets/${petId}/records/${recordId}`, recordData, 'AUTHENTICATED_UPDATE', PETS_LOADING_TEXTS.UPDATE_RECORD, config) } /** * 删除宠物记录 - * @param {String|Number} petId 宠物ID - * @param {String|Number} recordId 记录ID - * @param {Object} config 自定义配置 - * @returns {Promise} + * @description 删除指定的宠物记录 + * @param {string|number} petId 宠物ID + * @param {string|number} recordId 记录ID + * @param {Object} [config={}] 自定义请求配置 + * @returns {Promise} 返回删除结果 + * @example + * // 删除记录 + * await deletePetRecord(123, 456) */ export const deletePetRecord = (petId, recordId, config = {}) => { - return uni.$u.http.delete(`/pets/${petId}/records/${recordId}`, {}, { - custom: { - auth: true, - loading: true, - loadingText: '正在删除记录...', - ...config.custom - }, - ...config - }) + return executePetsDeleteRequest(`/pets/${petId}/records/${recordId}`, {}, 'AUTHENTICATED_DELETE', PETS_LOADING_TEXTS.DELETE_RECORD, config) } +// ==================== 宠物健康档案API ==================== + /** * 获取宠物健康数据 - * @param {String|Number} petId 宠物ID - * @param {Object} params 查询参数 - * @param {Object} config 自定义配置 - * @returns {Promise} + * @description 获取宠物的健康档案数据,包括疫苗记录、体检记录等 + * @param {string|number} petId 宠物ID + * @param {Object} [params={}] 查询参数 + * @param {string} [params.type] 健康数据类型:'vaccine' | 'checkup' | 'medication' | 'all' + * @param {string} [params.startDate] 开始日期 + * @param {string} [params.endDate] 结束日期 + * @param {Object} [config={}] 自定义请求配置 + * @returns {Promise} 返回健康数据 + * @example + * // 获取所有健康数据 + * const healthData = await getPetHealthData(123) + * + * // 获取疫苗记录 + * const vaccineData = await getPetHealthData(123, { + * type: 'vaccine' + * }) */ export const getPetHealthData = (petId, params = {}, config = {}) => { - return uni.$u.http.get(`/pets/${petId}/health`, { - params, - custom: { - auth: true, - loading: true, - ...config.custom - }, - ...config - }) + return executePetsGetRequest(`/pets/${petId}/health`, params, 'AUTHENTICATED_QUERY_WITH_LOADING', config) } /** - * 获取宠物时间线 - * @param {String|Number} petId 宠物ID - * @param {Object} params 查询参数 - * @param {Object} config 自定义配置 - * @returns {Promise} + * 获取宠物成长时间线 + * @description 获取宠物的成长时间线,包括重要事件和里程碑 + * @param {string|number} petId 宠物ID + * @param {Object} [params={}] 查询参数 + * @param {number} [params.limit] 限制返回数量 + * @param {string} [params.type] 事件类型筛选 + * @param {Object} [config={}] 自定义请求配置 + * @returns {Promise} 返回时间线事件数组 + * @example + * // 获取完整时间线 + * const timeline = await getPetTimeline(123) + * + * // 获取最近10个事件 + * const recentEvents = await getPetTimeline(123, { + * limit: 10 + * }) */ export const getPetTimeline = (petId, params = {}, config = {}) => { - return uni.$u.http.get(`/pets/${petId}/timeline`, { - params, - custom: { - auth: true, - loading: true, - ...config.custom - }, - ...config - }) + return executePetsGetRequest(`/pets/${petId}/timeline`, params, 'AUTHENTICATED_QUERY_WITH_LOADING', config) +} + +// ==================== 导出配置常量(供外部使用) ==================== + +/** + * 导出宠物配置常量,供其他模块使用 + */ +export const PETS_CONFIG = { + PETS_CONFIG_TEMPLATES, + PETS_LOADING_TEXTS +} + +/** + * 导出宠物工具函数,供其他模块使用 + */ +export const PETS_UTILS = { + createPetsConfig, + executePetsGetRequest, + executePetsPostRequest, + executePetsPutRequest, + executePetsDeleteRequest }