/** * 通用API接口模块 * 提供文件上传、系统配置、地区数据等通用功能的API接口 */ import BaseRequest from '../utils/request-helper.js' import { LOADING_TEXTS } from '../config/constants.js' // ==================== API方法 ==================== // ==================== 文件上传相关API ==================== /** * 上传单张图片 * @param {Object} imageData 图片上传数据对象 * @param {Object} config 自定义请求配置 * @returns {Promise} 返回上传结果 */ export const uploadImage = (imageData, config = {}) => { return BaseRequest.upload('/upload/image', imageData, LOADING_TEXTS.UPLOAD_IMAGE, config) } /** * 批量上传多张图片 * @param {Array} imageList 图片列表数组 * @param {Object} config 自定义请求配置 * @returns {Promise} 返回所有图片的上传结果数组 */ 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 }) } 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} 返回上传结果 */ export const uploadFile = (fileData, config = {}) => { return BaseRequest.upload('/upload/file', fileData, LOADING_TEXTS.UPLOAD_FILE, config) } /** * 下载文件到本地 * @param {string} url 文件下载URL * @param {Object} config 自定义请求配置 * @returns {Promise} 返回下载结果 */ export const downloadFile = (url, config = {}) => { return BaseRequest.download(url, config.savePath, LOADING_TEXTS.DOWNLOAD_FILE, config) } // ==================== 云存储相关API ==================== /** * 获取七牛云上传凭证 * @param {Object} params 请求参数 * @param {Object} config 自定义请求配置 * @returns {Promise} 返回七牛云上传配置信息 */ export const getQiniuToken = (params = {}, config = {}) => { return BaseRequest.get('/upload/qiniu-token', params, 'SILENT_REQUEST', config) } /** * 获取阿里云OSS上传签名 * @param {Object} params 请求参数 * @param {Object} config 自定义请求配置 * @returns {Promise} 返回OSS上传配置信息 */ export const getOSSSignature = (params = {}, config = {}) => { return BaseRequest.get('/upload/oss-signature', params, 'SILENT_REQUEST', config) } // ==================== 系统信息相关API ==================== /** * 获取系统配置信息 * @param {Object} params 查询参数 * @param {Object} config 自定义请求配置 * @returns {Promise} 返回系统配置对象 */ export const getSystemConfig = (params = {}, config = {}) => { return BaseRequest.get('/system/config', params, 'SILENT_REQUEST', config) } /** * 获取应用版本信息 * @description 获取当前应用的版本信息和更新历史 * @param {Object} [config={}] 自定义请求配置 * @returns {Promise} 返回版本信息对象 * @example * // 获取版本信息 * const versionInfo = await getVersionInfo() * // 返回格式: * // { * // currentVersion: '1.0.0', * // latestVersion: '1.1.0', * // updateAvailable: true, * // updateLog: ['修复bug', '新增功能'] * // } */ export const getVersionInfo = (config = {}) => { return BaseRequest.get('/system/version', {}, 'SILENT_REQUEST', config) } /** * 检查应用更新 * @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} 返回更新检查结果 * @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 BaseRequest.post('/system/check-update', versionData, 'PUBLIC_REQUEST', LOADING_TEXTS.CHECK_UPDATE, config) } // 短信验证码相关API已移至 http/api/auth.js 文件中 // ==================== 基础数据相关API ==================== /** * 获取地区数据 * @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} 返回地区数据数组 * @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 = {}) => { return BaseRequest.get('/common/regions', params, 'SILENT_REQUEST', config) } /** * 提交用户反馈 * @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} 返回提交结果,包含反馈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 BaseRequest.post('/feedback', feedbackData, 'AUTHENTICATED_UPDATE', LOADING_TEXTS.SUBMIT_FEEDBACK, config) }