<view bindtap='save'>保存图片到相册</view>
save () {
let that = this
wx.showToast({
icon: 'loading',
title: '正在保存图片',
duration: 1000
})
wx.getSetting({
success (res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success () {
that.savePhoto();
},
fail () {
wx.openSetting({
success () {
wx.authorize({
scope: 'scope.writePhotosAlbum',
success() {
that.savePhoto();
}
})
}
})
}
})
} else {
that.savePhoto()
}
}
})
},
savePhoto() {
let that = this
wx.downloadFile({
url: that.data.imgUrl,
success: function (res) {
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success(res) {
wx.showToast({
title: '保存成功',
icon: "success",
duration: 1000
})
}
})
}
})
}