- 你需要知道当前用户是否授权 你保存相册的权限
2.你直接吧代码copy吧。 写不动了
savePoster(){
let _this= this;
uni.getSetting({
success(res) {
if (res.authSetting['scope.writePhotosAlbum']) {
_this.saveImageToPhotosAlbum(_this.goodUrl);
} else {
uni.authorize({
scope: 'scope.writePhotosAlbum',
success(res) {
if (res.errMsg === 'authorize:ok') {
_this.saveImageToPhotosAlbum(_this.goodUrl);
}
},
fail() {
uni.showToast({
title: "请打开保存相册权限,再点击保存相册分享",
icon: "none",
duration: 3000
});
}
})
}
},
})
},
saveImageToPhotosAlbum(goodUrl) {
uni.downloadFile({
url: goodUrl,
success: (res) => {
if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success() {
uni.showToast({
title: "保存成功",
icon: "none"
});
},
fail() {
uni.showToast({
title: "保存取消",
icon: "none"
});
}
});
}
}
})
}