handleUploadFile(){
let that = this;
wx.chooseMessageFile({
count: 4,
success(res){
const tempFiles=res.tempFiles;
var successUp = 0;
var failUp = 0;
var length = tempFiles.length;
var count = 0;
that.uploadOneByOne(tempFiles,successUp,failUp,count,length);
}
})
}
uploadOneByOne(imgPaths,successUp, failUp, count, length){
var that = this;
wx.showLoading({
title: '正在上传第'+count+'个',
})
wx.uploadFile({
url: 'https://example.weixin.qq.com/upload',
filePath: imgPaths[count].path,
name: 'multipartFile',
header:{
'content-type':'multipart/form-data',
},
success:function(reData){
let data = reData.data
let dataJson = JSON.parse(data);
let file = dataJson.body.dataInfo;
console.log(file);
successUp++;
},
fail:function(e){
failUp++;
},
complete:function(e){
count++;
if(count == length){
console.log('上传成功' + successUp + ',' + '失败' + failUp);
wx.showToast({
title: '上传成功' + successUp,
icon: 'success',
duration: 2000
})
}else{
that.uploadOneByOne(imgPaths, successUp, failUp, count, length);
console.log('正在上传第' + count + '张');
}
}
})
}
|