上代码:(写的好累啊…)
//微信小程序保存到相册
saveEwm(e) {
var that = this
//获取相册授权
uni.getSetting({
success(res) {
if (!res.authSetting['scope.writePhotosAlbum']) {
uni.authorize({
scope: 'scope.writePhotosAlbum',
success() {
//这里是用户同意授权后的回调
that.saveImgToLocal();
},
fail() { //这里是用户拒绝授权后的回调
that.openSettingBtnHidden = false
}
})
} else { //用户已经授权过了
that.saveImgToLocal();
}
}
})
},
saveImgToLocal(e) {
let that = this
uni.showModal({
title: '提示',
content: '确定保存到相册吗',
success: function(res) {
if (res.confirm) {
uni.downloadFile({
url: that.shareImg, //图片地址
success: (res) => {
// console.log(res)
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function() {
uni.showToast({
title: "保存成功",
icon: "none"
});
},
fail: function() {
uni.showToast({
title: "保存失败",
icon: "none"
});
}
});
}
}
})
} else if (res.cancel) {}
}
});
},