This commit is contained in:
2025-09-05 17:35:26 +08:00
parent 23123f3f9a
commit 3cbbd87a77
14 changed files with 1594 additions and 1745 deletions
+3 -3
View File
@@ -12,7 +12,7 @@ export const getAdoptionPets = (params = {}, config = {}) => {
params,
custom: {
auth: false,
loading: true,
loading: false,
...config.custom
},
...config
@@ -30,7 +30,7 @@ export const searchPets = (searchParams, config = {}) => {
params: searchParams,
custom: {
auth: false,
loading: true,
loading: false,
...config.custom
},
...config
@@ -47,7 +47,7 @@ export const filterPets = (filterParams, config = {}) => {
return uni.$u.http.post('/adoption/pets/filter', filterParams, {
custom: {
auth: false,
loading: true,
loading: false,
...config.custom
},
...config
+2 -2
View File
@@ -30,7 +30,7 @@ export const getKnowledgeBase = (params = {}, config = {}) => {
params,
custom: {
auth: false,
loading: true,
loading: false,
...config.custom
},
...config
@@ -48,7 +48,7 @@ export const getChatHistory = (params = {}, config = {}) => {
params,
custom: {
auth: true,
loading: true,
loading: false,
...config.custom
},
...config
+445 -167
View File
@@ -1,234 +1,512 @@
// 通用API接口
/**
* 通用API接口模块
*
* @fileoverview 提供文件上传、系统配置、地区数据等通用功能的API接口
* @author 系统开发团队
* @version 2.0.0
* @since 1.0.0
*
* @description
* 本模块包含以下功能分组:
* - 文件上传相关API:图片上传、文件上传、批量上传
* - 云存储相关API:七牛云、阿里云OSS配置获取
* - 系统信息相关API:系统配置、版本信息、更新检查
* - 基础数据相关API:地区数据、反馈提交
*
* @example
* // 基本用法示例
* import { uploadImage, getSystemConfig } from '@/http/api/common.js'
*
* // 上传图片
* const result = await uploadImage({ filePath: 'path/to/image.jpg' })
*
* // 获取系统配置
* const config = await getSystemConfig()
*/
// ==================== 类型定义 ====================
/**
* 上传图片
* @param {Object} imageData 图片数据
* @typedef {Object} UploadData 上传数据对象
* @property {string} filePath 文件路径
* @property {string} [name] 文件字段名,默认'file'
* @property {Object} [formData] 额外的表单数据
*/
/**
* @typedef {Object} UploadResult 上传结果对象
* @property {string} url 文件访问URL
* @property {string} key 文件存储键名
* @property {number} size 文件大小
* @property {string} type 文件类型
*/
/**
* @typedef {Object} SystemConfig 系统配置对象
* @property {Object} upload 上传配置
* @property {Object} app 应用配置
* @property {Object} features 功能开关配置
*/
// ==================== 配置常量 ====================
/**
* 通用API的默认配置模板
*/
const COMMON_CONFIG_TEMPLATES = {
// 需要认证的上传请求
AUTHENTICATED_UPLOAD: {
auth: true,
loading: true,
toast: true
},
// 公开的下载请求
PUBLIC_DOWNLOAD: {
auth: false,
loading: true,
toast: true
},
// 静默的配置获取请求
SILENT_CONFIG: {
auth: false,
loading: false,
toast: false
},
// 需要认证的提交请求
AUTHENTICATED_SUBMIT: {
auth: true,
loading: true,
toast: true
}
}
/**
* 通用操作的loading文本配置
*/
const COMMON_LOADING_TEXTS = {
UPLOAD_IMAGE: '正在上传图片...',
UPLOAD_FILE: '正在上传文件...',
UPLOAD_IMAGES: '正在批量上传...',
DOWNLOAD_FILE: '正在下载文件...',
CHECK_UPDATE: '正在检查更新...',
SUBMIT_FEEDBACK: '正在提交反馈...'
}
// ==================== 工具函数 ====================
/**
* 创建通用请求的标准化配置
* @param {string} template 配置模板名称
* @param {Object} customConfig 自定义配置
* @param {string} loadingText 自定义loading文本
* @returns {Object} 标准化的请求配置
*/
const createCommonConfig = (template, customConfig = {}, loadingText = null) => {
const baseConfig = COMMON_CONFIG_TEMPLATES[template] || {}
const config = {
custom: {
...baseConfig,
...(loadingText && { loadingText }),
...customConfig.custom
},
...customConfig
}
// 移除custom属性中的undefined值
Object.keys(config.custom).forEach(key => {
if (config.custom[key] === undefined) {
delete config.custom[key]
}
})
return config
}
/**
* 执行上传请求的通用方法
* @param {string} url 上传URL
* @param {Object} uploadData 上传数据
* @param {string} loadingText loading文本
* @param {Object} config 自定义配置
* @returns {Promise}
* @returns {Promise} 请求Promise
*/
const executeUploadRequest = (url, uploadData, loadingText, config = {}) => {
const requestConfig = createCommonConfig('AUTHENTICATED_UPLOAD', config, loadingText)
return uni.$u.http.upload(url, {
filePath: uploadData.filePath,
name: uploadData.name || 'file',
formData: uploadData.formData || {},
...requestConfig
})
}
// ==================== API方法 ====================
// ==================== 文件上传相关API ====================
/**
* 上传单张图片
* @description 上传图片文件到服务器,支持多种图片格式
* @param {UploadData} imageData 图片上传数据对象
* @param {string} imageData.filePath 图片文件路径
* @param {string} [imageData.name='file'] 上传字段名
* @param {Object} [imageData.formData={}] 额外的表单数据
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<UploadResult>} 返回上传结果,包含图片URL等信息
* @example
* // 基本图片上传
* const result = await uploadImage({
* filePath: 'path/to/image.jpg'
* })
*
* // 带额外数据的图片上传
* const result = await uploadImage({
* filePath: 'path/to/image.jpg',
* name: 'avatar',
* formData: { category: 'profile' }
* })
*/
export const uploadImage = (imageData, config = {}) => {
return uni.$u.http.upload('/upload/image', {
filePath: imageData.filePath,
name: imageData.name || 'file',
formData: imageData.formData || {},
custom: {
auth: true,
loading: true,
loadingText: '正在上传图片...',
...config.custom
},
...config
})
return executeUploadRequest('/upload/image', imageData, COMMON_LOADING_TEXTS.UPLOAD_IMAGE, config)
}
/**
* 上传多张图片
* @param {Array} imageList 图片列表
* @param {Object} config 自定义配置
* @returns {Promise}
* 批量上传多张图片
* @description 同时上传多张图片,支持并发上传提升效率
* @param {UploadData[]} imageList 图片列表数组
* @param {Object} [config={}] 自定义请求配置
* @param {boolean} [config.showProgress=true] 是否显示整体进度
* @param {number} [config.maxConcurrent=3] 最大并发上传数量
* @returns {Promise<UploadResult[]>} 返回所有图片的上传结果数组
* @example
* // 批量上传图片
* const results = await uploadImages([
* { filePath: 'path/to/image1.jpg' },
* { filePath: 'path/to/image2.jpg' },
* { filePath: 'path/to/image3.jpg' }
* ])
*
* // 自定义并发数量
* const results = await uploadImages(imageList, {
* maxConcurrent: 5,
* custom: { loadingText: '正在批量上传图片...' }
* })
*/
export const uploadImages = (imageList, config = {}) => {
const uploadPromises = imageList.map(imageData => {
return uploadImage(imageData, {
...config,
custom: {
loading: false, // 批量上传时不显示单个loading
...config.custom
}
export const uploadImages = async (imageList, config = {}) => {
const { maxConcurrent = 3, showProgress = true } = config
// 显示整体进度loading
if (showProgress) {
uni.showLoading({
title: config.custom?.loadingText || COMMON_LOADING_TEXTS.UPLOAD_IMAGES
})
})
return Promise.all(uploadPromises)
}
try {
// 分批并发上传
const results = []
for (let i = 0; i < imageList.length; i += maxConcurrent) {
const batch = imageList.slice(i, i + maxConcurrent)
const batchPromises = batch.map(imageData => {
return uploadImage(imageData, {
...config,
custom: {
loading: false, // 批量上传时不显示单个loading
...config.custom
}
})
})
const batchResults = await Promise.all(batchPromises)
results.push(...batchResults)
}
return results
} finally {
if (showProgress) {
uni.hideLoading()
}
}
}
/**
* 上传文件
* @param {Object} fileData 文件数据
* @param {Object} config 自定义配置
* @returns {Promise}
* 上传通用文件
* @description 上传各种类型的文件到服务器
* @param {UploadData} fileData 文件上传数据对象
* @param {string} fileData.filePath 文件路径
* @param {string} [fileData.name='file'] 上传字段名
* @param {Object} [fileData.formData={}] 额外的表单数据
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<UploadResult>} 返回上传结果,包含文件URL等信息
* @example
* // 上传文档文件
* const result = await uploadFile({
* filePath: 'path/to/document.pdf',
* formData: { type: 'document' }
* })
*/
export const uploadFile = (fileData, config = {}) => {
return uni.$u.http.upload('/upload/file', {
filePath: fileData.filePath,
name: fileData.name || 'file',
formData: fileData.formData || {},
custom: {
auth: true,
loading: true,
loadingText: '正在上传文件...',
...config.custom
},
...config
})
return executeUploadRequest('/upload/file', fileData, COMMON_LOADING_TEXTS.UPLOAD_FILE, config)
}
/**
* 下载文件
* @param {String} url 文件URL
* @param {Object} config 自定义配置
* @returns {Promise}
* 下载文件到本地
* @description 从服务器下载文件到本地存储
* @param {string} url 文件下载URL
* @param {Object} [config={}] 自定义请求配置
* @param {string} [config.savePath] 保存路径,不指定则使用默认路径
* @returns {Promise<Object>} 返回下载结果,包含本地文件路径
* @example
* // 基本文件下载
* const result = await downloadFile('https://example.com/file.pdf')
*
* // 指定保存路径
* const result = await downloadFile('https://example.com/file.pdf', {
* savePath: 'downloads/myfile.pdf'
* })
*/
export const downloadFile = (url, config = {}) => {
const requestConfig = createCommonConfig('PUBLIC_DOWNLOAD', config, COMMON_LOADING_TEXTS.DOWNLOAD_FILE)
return uni.$u.http.download(url, {
custom: {
auth: false,
loading: true,
loadingText: '正在下载文件...',
...config.custom
},
...config
...(config.savePath && { savePath: config.savePath }),
...requestConfig
})
}
// ==================== 云存储相关API ====================
/**
* 获取七牛云上传token
* @param {Object} config 自定义配置
* @returns {Promise}
* 获取七牛云上传凭证
* @description 获取七牛云直传所需的上传token
* @param {Object} [params={}] 请求参数
* @param {string} [params.bucket] 存储桶名称
* @param {string} [params.prefix] 文件前缀
* @param {number} [params.expires] 过期时间(秒)
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回七牛云上传配置信息
* @example
* // 获取默认配置
* const qiniuConfig = await getQiniuToken()
*
* // 获取指定桶的配置
* const qiniuConfig = await getQiniuToken({
* bucket: 'my-bucket',
* prefix: 'images/',
* expires: 3600
* })
*/
export const getQiniuToken = (config = {}) => {
export const getQiniuToken = (params = {}, config = {}) => {
const requestConfig = createCommonConfig('SILENT_CONFIG', config)
return uni.$u.http.get('/upload/qiniu-token', {
custom: {
auth: true,
loading: false,
...config.custom
},
...config
...(Object.keys(params).length > 0 && { params }),
...requestConfig
})
}
/**
* 获取阿里云OSS上传签名
* @param {Object} config 自定义配置
* @returns {Promise}
* @description 获取阿里云OSS直传所需的签名信息
* @param {Object} [params={}] 请求参数
* @param {string} [params.bucket] 存储桶名称
* @param {string} [params.prefix] 文件前缀
* @param {number} [params.expires] 过期时间(秒)
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回OSS上传配置信息
* @example
* // 获取默认OSS配置
* const ossConfig = await getOSSSignature()
*
* // 获取指定配置
* const ossConfig = await getOSSSignature({
* bucket: 'my-oss-bucket',
* prefix: 'uploads/',
* expires: 1800
* })
*/
export const getOSSSignature = (config = {}) => {
export const getOSSSignature = (params = {}, config = {}) => {
const requestConfig = createCommonConfig('SILENT_CONFIG', config)
return uni.$u.http.get('/upload/oss-signature', {
custom: {
auth: true,
loading: false,
...config.custom
},
...config
...(Object.keys(params).length > 0 && { params }),
...requestConfig
})
}
// ==================== 系统信息相关API ====================
/**
* 获取系统配置
* @param {Object} config 自定义配置
* @returns {Promise}
* 获取系统配置信息
* @description 获取应用的系统配置,包括功能开关、上传配置等
* @param {Object} [params={}] 查询参数
* @param {string[]} [params.keys] 指定获取的配置键名数组
* @param {string} [params.category] 配置分类:'app' | 'upload' | 'features'
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<SystemConfig>} 返回系统配置对象
* @example
* // 获取所有配置
* const systemConfig = await getSystemConfig()
*
* // 获取指定分类的配置
* const uploadConfig = await getSystemConfig({
* category: 'upload'
* })
*
* // 获取指定键的配置
* const specificConfig = await getSystemConfig({
* keys: ['maxFileSize', 'allowedTypes']
* })
*/
export const getSystemConfig = (config = {}) => {
export const getSystemConfig = (params = {}, config = {}) => {
const requestConfig = createCommonConfig('SILENT_CONFIG', config)
return uni.$u.http.get('/system/config', {
custom: {
auth: false,
loading: false,
...config.custom
},
...config
...(Object.keys(params).length > 0 && { params }),
...requestConfig
})
}
/**
* 获取版本信息
* @param {Object} config 自定义配置
* @returns {Promise}
* 获取应用版本信息
* @description 获取当前应用的版本信息和更新历史
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回版本信息对象
* @example
* // 获取版本信息
* const versionInfo = await getVersionInfo()
* // 返回格式:
* // {
* // currentVersion: '1.0.0',
* // latestVersion: '1.1.0',
* // updateAvailable: true,
* // updateLog: ['修复bug', '新增功能']
* // }
*/
export const getVersionInfo = (config = {}) => {
return uni.$u.http.get('/system/version', {
custom: {
auth: false,
loading: false,
...config.custom
},
...config
})
const requestConfig = createCommonConfig('SILENT_CONFIG', config)
return uni.$u.http.get('/system/version', requestConfig)
}
/**
* 检查更新
* @param {Object} versionData 版本数据
* @param {Object} config 自定义配置
* @returns {Promise}
* 检查应用更新
* @description 检查是否有新版本可用,并获取更新信息
* @param {Object} versionData 当前版本数据
* @param {string} versionData.currentVersion 当前版本号
* @param {string} versionData.platform 平台:'android' | 'ios' | 'h5' | 'mp-weixin'
* @param {string} [versionData.channel] 更新渠道
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回更新检查结果
* @example
* // 检查更新
* const updateInfo = await checkUpdate({
* currentVersion: '1.0.0',
* platform: 'android'
* })
*
* // 指定更新渠道
* const updateInfo = await checkUpdate({
* currentVersion: '1.0.0',
* platform: 'android',
* channel: 'beta'
* })
*/
export const checkUpdate = (versionData, config = {}) => {
return uni.$u.http.post('/system/check-update', versionData, {
custom: {
auth: false,
loading: true,
...config.custom
},
...config
})
const requestConfig = createCommonConfig('PUBLIC_DOWNLOAD', config, COMMON_LOADING_TEXTS.CHECK_UPDATE)
return uni.$u.http.post('/system/check-update', versionData, requestConfig)
}
/**
* 发送短信验证码
* @param {Object} smsData 短信数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const sendSmsCode = (smsData, config = {}) => {
return uni.$u.http.post('/sms/send', smsData, {
custom: {
auth: false,
loading: true,
loadingText: '正在发送验证码...',
...config.custom
},
...config
})
}
// 短信验证码相关API已移至 http/api/auth.js 文件中
/**
* 验证短信验证码
* @param {Object} verifyData 验证数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const verifySmsCode = (verifyData, config = {}) => {
return uni.$u.http.post('/sms/verify', verifyData, {
custom: {
auth: false,
loading: true,
loadingText: '正在验证...',
...config.custom
},
...config
})
}
// ==================== 基础数据相关API ====================
/**
* 获取地区数据
* @param {Object} params 查询参数
* @param {Object} config 自定义配置
* @returns {Promise}
* @description 获取省市区三级联动的地区数据
* @param {Object} [params={}] 查询参数
* @param {string} [params.level] 数据层级:'province' | 'city' | 'district' | 'all'
* @param {string} [params.parentCode] 父级地区代码
* @param {boolean} [params.includeCoordinates] 是否包含经纬度信息
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object[]>} 返回地区数据数组
* @example
* // 获取所有省份
* const provinces = await getRegionData({ level: 'province' })
*
* // 获取指定省份下的城市
* const cities = await getRegionData({
* level: 'city',
* parentCode: '110000'
* })
*
* // 获取完整的三级数据
* const allRegions = await getRegionData({ level: 'all' })
*/
export const getRegionData = (params = {}, config = {}) => {
const requestConfig = createCommonConfig('SILENT_CONFIG', config)
return uni.$u.http.get('/common/regions', {
params,
custom: {
auth: false,
loading: false,
...config.custom
},
...config
...(Object.keys(params).length > 0 && { params }),
...requestConfig
})
}
/**
* 意见反馈
* @param {Object} feedbackData 反馈数据
* @param {Object} config 自定义配置
* @returns {Promise}
* 提交用户反馈
* @description 提交用户的意见反馈或问题报告
* @param {Object} feedbackData 反馈数据对象
* @param {string} feedbackData.type 反馈类型:'bug' | 'suggestion' | 'complaint' | 'other'
* @param {string} feedbackData.title 反馈标题
* @param {string} feedbackData.content 反馈内容
* @param {string} [feedbackData.contact] 联系方式
* @param {string[]} [feedbackData.images] 相关图片URL数组
* @param {Object} [feedbackData.deviceInfo] 设备信息
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回提交结果,包含反馈ID
* @example
* // 提交bug反馈
* const result = await submitFeedback({
* type: 'bug',
* title: '登录页面异常',
* content: '点击登录按钮后页面卡死',
* contact: 'user@example.com',
* images: ['https://example.com/screenshot.jpg']
* })
*
* // 提交功能建议
* const result = await submitFeedback({
* type: 'suggestion',
* title: '希望增加夜间模式',
* content: '建议应用支持夜间模式,保护用户视力'
* })
*/
export const submitFeedback = (feedbackData, config = {}) => {
return uni.$u.http.post('/feedback', feedbackData, {
custom: {
auth: true,
loading: true,
loadingText: '正在提交反馈...',
...config.custom
},
...config
})
const requestConfig = createCommonConfig('AUTHENTICATED_SUBMIT', config, COMMON_LOADING_TEXTS.SUBMIT_FEEDBACK)
return uni.$u.http.post('/feedback', feedbackData, requestConfig)
}
// ==================== 导出配置常量(供外部使用) ====================
/**
* 导出通用配置常量,供其他模块使用
*/
export const COMMON_CONFIG = {
COMMON_CONFIG_TEMPLATES,
COMMON_LOADING_TEXTS
}
/**
* 导出通用工具函数,供其他模块使用
*/
export const COMMON_UTILS = {
createCommonConfig,
executeUploadRequest
}
+329 -60
View File
@@ -1,90 +1,359 @@
// 宠物管理相关API接口
// 注意:所有接口的鉴权配置已在 http/config/config.js 中统一管理
/**
* 宠物管理相关API接口模块
*
* @fileoverview 提供宠物信息管理、记录管理、健康档案等相关的API接口
* @author 系统开发团队
* @version 2.0.0
* @since 1.0.0
*
* @description
* 本模块包含以下功能分组:
* - 宠物基础信息管理:增删改查宠物信息
* - 宠物记录管理:日常记录、健康记录、成长记录
* - 宠物健康档案:疫苗记录、体检记录、用药记录
* - 宠物统计分析:成长数据、健康趋势分析
*
* @example
* // 基本用法示例
* import { getPetsList, addPet, getPetRecords } from '@/http/api/pets.js'
*
* // 获取宠物列表
* const pets = await getPetsList()
*
* // 添加新宠物
* await addPet({ name: '小白', breed: '金毛', age: 2 })
*
* // 获取宠物记录
* const records = await getPetRecords(petId)
*/
// ==================== 类型定义 ====================
/**
* 获取宠物列表
* @typedef {Object} PetInfo 宠物信息对象
* @property {string} id 宠物ID
* @property {string} name 宠物名称
* @property {string} breed 品种
* @property {string} type 类型:'dog' | 'cat' | 'bird' | 'rabbit' | 'other'
* @property {string} gender 性别:'male' | 'female'
* @property {number} age 年龄(月)
* @property {number} weight 体重(kg)
* @property {string} avatarUrl 头像URL
* @property {string} description 描述
* @property {string} createTime 创建时间
*/
/**
* @typedef {Object} PetRecord 宠物记录对象
* @property {string} id 记录ID
* @property {string} petId 宠物ID
* @property {string} type 记录类型:'feeding' | 'health' | 'exercise' | 'grooming' | 'other'
* @property {string} title 记录标题
* @property {string} content 记录内容
* @property {string[]} images 相关图片
* @property {string} recordTime 记录时间
*/
// ==================== 配置常量 ====================
/**
* 宠物API的默认配置模板
*/
const PETS_CONFIG_TEMPLATES = {
// 需要认证的查询请求(无loading)
AUTHENTICATED_QUERY: {
auth: true,
loading: false,
toast: true
},
// 需要认证的查询请求(有loading)
AUTHENTICATED_QUERY_WITH_LOADING: {
auth: true,
loading: true,
toast: true
},
// 需要认证的更新请求
AUTHENTICATED_UPDATE: {
auth: true,
loading: true,
toast: true
},
// 需要认证的删除请求
AUTHENTICATED_DELETE: {
auth: true,
loading: true,
toast: true
}
}
/**
* 宠物相关的loading文本配置
*/
const PETS_LOADING_TEXTS = {
ADD_PET: '正在添加宠物...',
UPDATE_PET: '正在更新宠物信息...',
DELETE_PET: '正在删除宠物...',
ADD_RECORD: '正在添加记录...',
UPDATE_RECORD: '正在更新记录...',
DELETE_RECORD: '正在删除记录...',
LOADING_DATA: '正在加载...'
}
// ==================== 工具函数 ====================
/**
* 创建宠物请求的标准化配置
* @param {string} template 配置模板名称
* @param {Object} customConfig 自定义配置
* @param {string} loadingText 自定义loading文本
* @returns {Object} 标准化的请求配置
*/
const createPetsConfig = (template, customConfig = {}, loadingText = null) => {
const baseConfig = PETS_CONFIG_TEMPLATES[template] || {}
const config = {
custom: {
...baseConfig,
...(loadingText && { loadingText }),
...customConfig.custom
},
...customConfig
}
// 移除custom属性中的undefined值
Object.keys(config.custom).forEach(key => {
if (config.custom[key] === undefined) {
delete config.custom[key]
}
})
return config
}
/**
* 执行宠物相关的GET请求
* @param {string} url 请求URL
* @param {Object} params 查询参数
* @param {string} template 配置模板
* @param {Object} config 自定义配置
* @returns {Promise}
* @returns {Promise} 请求Promise
*/
const executePetsGetRequest = (url, params = {}, template = 'AUTHENTICATED_QUERY', config = {}) => {
const requestConfig = createPetsConfig(template, config)
return uni.$u.http.get(url, {
...(Object.keys(params).length > 0 && { params }),
...requestConfig
})
}
/**
* 执行宠物相关的POST请求
* @param {string} url 请求URL
* @param {Object} data 请求数据
* @param {string} template 配置模板
* @param {string} loadingText loading文本
* @param {Object} config 自定义配置
* @returns {Promise} 请求Promise
*/
const executePetsPostRequest = (url, data = {}, template = 'AUTHENTICATED_UPDATE', loadingText = null, config = {}) => {
const requestConfig = createPetsConfig(template, config, loadingText)
return uni.$u.http.post(url, data, requestConfig)
}
/**
* 执行宠物相关的PUT请求
* @param {string} url 请求URL
* @param {Object} data 请求数据
* @param {string} template 配置模板
* @param {string} loadingText loading文本
* @param {Object} config 自定义配置
* @returns {Promise} 请求Promise
*/
const executePetsPutRequest = (url, data = {}, template = 'AUTHENTICATED_UPDATE', loadingText = null, config = {}) => {
const requestConfig = createPetsConfig(template, config, loadingText)
return uni.$u.http.put(url, data, requestConfig)
}
/**
* 执行宠物相关的DELETE请求
* @param {string} url 请求URL
* @param {Object} data 请求数据
* @param {string} template 配置模板
* @param {string} loadingText loading文本
* @param {Object} config 自定义配置
* @returns {Promise} 请求Promise
*/
const executePetsDeleteRequest = (url, data = {}, template = 'AUTHENTICATED_DELETE', loadingText = null, config = {}) => {
const requestConfig = createPetsConfig(template, config, loadingText)
return uni.$u.http.delete(url, data, requestConfig)
}
// ==================== API方法 ====================
// ==================== 宠物基础信息管理API ====================
/**
* 获取用户宠物列表
* @description 获取当前用户的所有宠物信息列表,支持分页和筛选
* @param {Object} [params={}] 查询参数
* @param {number} [params.page=1] 页码
* @param {number} [params.pageSize=20] 每页数量
* @param {string} [params.type] 宠物类型筛选:'dog' | 'cat' | 'bird' | 'rabbit' | 'other'
* @param {string} [params.breed] 品种筛选
* @param {string} [params.keyword] 关键词搜索(名称、品种)
* @param {string} [params.sortBy] 排序字段:'createTime' | 'name' | 'age'
* @param {string} [params.sortOrder] 排序方向:'asc' | 'desc'
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回宠物列表和分页信息
* @example
* // 获取所有宠物
* const pets = await getPetsList()
*
* // 分页获取狗狗列表
* const dogs = await getPetsList({
* type: 'dog',
* page: 1,
* pageSize: 10
* })
*
* // 搜索宠物
* const searchResults = await getPetsList({
* keyword: '小白',
* sortBy: 'createTime',
* sortOrder: 'desc'
* })
*/
export const getPetsList = (params = {}, config = {}) => {
return uni.$u.http.get('/pets', {
params,
custom: {
loading: true,
...config.custom
},
...config
})
return executePetsGetRequest('/pets', params, 'AUTHENTICATED_QUERY', config)
}
/**
* 获取宠物详情
* @param {String|Number} petId 宠物ID
* @param {Object} config 自定义配置
* @returns {Promise}
* 获取宠物详细信息
* @description 根据宠物ID获取详细的宠物信息
* @param {string|number} petId 宠物ID
* @param {Object} [config={}] 自定义请求配置
* @param {boolean} [config.includeRecords=false] 是否包含最近记录
* @param {boolean} [config.includeHealth=false] 是否包含健康档案
* @returns {Promise<PetInfo>} 返回宠物详细信息
* @example
* // 获取基本信息
* const pet = await getPetDetail(123)
*
* // 获取包含记录的详细信息
* const petWithRecords = await getPetDetail(123, {
* includeRecords: true,
* includeHealth: true
* })
*/
export const getPetDetail = (petId, config = {}) => {
return uni.$u.http.get(`/pets/${petId}`, {
custom: {
loading: true,
...config.custom
},
...config
})
const params = {}
if (config.includeRecords) params.includeRecords = true
if (config.includeHealth) params.includeHealth = true
return executePetsGetRequest(`/pets/${petId}`, params, 'AUTHENTICATED_QUERY_WITH_LOADING', config)
}
/**
* 添加宠物
* @param {Object} petData 宠物数据
* @param {Object} config 自定义配置
* @returns {Promise}
* 添加新宠物
* @description 为当前用户添加一只新宠物
* @param {Object} petData 宠物信息数据
* @param {string} petData.name 宠物名称(必填)
* @param {string} petData.breed 品种(必填)
* @param {string} petData.type 类型:'dog' | 'cat' | 'bird' | 'rabbit' | 'other'
* @param {string} petData.gender 性别:'male' | 'female'
* @param {number} [petData.age] 年龄(月)
* @param {number} [petData.weight] 体重(kg)
* @param {string} [petData.avatarUrl] 头像URL
* @param {string} [petData.description] 描述
* @param {string} [petData.birthDate] 出生日期
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<PetInfo>} 返回新添加的宠物信息
* @example
* // 添加基本宠物信息
* const newPet = await addPet({
* name: '小白',
* breed: '金毛',
* type: 'dog',
* gender: 'male',
* age: 24,
* weight: 25.5
* })
*
* // 添加完整宠物信息
* const newPet = await addPet({
* name: '小花',
* breed: '英短',
* type: 'cat',
* gender: 'female',
* age: 12,
* weight: 4.2,
* avatarUrl: 'https://example.com/cat.jpg',
* description: '很可爱的小猫咪',
* birthDate: '2023-01-15'
* })
*/
export const addPet = (petData, config = {}) => {
return uni.$u.http.post('/pets', petData, {
custom: {
loading: true,
loadingText: '正在添加宠物...',
...config.custom
},
...config
})
return executePetsPostRequest('/pets', petData, 'AUTHENTICATED_UPDATE', PETS_LOADING_TEXTS.ADD_PET, config)
}
/**
* 更新宠物信息
* @param {String|Number} petId 宠物ID
* @param {Object} petData 宠物数据
* @param {Object} config 自定义配置
* @returns {Promise}
* @description 更新指定宠物的信息,支持部分字段更新
* @param {string|number} petId 宠物ID
* @param {Object} petData 要更新的宠物数据
* @param {string} [petData.name] 宠物名称
* @param {string} [petData.breed] 品种
* @param {string} [petData.type] 类型
* @param {string} [petData.gender] 性别
* @param {number} [petData.age] 年龄(月)
* @param {number} [petData.weight] 体重(kg)
* @param {string} [petData.avatarUrl] 头像URL
* @param {string} [petData.description] 描述
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<PetInfo>} 返回更新后的宠物信息
* @example
* // 更新宠物体重
* const updatedPet = await updatePet(123, {
* weight: 26.0
* })
*
* // 更新多个字段
* const updatedPet = await updatePet(123, {
* name: '小白白',
* age: 25,
* description: '更新后的描述'
* })
*/
export const updatePet = (petId, petData, config = {}) => {
return uni.$u.http.put(`/pets/${petId}`, petData, {
custom: {
loading: true,
loadingText: '正在更新宠物信息...',
...config.custom
},
...config
})
return executePetsPutRequest(`/pets/${petId}`, petData, 'AUTHENTICATED_UPDATE', PETS_LOADING_TEXTS.UPDATE_PET, config)
}
/**
* 删除宠物
* @param {String|Number} petId 宠物ID
* @param {Object} config 自定义配置
* @returns {Promise}
* @description 永久删除指定的宠物及其所有相关记录,此操作不可逆
* @param {string|number} petId 宠物ID
* @param {Object} [config={}] 自定义请求配置
* @param {boolean} [config.force=false] 是否强制删除(忽略关联数据检查)
* @returns {Promise<Object>} 返回删除结果
* @example
* // 普通删除
* await deletePet(123)
*
* // 强制删除(忽略关联数据)
* await deletePet(123, { force: true })
*
* @warning 此操作将永久删除宠物及其所有记录,请谨慎使用
*/
export const deletePet = (petId, config = {}) => {
return uni.$u.http.delete(`/pets/${petId}`, {}, {
custom: {
auth: true,
loading: true,
loadingText: '正在删除宠物...',
...config.custom
},
...config
})
const data = config.force ? { force: true } : {}
return executePetsDeleteRequest(`/pets/${petId}`, data, 'AUTHENTICATED_DELETE', PETS_LOADING_TEXTS.DELETE_PET, config)
}
/**
@@ -99,7 +368,7 @@ export const getPetRecords = (petId, params = {}, config = {}) => {
params,
custom: {
auth: true,
loading: true,
loading: false,
...config.custom
},
...config
+416 -224
View File
@@ -1,256 +1,448 @@
// 个人中心相关API接口
/**
* 个人中心相关API接口模块
*
* @fileoverview 提供用户信息管理、资料完善、偏好设置等相关的API接口
* @author 系统开发团队
* @version 2.0.0
* @since 1.0.0
*
* @description
* 本模块包含以下功能分组:
* - 用户信息相关API:获取、更新用户基本信息
* - 用户统计相关API:获取各项统计数据
* - 账户管理相关API:账户注销等敏感操作
* - 用户资料完善相关API:新用户资料完善
* - 头像上传相关API:头像图片上传和更新
* - 用户偏好设置相关API:个性化设置管理
* - 用户活动记录相关API:操作记录查询
*
* @example
* // 基本用法示例
* import { getUserInfo, updateUserInfo } from '@/http/api/profile.js'
*
* // 获取用户信息
* const userInfo = await getUserInfo()
*
* // 更新用户信息
* await updateUserInfo({ nickName: '新昵称' })
*
* @example
* // 使用配置常量
* import { PROFILE_CONFIG, PROFILE_UTILS } from '@/http/api/profile.js'
*
* // 使用工具函数创建自定义请求
* const customRequest = PROFILE_UTILS.executeGetRequest('/custom/endpoint')
*/
// ==================== 类型定义 ====================
/**
* 获取用户信息
* @param {Object} config 自定义配置
* @returns {Promise}
* @typedef {Object} UserInfo 用户信息对象
* @property {string} id 用户ID
* @property {string} nickName 用户昵称
* @property {string} avatarUrl 头像URL
* @property {string} gender 性别:'男' | '女' | '保密'
* @property {string} birthday 生日,格式:YYYY-MM-DD
* @property {string} region 所在地区
* @property {string} bio 个人简介
* @property {string} createTime 创建时间
* @property {string} updateTime 更新时间
*/
export const getUserInfo = (config = {}) => {
return uni.$u.http.get('/user/info', {
/**
* @typedef {Object} UserStats 用户统计数据对象
* @property {number} petCount 宠物数量
* @property {number} recordCount 记录数量
* @property {number} reminderCount 提醒数量
* @property {number} familyMemberCount 家庭成员数量
*/
/**
* @typedef {Object} RequestConfig 请求配置对象
* @property {Object} custom 自定义配置
* @property {boolean} custom.auth 是否需要认证
* @property {boolean} custom.loading 是否显示loading
* @property {string} custom.loadingText loading文本
* @property {boolean} custom.toast 是否显示错误提示
*/
// ==================== 配置常量 ====================
/**
* API请求的默认配置模板
*/
const DEFAULT_CONFIG_TEMPLATES = {
// 需要认证的查询请求(无loading)
AUTHENTICATED_QUERY: {
auth: true,
loading: false,
toast: true
},
// 需要认证的查询请求(有loading)
AUTHENTICATED_QUERY_WITH_LOADING: {
auth: true,
loading: true,
toast: true
},
// 需要认证的更新请求
AUTHENTICATED_UPDATE: {
auth: true,
loading: true,
toast: true
},
// 需要认证的删除请求
AUTHENTICATED_DELETE: {
auth: true,
loading: true,
toast: true
}
}
/**
* 常用的loading文本配置
*/
const LOADING_TEXTS = {
UPDATING_USER_INFO: '正在更新用户信息...',
SAVING_PROFILE: '正在保存...',
DELETING_ACCOUNT: '正在注销账户...',
UPLOADING_AVATAR: '正在上传头像...',
LOADING_DATA: '正在加载...'
}
// ==================== 工具函数 ====================
/**
* 创建标准化的API请求配置
* @param {string} template 配置模板名称
* @param {Object} customConfig 自定义配置
* @param {string} loadingText 自定义loading文本
* @returns {Object} 标准化的请求配置
*/
const createRequestConfig = (template, customConfig = {}, loadingText = null) => {
const baseConfig = DEFAULT_CONFIG_TEMPLATES[template] || {}
const config = {
custom: {
auth: true,
loading: true,
...config.custom
...baseConfig,
...(loadingText && { loadingText }),
...customConfig.custom
},
...config
...customConfig
}
// 移除custom属性中的undefined值
Object.keys(config.custom).forEach(key => {
if (config.custom[key] === undefined) {
delete config.custom[key]
}
})
return config
}
/**
* 执行GET请求的通用方法
* @param {string} url 请求URL
* @param {Object} params 查询参数
* @param {string} template 配置模板
* @param {Object} config 自定义配置
* @returns {Promise} 请求Promise
*/
const executeGetRequest = (url, params = {}, template = 'AUTHENTICATED_QUERY', config = {}) => {
const requestConfig = createRequestConfig(template, config)
return uni.$u.http.get(url, {
...(Object.keys(params).length > 0 && { params }),
...requestConfig
})
}
/**
* 更新用户信息
* @param {Object} userInfo 用户信息
* 执行POST请求的通用方法
* @param {string} url 请求URL
* @param {Object} data 请求数据
* @param {string} template 配置模板
* @param {string} loadingText loading文本
* @param {Object} config 自定义配置
* @returns {Promise}
* @returns {Promise} 请求Promise
*/
const executePostRequest = (url, data = {}, template = 'AUTHENTICATED_UPDATE', loadingText = null, config = {}) => {
const requestConfig = createRequestConfig(template, config, loadingText)
return uni.$u.http.post(url, data, requestConfig)
}
/**
* 执行PUT请求的通用方法
* @param {string} url 请求URL
* @param {Object} data 请求数据
* @param {string} template 配置模板
* @param {string} loadingText loading文本
* @param {Object} config 自定义配置
* @returns {Promise} 请求Promise
*/
const executePutRequest = (url, data = {}, template = 'AUTHENTICATED_UPDATE', loadingText = null, config = {}) => {
const requestConfig = createRequestConfig(template, config, loadingText)
return uni.$u.http.put(url, data, requestConfig)
}
/**
* 执行DELETE请求的通用方法
* @param {string} url 请求URL
* @param {Object} data 请求数据
* @param {string} template 配置模板
* @param {string} loadingText loading文本
* @param {Object} config 自定义配置
* @returns {Promise} 请求Promise
*/
const executeDeleteRequest = (url, data = {}, template = 'AUTHENTICATED_DELETE', loadingText = null, config = {}) => {
const requestConfig = createRequestConfig(template, config, loadingText)
return uni.$u.http.delete(url, data, requestConfig)
}
// ==================== API方法 ====================
// ==================== 用户信息相关API ====================
/**
* 获取用户基本信息
* @description 获取当前登录用户的基本信息,包括昵称、头像、个人资料等
* @param {Object} [config={}] 自定义请求配置
* @param {Object} [config.custom] 自定义请求选项
* @param {boolean} [config.custom.loading] 是否显示loading,默认true
* @param {boolean} [config.custom.toast] 是否显示错误提示,默认true
* @returns {Promise<Object>} 返回用户信息对象
* @example
* // 基本用法
* const userInfo = await getUserInfo()
*
* // 自定义配置
* const userInfo = await getUserInfo({
* custom: { loading: false }
* })
*/
export const getUserInfo = (config = {}) => {
return executeGetRequest('/user/info', {}, 'AUTHENTICATED_QUERY_WITH_LOADING', config)
}
/**
* 更新用户基本信息
* @description 更新用户的基本信息,如昵称、头像、个人简介等
* @param {Object} userInfo 用户信息对象
* @param {string} [userInfo.nickName] 用户昵称
* @param {string} [userInfo.avatarUrl] 头像URL
* @param {string} [userInfo.bio] 个人简介
* @param {string} [userInfo.gender] 性别
* @param {string} [userInfo.birthday] 生日
* @param {string} [userInfo.region] 地区
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回更新后的用户信息
* @example
* await updateUserInfo({
* nickName: '新昵称',
* bio: '个人简介'
* })
*/
export const updateUserInfo = (userInfo, config = {}) => {
return uni.$u.http.put('/user/info', userInfo, {
custom: {
auth: true,
loading: true,
loadingText: '正在更新用户信息...',
...config.custom
},
...config
})
return executePutRequest('/user/info', userInfo, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.UPDATING_USER_INFO, config)
}
/**
* 获取用户宠物列表
* @param {Object} params 查询参数
* @param {Object} config 自定义配置
* @returns {Promise}
* @description 获取当前用户的所有宠物信息列表
* @param {Object} [params={}] 查询参数
* @param {number} [params.page] 页码,默认1
* @param {number} [params.pageSize] 每页数量,默认20
* @param {string} [params.type] 宠物类型筛选
* @param {string} [params.status] 状态筛选
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回宠物列表和分页信息
* @example
* // 获取所有宠物
* const pets = await getUserPets()
*
* // 分页查询
* const pets = await getUserPets({ page: 1, pageSize: 10 })
*/
export const getUserPets = (params = {}, config = {}) => {
return uni.$u.http.get('/user/pets', {
params,
custom: {
auth: true,
loading: true,
...config.custom
},
...config
})
return executeGetRequest('/user/pets', params, 'AUTHENTICATED_QUERY', config)
}
/**
* 用户登录
* @param {Object} loginData 登录数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const userLogin = (loginData, config = {}) => {
return uni.$u.http.post('/auth/login', loginData, {
custom: {
auth: false,
loading: true,
loadingText: '正在登录...',
...config.custom
},
...config
})
}
/**
* 微信登录
* @param {Object} wxData 微信登录数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const wxLogin = (wxData, config = {}) => {
return uni.$u.http.post('/auth/wx-login', wxData, {
custom: {
auth: false,
loading: true,
loadingText: '正在登录...',
...config.custom
},
...config
})
}
/**
* 用户注册
* @param {Object} registerData 注册数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const userRegister = (registerData, config = {}) => {
return uni.$u.http.post('/auth/register', registerData, {
custom: {
auth: false,
loading: true,
loadingText: '正在注册...',
...config.custom
},
...config
})
}
/**
* 用户登出
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const userLogout = (config = {}) => {
return uni.$u.http.post('/auth/logout', {}, {
custom: {
auth: true,
loading: true,
...config.custom
},
...config
})
}
/**
* 刷新token
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const refreshToken = (config = {}) => {
const refreshToken = uni.getStorageSync('refreshToken')
return uni.$u.http.post('/auth/refresh', { refreshToken }, {
custom: {
loading: false,
toast: false,
...config.custom
},
...config
})
}
/**
* 修改密码
* @param {Object} passwordData 密码数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const changePassword = (passwordData, config = {}) => {
return uni.$u.http.put('/user/password', passwordData, {
custom: {
auth: true,
loading: true,
loadingText: '正在修改密码...',
...config.custom
},
...config
})
}
// ==================== 用户统计相关API ====================
/**
* 获取用户统计数据
* @param {Object} config 自定义配置
* @returns {Promise}
* @description 获取用户的各项统计数据,如宠物数量、记录数量、提醒数量等
* @param {Object} [config={}] 自定义请求配置
* @param {Object} [config.custom] 自定义请求选项
* @param {boolean} [config.custom.loading] 是否显示loading,默认false(后台获取)
* @returns {Promise<Object>} 返回统计数据对象
* @example
* const stats = await getUserStats()
* // 返回格式:
* // {
* // petCount: 3,
* // recordCount: 25,
* // reminderCount: 5,
* // familyMemberCount: 2
* // }
*/
export const getUserStats = (config = {}) => {
return uni.$u.http.get('/user/stats', {
custom: {
auth: true,
loading: true,
...config.custom
},
...config
})
return executeGetRequest('/user/stats', {}, 'AUTHENTICATED_QUERY', config)
}
/**
* 获取用户设置
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const getUserSettings = (config = {}) => {
return uni.$u.http.get('/user/settings', {
custom: {
auth: true,
loading: true,
...config.custom
},
...config
})
}
// ==================== 账户管理相关API ====================
/**
* 更新用户设置
* @param {Object} settings 设置数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const updateUserSettings = (settings, config = {}) => {
return uni.$u.http.put('/user/settings', settings, {
custom: {
auth: true,
loading: true,
loadingText: '正在保存设置...',
...config.custom
},
...config
})
}
/**
* 绑定手机号
* @param {Object} phoneData 手机号数据
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const bindPhone = (phoneData, config = {}) => {
return uni.$u.http.post('/user/bind-phone', phoneData, {
custom: {
loading: true,
loadingText: '正在绑定手机号...',
...config.custom
},
...config
})
}
/**
* 获取用户权限
* @param {Object} config 自定义配置
* @returns {Promise}
*/
export const getUserPermissions = (config = {}) => {
return uni.$u.http.get('/user/permissions', {
custom: {
loading: false,
...config.custom
},
...config
})
}
/**
* 注销账户
* @param {Object} config 自定义配置
* @returns {Promise}
* 注销用户账户
* @description 永久删除用户账户及所有相关数据,此操作不可逆
* @param {Object} [config={}] 自定义请求配置
* @param {Object} [config.custom] 自定义请求选项
* @param {boolean} [config.custom.loading] 是否显示loading,默认true
* @param {string} [config.custom.loadingText] 自定义loading文本
* @returns {Promise<Object>} 返回注销结果
* @example
* await deleteAccount()
*
* @warning 此操作将永久删除所有用户数据,请谨慎使用
*/
export const deleteAccount = (config = {}) => {
return uni.$u.http.delete('/user/account', {}, {
custom: {
loading: true,
loadingText: '正在注销账户...',
...config.custom
},
...config
})
return executeDeleteRequest('/user/account', {}, 'AUTHENTICATED_DELETE', LOADING_TEXTS.DELETING_ACCOUNT, config)
}
// ==================== 用户资料完善相关API ====================
/**
* 完善用户资料信息
* @description 用于新用户首次登录后完善个人资料信息,或更新现有资料
* @param {Object} profileData 用户资料数据对象
* @param {string} profileData.nickName 用户昵称(必填)
* @param {string} [profileData.avatarUrl] 头像URL
* @param {string} [profileData.gender] 性别:'男' | '女' | '保密'
* @param {string} [profileData.birthday] 生日,格式:YYYY-MM-DD
* @param {string} [profileData.region] 所在地区
* @param {string} [profileData.bio] 个人简介
* @param {Object} [config={}] 自定义请求配置
* @param {Object} [config.custom] 自定义请求选项
* @param {boolean} [config.custom.loading] 是否显示loading,默认true
* @param {string} [config.custom.loadingText] 自定义loading文本
* @returns {Promise<Object>} 返回完善后的用户信息
* @example
* // 基本用法
* await completeUserProfile({
* nickName: '小明',
* gender: '男',
* birthday: '1990-01-01',
* region: '北京市',
* bio: '热爱宠物的程序员'
* })
*
* // 自定义loading文本
* await completeUserProfile(profileData, {
* custom: { loadingText: '正在创建用户资料...' }
* })
*/
export const completeUserProfile = (profileData, config = {}) => {
return executePostRequest('/user/profile/complete', profileData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.SAVING_PROFILE, config)
}
// ==================== 头像上传相关API ====================
/**
* 上传用户头像
* @description 上传并更新用户头像图片
* @param {Object} avatarData 头像数据对象
* @param {string} avatarData.avatarUrl 头像图片URL或base64数据
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回上传结果和新的头像URL
* @example
* const result = await uploadAvatar({
* avatarUrl: 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...'
* })
*/
export const uploadAvatar = (avatarData, config = {}) => {
return executePostRequest('/user/avatar', avatarData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.UPLOADING_AVATAR, config)
}
// ==================== 用户偏好设置相关API ====================
/**
* 获取用户偏好设置
* @description 获取用户的个性化偏好设置,如通知设置、隐私设置等
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回用户偏好设置对象
* @example
* const preferences = await getUserPreferences()
*/
export const getUserPreferences = (config = {}) => {
return executeGetRequest('/user/preferences', {}, 'AUTHENTICATED_QUERY', config)
}
/**
* 更新用户偏好设置
* @description 更新用户的个性化偏好设置
* @param {Object} preferences 偏好设置对象
* @param {boolean} [preferences.notificationEnabled] 是否启用通知
* @param {boolean} [preferences.privacyMode] 是否启用隐私模式
* @param {string} [preferences.theme] 主题设置:'light' | 'dark' | 'auto'
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回更新后的偏好设置
* @example
* await updateUserPreferences({
* notificationEnabled: true,
* theme: 'dark'
* })
*/
export const updateUserPreferences = (preferences, config = {}) => {
return executePutRequest('/user/preferences', preferences, 'AUTHENTICATED_UPDATE', '正在保存设置...', config)
}
// ==================== 用户活动记录相关API ====================
/**
* 获取用户活动记录
* @description 获取用户的操作活动记录列表
* @param {Object} [params={}] 查询参数
* @param {number} [params.page] 页码,默认1
* @param {number} [params.pageSize] 每页数量,默认20
* @param {string} [params.type] 活动类型筛选
* @param {string} [params.startDate] 开始日期
* @param {string} [params.endDate] 结束日期
* @param {Object} [config={}] 自定义请求配置
* @returns {Promise<Object>} 返回活动记录列表和分页信息
* @example
* const activities = await getUserActivities({
* page: 1,
* pageSize: 10,
* type: 'pet_care'
* })
*/
export const getUserActivities = (params = {}, config = {}) => {
return executeGetRequest('/user/activities', params, 'AUTHENTICATED_QUERY', config)
}
// ==================== 导出配置常量(供外部使用) ====================
/**
* 导出配置常量,供其他模块使用
*/
export const PROFILE_CONFIG = {
DEFAULT_CONFIG_TEMPLATES,
LOADING_TEXTS
}
/**
* 导出工具函数,供其他模块使用
*/
export const PROFILE_UTILS = {
createRequestConfig,
executeGetRequest,
executePostRequest,
executePutRequest,
executeDeleteRequest
}
+2 -2
View File
@@ -11,7 +11,7 @@ export const getReviews = (params = {}, config = {}) => {
params,
custom: {
auth: false,
loading: true,
loading: false,
...config.custom
},
...config
@@ -31,7 +31,7 @@ export const getTargetReviews = (targetType, targetId, params = {}, config = {})
params,
custom: {
auth: false,
loading: true,
loading: false,
...config.custom
},
...config
+11 -3
View File
@@ -60,7 +60,13 @@ export const NO_AUTH_APIS = [
'/auth/login',
'/auth/register',
'/auth/wx-login',
'/auth/wx-phone-login', // 微信手机号登录
'/auth/refresh',
'/auth/reset-password', // 重置密码
// 短信验证相关
'/sms/send', // 发送短信验证码
'/sms/verify', // 验证短信验证码
// 公开浏览的接口
'/ai/knowledge', // AI知识库
@@ -69,12 +75,14 @@ export const NO_AUTH_APIS = [
'/adoption/pets/filter', // 筛选宠物
'/adoption/organizations', // 领养机构列表
'/reviews', // 查看评价
'/reviews/*', // 查看特定对象的评价
// 系统相关
'/system/config', // 系统配置
'/system/version', // 版本信息
'/system/check-update', // 检查更新
'/sms/send', // 发送短信验证码
'/sms/verify', // 验证短信验证码
'/common/regions' // 地区数据
'/common/regions', // 地区数据
'/common/upload-config' // 上传配置
]
/**