204 lines
4.3 KiB
JavaScript
204 lines
4.3 KiB
JavaScript
// 宠物管理相关API接口
|
|
// 注意:所有接口的鉴权配置已在 http/config/config.js 中统一管理
|
|
|
|
/**
|
|
* 获取宠物列表
|
|
* @param {Object} params 查询参数
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getPetsList = (params = {}, config = {}) => {
|
|
return uni.$u.http.get('/pets', {
|
|
params,
|
|
custom: {
|
|
loading: true,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取宠物详情
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getPetDetail = (petId, config = {}) => {
|
|
return uni.$u.http.get(`/pets/${petId}`, {
|
|
custom: {
|
|
loading: true,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 添加宠物
|
|
* @param {Object} petData 宠物数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const addPet = (petData, config = {}) => {
|
|
return uni.$u.http.post('/pets', petData, {
|
|
custom: {
|
|
loading: true,
|
|
loadingText: '正在添加宠物...',
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 更新宠物信息
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {Object} petData 宠物数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const updatePet = (petId, petData, config = {}) => {
|
|
return uni.$u.http.put(`/pets/${petId}`, petData, {
|
|
custom: {
|
|
loading: true,
|
|
loadingText: '正在更新宠物信息...',
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 删除宠物
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const deletePet = (petId, config = {}) => {
|
|
return uni.$u.http.delete(`/pets/${petId}`, {}, {
|
|
custom: {
|
|
auth: true,
|
|
loading: true,
|
|
loadingText: '正在删除宠物...',
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取宠物记录列表
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {Object} params 查询参数
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getPetRecords = (petId, params = {}, config = {}) => {
|
|
return uni.$u.http.get(`/pets/${petId}/records`, {
|
|
params,
|
|
custom: {
|
|
auth: true,
|
|
loading: true,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 添加宠物记录
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {Object} recordData 记录数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const addPetRecord = (petId, recordData, config = {}) => {
|
|
return uni.$u.http.post(`/pets/${petId}/records`, recordData, {
|
|
custom: {
|
|
auth: true,
|
|
loading: true,
|
|
loadingText: '正在添加记录...',
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 更新宠物记录
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {String|Number} recordId 记录ID
|
|
* @param {Object} recordData 记录数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
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
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 删除宠物记录
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {String|Number} recordId 记录ID
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const deletePetRecord = (petId, recordId, config = {}) => {
|
|
return uni.$u.http.delete(`/pets/${petId}/records/${recordId}`, {}, {
|
|
custom: {
|
|
auth: true,
|
|
loading: true,
|
|
loadingText: '正在删除记录...',
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取宠物健康数据
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {Object} params 查询参数
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getPetHealthData = (petId, params = {}, config = {}) => {
|
|
return uni.$u.http.get(`/pets/${petId}/health`, {
|
|
params,
|
|
custom: {
|
|
auth: true,
|
|
loading: true,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取宠物时间线
|
|
* @param {String|Number} petId 宠物ID
|
|
* @param {Object} params 查询参数
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getPetTimeline = (petId, params = {}, config = {}) => {
|
|
return uni.$u.http.get(`/pets/${petId}/timeline`, {
|
|
params,
|
|
custom: {
|
|
auth: true,
|
|
loading: true,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|