小程序多图片下载 迭代

picArr=['sdfasfasf.jpg','sdafasfdsaf.jpg']

//下载内容

xiazaiTupian: function (picArr,index) {

let that=this;

index=index||0;

console.log(picArr[index])

wx.downloadFile({

url: picArr[index],

success: function (res) {

var temp = res.tempFilePath

console.log(index)

console.log(temp)

wx.saveImageToPhotosAlbum({

filePath: temp,

success: function () {

index+=1;

if (index < picArr.length){

that.xiazaiTupian(picArr, index);

}else{

wx.showToast({

title: '下载完成',

})

}

},

fail: function () {

index += 1;

if (index < picArr.length) {

that.xiazaiTupian(picArr, index);

} else {

wx.showToast({

title: '下载完成',

})

}

wx.showToast({

title: '第' + (index+1) + '下载失败',

})

}

})

},

fail: function (res) {

wx.showToast({

title: '下载失败',

})

}

})

},