if (!authSetting.authSetting["scope.writePhotosAlbum"]) {
console.log("未授权保存到相册,请求授权...");
try {
await Taro.authorize({ scope: "scope.writePhotosAlbum" });
console.log("✅ 授权成功");
} catch (authError) {
console.log("❌ 授权失败,引导用户打开设置页面");
const res = await Taro.showModal({
title: "需要相册权限",
content: "保存图片到相册需要您的授权,是否前往设置页面开启权限?",
confirmText: "去设置",
cancelText: "取消",
});
if (res.confirm) {
await Taro.openSetting();
const newAuthSetting = await Taro.getSetting();
if (!newAuthSetting.authSetting["scope.writePhotosAlbum"]) {
Taro.showToast({
title: "未授权保存到相册",
icon: "none",
duration: 2000,
});
return false;
}
} else {
return false;
}
}
}
