async function chooseAndUploadImg(imgNum = 1, fileMaxSize = 1024 * 2,
respCallback = function(ret) {
return ret
}) {
return new Promise((resolve, reject) => {
wx.chooseImage({
count: imgNum,
sourceType: ['album'],
success(ret) {
const tempFilePaths = ret.tempFilePaths;
let num = 1;
let urls = [];
tempFilePaths.forEach(async (path, pathIdx) => {
let kb = ret.tempFiles[pathIdx].size / 1000;
let limit = fileMaxSize;
let ext = path.split('.').pop()
if (limit && kb > limit) {
wx.showToast({
icon: 'none',
title: '图片' + num + '超' + limit + 'kb,已忽略!'
});
} else {
wx.showLoading({
mask: true,
title: '正在上传 ' + num + '/' + tempFilePaths.length
});
let {
fileUrl
} = await 你自己的上传方法({
filePath: path
}).catch(errHandle-自定义的err方法)
urls.push(fileUrl)
uni.hideLoading();
if (urls.length === tempFilePaths.length) {
resolve(urls)
}
}
});
},
fail(ret) {
console.log('选择这里失败了')
reject(ret);
}
})
})
}