1、按钮
<button bindtap="downloadImages">
2、实现
downloadImages: function() { this.setData({ shareName: null }) //复制文本 let share = this.data.product.goodsDto.share; console.log("share=", share); wx.setClipboardData({ data: share, success: function(res) { wx.showToast({ title: '复制成功', duration: 1000 }) wx.hideToast(); } }) //复制图片 wx.getSetting({ success: (res) => { console.log("scope.writePhotosAlbum的状态", res.authSetting['scope.writePhotosAlbum']); if (res.authSetting['scope.writePhotosAlbum'] == false) { wx.openSetting({ success(settingdata) { console.log("======settingdata=======", settingdata) }, fail(res) { console.log("再次发起授权失败了") } }) } } }) // let image = this.data.product.images3; // let img1 = []; // for (let j = 0; j < image.length; j++) { // img1.push(image[j].uri); // } var img1 = ["https://dss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=3892521478,1695688217&fm=26&gp=0.jpg", "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1694681277,1453280371&fm=26&gp=0.jpg"]; console.log("uri", img1); let count = 0; for (let i = 0; i < img1.length; i++) { wx.downloadFile({ url: img1[i], success: function(res) { console.log("图片保存到本地", res); //图片保存到本地 wx.saveImageToPhotosAlbum({ // filePath: res.tempFilePath, filePath: res.tempFilePath, success: function(data) { count++; wx.showLoading({ title: '保存中...', mask: true, }); console.log("count", count); console.log("img1.length=", img1.length); if (img1.length === count) { if (img1.length === count) { wx.showToast({ title: '保存成功', icon: 'success', duration: 1000 }) } else { wx.showToast({ title: '请重新保存', duration: 1000 }) } } console.log("data:",data); }, fail: function(err) { console.log("err=", err); if (err.errMsg == "saveImageToPhotosAlbum:fail auth deny") { wx.showToast({ title: '请授权下载', duration: 1000, icon:'none' }) console.log("用户一开始拒绝了,再次发起授权") console.log('打开设置窗口') } } }) }, fail: function(err) { wx.showToast({ title: '请重新下载', duration: 1000 }) } }) } },