// 保存图片
SaveCard(e) {
let that = this;
var imgSrc = this.data.imgSrc
console.log(imgSrc);
//获取相册授权
wx.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
console.log('授权成功');
that.img(imgSrc)
}
})
} else {
that.img(imgSrc)
}
}
})
},
img(imgSrc) {
var imgSrc = imgSrc
wx.downloadFile({
url: imgSrc,
success: function (res) {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function (data) {
console.log(data);
wx.showToast({
title: '保存成功',
duration: 2000
})
},
fail: function (err) {
console.log(err);
if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
wx.openSetting({
success(settingdata) {
console.log(settingdata)
if (settingdata.authSetting['scope.writePhotosAlbum']) {
wx.showToast({
title: '图片已保存',
icon: 'none',
duration: 2000
})
console.log('获取权限成功,给出再次点击图片保存到相册的提示。')
} else {
console.log('获取权限失败,给出不给权限就无法正常使用的提示')
}
}
})
}
}
})
}
})
},
小程序保存图片到本地相册
最新推荐文章于 2024-07-17 18:22:26 发布