49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
Page({
|
|
data: {
|
|
imageUrl: '../../../image/refund.jpg' // 图片路径
|
|
},
|
|
saveImage: function() {
|
|
const self = this;
|
|
wx.getSetting({
|
|
success(res) {
|
|
if (!res.authSetting['scope.writePhotosAlbum']) {
|
|
wx.authorize({
|
|
scope: 'scope.writePhotosAlbum',
|
|
success() {
|
|
self.saveImageToAlbum();
|
|
},
|
|
fail() {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '请授权保存图片到相册',
|
|
showCancel: false
|
|
});
|
|
}
|
|
});
|
|
} else {
|
|
self.saveImageToAlbum();
|
|
}
|
|
}
|
|
});
|
|
},
|
|
saveImageToAlbum: function() {
|
|
wx.saveImageToPhotosAlbum({
|
|
filePath: this.data.imageUrl,
|
|
success(res) {
|
|
wx.showToast({
|
|
title: '保存成功',
|
|
icon: 'success',
|
|
duration: 2000
|
|
});
|
|
},
|
|
fail(err) {
|
|
wx.showToast({
|
|
title: '保存失败',
|
|
icon: 'none',
|
|
duration: 2000
|
|
});
|
|
console.error('保存失败', err);
|
|
}
|
|
});
|
|
}
|
|
}); |