解决方法:
saveClick(e) {
let img = this.data.qrImgSrc;
if (img) {
let fileName = new Date().valueOf();
let filePath = wx.env.USER_DATA_PATH + '/' + fileName + '.jpg'
wx.downloadFile({
url: img,//此处为接口返回的图片地址
filePath: filePath,
success: function (res) {
// 保存图片到系统相册
wx.saveImageToPhotosAlbum({
filePath: filePath,
success(data) {
},
fail(data){
if(err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
wx.showModal({
title: '提示',
content: '需要您授权保存相册',
showCancel: false,
success: modalSuccess => {
wx.openSetting({
success(settingdata) {
if (settingdata.authSetting['scope.writePhotosAlbum']) {
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
}else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
}
})
}
})
}
}
})
},
fail: function (res) {
}
})
}
},