235 lines
4.6 KiB
JavaScript
235 lines
4.6 KiB
JavaScript
// 通用API接口
|
|
|
|
/**
|
|
* 上传图片
|
|
* @param {Object} imageData 图片数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
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
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 上传多张图片
|
|
* @param {Array} imageList 图片列表
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const uploadImages = (imageList, config = {}) => {
|
|
const uploadPromises = imageList.map(imageData => {
|
|
return uploadImage(imageData, {
|
|
...config,
|
|
custom: {
|
|
loading: false, // 批量上传时不显示单个loading
|
|
...config.custom
|
|
}
|
|
})
|
|
})
|
|
|
|
return Promise.all(uploadPromises)
|
|
}
|
|
|
|
/**
|
|
* 上传文件
|
|
* @param {Object} fileData 文件数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
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
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 下载文件
|
|
* @param {String} url 文件URL
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const downloadFile = (url, config = {}) => {
|
|
return uni.$u.http.download(url, {
|
|
custom: {
|
|
auth: false,
|
|
loading: true,
|
|
loadingText: '正在下载文件...',
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取七牛云上传token
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getQiniuToken = (config = {}) => {
|
|
return uni.$u.http.get('/upload/qiniu-token', {
|
|
custom: {
|
|
auth: true,
|
|
loading: false,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取阿里云OSS上传签名
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getOSSSignature = (config = {}) => {
|
|
return uni.$u.http.get('/upload/oss-signature', {
|
|
custom: {
|
|
auth: true,
|
|
loading: false,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取系统配置
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getSystemConfig = (config = {}) => {
|
|
return uni.$u.http.get('/system/config', {
|
|
custom: {
|
|
auth: false,
|
|
loading: false,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取版本信息
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getVersionInfo = (config = {}) => {
|
|
return uni.$u.http.get('/system/version', {
|
|
custom: {
|
|
auth: false,
|
|
loading: false,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 检查更新
|
|
* @param {Object} versionData 版本数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const checkUpdate = (versionData, config = {}) => {
|
|
return uni.$u.http.post('/system/check-update', versionData, {
|
|
custom: {
|
|
auth: false,
|
|
loading: true,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 发送短信验证码
|
|
* @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
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 验证短信验证码
|
|
* @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
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 获取地区数据
|
|
* @param {Object} params 查询参数
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const getRegionData = (params = {}, config = {}) => {
|
|
return uni.$u.http.get('/common/regions', {
|
|
params,
|
|
custom: {
|
|
auth: false,
|
|
loading: false,
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|
|
|
|
/**
|
|
* 意见反馈
|
|
* @param {Object} feedbackData 反馈数据
|
|
* @param {Object} config 自定义配置
|
|
* @returns {Promise}
|
|
*/
|
|
export const submitFeedback = (feedbackData, config = {}) => {
|
|
return uni.$u.http.post('/feedback', feedbackData, {
|
|
custom: {
|
|
auth: true,
|
|
loading: true,
|
|
loadingText: '正在提交反馈...',
|
|
...config.custom
|
|
},
|
|
...config
|
|
})
|
|
}
|