// 保存二维码
saveImg:function(e){
let src = e.target.dataset.src;
let that = this;
wx.showLoading({
title: '加载中',
})
// 获取相册授权
wx.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
//这里是用户同意授权后的回调
that.saveTeacherToLocal(src);
},
fail() {
//这里是用户拒绝授权后的回调
wx.showModal({
title: '提示信息',
content: '若点击不授权,将无法使用保存图片功能',
cancelText: '不授权',
cancelColor: '#bbb',
confirmText: '授权',
success(modalRes) {
if (modalRes.confirm) {
wx.openSetting({
success(openMsg) {
console.log(openMsg)
},
fail: function (err) {
console.log(err)
}
})
} else if (modalRes.cancel) {
console.log('用户点击取消')
}
}
})
}
})
} else { //用户已经授权过了
that.saveTeacherToLocal(src);
}
wx.hideLoading();
}
})
},
//保存图片到本地
saveTeacherToLocal: function (src) {
wx.downloadFile({
url: src,
success: (res) => {
wx.saveImageToPhotosAlbum({ //保存到本地
filePath: res.tempFilePath,
success(res1) {
wx.showToast({
title: '保存成功',
icon: 'success',
duration: 2000
})
},
fail: function (err) {
console.log(err);
}
})
}
})
}