function submit(){
var countPromise = [];
var files = [
"http://tmp/wx2020.o6AdxKt6o.0jCN63JzAkZfc367690b907625ee19dde167f9a0c2e5.png",
"http://tmp/wx2020.o6AdxKt6o.hcpVIUyYJ8Hn3e05e34de47d5a979b9fbc111f8e9590.png",
"http://tmp/wx2020.o6AdxKt6o.uX5umpwlnx4N78f7c7bfbaa55a74f3561922d0d0e358.png",
"http://tmp/wx2020.o6AdxKt6o.te0sK16lJEvP526fc649f4de145daa982abfe685f806.png",
"http://tmp/wx2020.o6AdxKt6o.te0sK16lJEvP526fc649f4de145daa982abfe685f805.png",
];
files.forEach((item,index)=>{
var uploadPromise = new Promise((resolve, reject) => {
ajaxData(item, index , function(status){
resolve(status ? true : false)
})
})
countPromise.push(uploadPromise);
Promise.all(countPromise).then(uploadFiles => {
console.log("uploadFiles=>",uploadFiles);
if(uploadFiles.length == countPromise.length ){
var errNum = 0;
uploadFiles.forEach((status) => {
if (!status) {
errNum++
}
})
if(errNum){
console.log("上传失败的图片共有:" + errNum + "张")
}
}
});
})
function ajaxData(item, index , callback){
setTimeout(()=>{
console.log("ajaxData 2 index=>",index);
if(!!callback){
callback(index % 2 == 1)
}
}, 1 * 1000);
}
}
留名后看