小程序保存图片到本地
//保存图片
saveImage(e) {
let that = this;
let url = e.currentTarget.dataset.url;
//用户需要授权
wx.getSetting({
success: (res) => {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: () => {
// 同意授权
that.saveImg1(url);
},
fail: (res) => {
console.log(res);
wx.showToast({
title: '请给小程序授权再保存哦~~',
icon: 'none'
})
}
})
} else {
// 已经授权了
this.saveImg1(url);
}
},
fail: (res) => {
console.log(res);
}
})
},
saveImg1(url) {
console.log(url)
wx.getImageInfo({
src: url,
success: (res) => {
let path = res.path;
wx.saveImageToPhotosAlbum({
filePath: path,
success: (res) => {
console.log(res);
wx.showToast({
title: '保存成功'
})
},
fail: (res) => {
console.log(res);
}
})
},
fail: (res) => {
console.log(res);
}
})
},