提现功能需要添加
This commit is contained in:
45
utils/media.js
Normal file
45
utils/media.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 封装 uni.chooseImage,返回 Promise,便于 async/await 使用
|
||||
* @param {Object} options - 透传给 uni.chooseImage 的配置
|
||||
* @returns {Promise<Array<string>>} 返回选中的临时图片路径数组
|
||||
*/
|
||||
export function chooseImage(options = {}) {
|
||||
// 默认配置
|
||||
const defaultOptions = {
|
||||
count: 1,
|
||||
sourceType: ['album', 'camera'],
|
||||
...options
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.chooseImage({
|
||||
...defaultOptions,
|
||||
success(res) {
|
||||
if (res.tempFilePaths && res.tempFilePaths.length > 0) {
|
||||
resolve(res.tempFilePaths)
|
||||
} else {
|
||||
reject(new Error('未选择任何图片'))
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
// 统一错误处理(如权限被拒、用户取消等)
|
||||
let msg = '选择图片失败'
|
||||
if (err.errMsg.includes('cancel')) {
|
||||
msg = '用户取消选择'
|
||||
} else if (
|
||||
err.errMsg.includes('auth deny') ||
|
||||
err.errMsg.includes('permission')
|
||||
) {
|
||||
msg = '请在设置中开启相册或相机权限'
|
||||
}
|
||||
// 可选:自动弹出 toast 提示
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
})
|
||||
reject(new Error(msg))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -132,3 +132,4 @@ export const uploadMultipleFiles = (filePaths, config = {}) => {
|
||||
)
|
||||
return Promise.all(uploadPromises)
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ const hideLoading = () => {
|
||||
* @param {string} type - 'success' | 'error' | 'warning' | 'none'
|
||||
* @param {number} duration - 持续时间(毫秒)
|
||||
*/
|
||||
const showToast = (message, type = 'none', duration = 2000) => {
|
||||
const showToast = (message, type = 'none', duration = 1800) => {
|
||||
let icon = 'none'
|
||||
if (type === 'success') icon = 'success'
|
||||
if (type === 'error') icon = 'error'
|
||||
|
||||
Reference in New Issue
Block a user