const savePosterPath = (url) => {
uni.showLoading({
title: '正在保存图片...'
});
uni.getSetting({
success: (res) => {
if (!res.authSetting["scope.writePhotosAlbum"]) {
uni.authorize({
scope: "scope.writePhotosAlbum",
success: () => {
uni.saveImageToPhotosAlbum({
filePath: url,
success: (res) => {
uni.hideLoading();
return uni.showToast({
title: "保存成功!",
});
},
fail: (res) => {
console.log(res.errMsg);
return uni.showToast({
title: res.errMsg,
});
},
complete: (res) => {uni.hideLoading();},
});
},
fail: () => {
uni.hideLoading();
uni.showModal({
title: "您已拒绝获取相册权限",
content: "是否进入权限管理,调整授权?",
success: (res) => {
if (res.confirm) {
uni.openSetting({
success: (res) => {
console.log(res.authSetting);
},
});
} else if (res.cancel) {
return uni.showToast({
title: "已取消!",
});
}
},
});
},
});
} else {
uni.saveImageToPhotosAlbum({
filePath: url,
success: (res) => {
uni.hideLoading();
return uni.showToast({
title: "保存成功!",
});
},
fail: (res) => {
uni.hideLoading();
console.log(res.errMsg);
return uni.showToast({
title: res.errMsg,
});
},
complete: (res) => {uni.hideLoading();},
});
}
},
fail: (res) => {},
});
};
用到的方法
1. uni.getSetting
uniapp官网链接: https://uniapp.dcloud.io/api/other/setting.html#getsetting
2. uni.authorize
链接:https://uniapp.dcloud.io/api/other/authorize.html#authorize
3. uni.saveImageToPhotosAlbum
链接: https://uniapp.dcloud.io/api/media/image.html#saveimagetophotosalbum
4. uni.openSetting
链接: https://uniapp.dcloud.io/api/other/setting.html#opensetting
|