点击保存图片
saveimg() {
let that = this
wx.showLoading({
title: '正在保存',
mask: true,
})
wx.canvasToTempFilePath({
canvasId: 'canvas-demo',
success: (res) => {
console.log(res);
wx.hideLoading();
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function (res) {
console.log(res);
wx.showToast({
title: '保存成功',
})
that.setData({
modalName: null,
})
},
fail: function (res) {
console.log(res);
if (res.errMsg == 'saveImageToPhotosAlbum:fail auth deny') {
wx.showModal({
title: '请打开相册授权',
success(res) {
if (res.confirm) {
wx.openSetting({
success: function (data) {},
fail: function (data) {
console.log("openSetting fail", data);
}
});
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
}
})
},
fail: function (res) {
console.log(res);
}
});