//上传图片
const upLoadFileList=(fileList,callBack)=>{
if(fileList.length==0){
typeof callBack == “function” && callBack([])
return;
}
wx.showLoading({
title: ‘上传中’,
});
const upImgList=[];
const length=fileList.length;
const timestamp = Date.parse(new Date());
for (let i = 0; i < length; i++) {
const filePath = fileList[i];
const cloudPath = `upLoadFiles/images/${timestamp+i+filePath.match(/\.[^.]+?$/)[0]}`;
wx.cloud.uploadFile({
cloudPath,
filePath,
success: res => {
upImgList.push(res.fileID);
if(upImgList.length==length){
typeof callBack == “function” && callBack(upImgList)
}
},
fail:res=>{
wx.showToast({
icon: ‘none’,
title: ‘上传失败’,
});
typeof callBack == “function” && callBack([]);
return;
}
})
}
}
module.exports = {
upLoadFileList
}