fix: update page
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
id="agree-btn"
|
||||
class="btn agree"
|
||||
open-type="agreePrivacyAuthorization"
|
||||
@agreePrivacyAuthorization="handleAgree"
|
||||
@agreeprivacyauthorization="handleAgree"
|
||||
>
|
||||
同意
|
||||
</button>
|
||||
@@ -32,28 +32,41 @@ import { reportPrivacy } from "@/api/auth.js";
|
||||
const show = ref(false);
|
||||
const privacyContractName = ref("《用户隐私保护指引》");
|
||||
|
||||
const emit = defineEmits(["agree"]);
|
||||
let resolveCheck = null;
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
const check = () => {
|
||||
return new Promise((resolve) => {
|
||||
if (uni.getPrivacySetting) {
|
||||
uni.getPrivacySetting({
|
||||
success: (res) => {
|
||||
if (res.needAuthorization) {
|
||||
privacyContractName.value =
|
||||
res.privacyContractName || "《用户隐私保护指引》";
|
||||
show.value = true;
|
||||
resolveCheck = resolve;
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error("getPrivacySetting fail:", err);
|
||||
resolve(true);
|
||||
},
|
||||
});
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
};
|
||||
// #endif
|
||||
|
||||
// Only for WeChat Mini Program
|
||||
// #ifdef MP-WEIXIN
|
||||
onMounted(() => {
|
||||
if (uni.getPrivacySetting) {
|
||||
uni.getPrivacySetting({
|
||||
success: (res) => {
|
||||
console.log("getPrivacySetting", res);
|
||||
if (res.needAuthorization) {
|
||||
privacyContractName.value = res.privacyContractName;
|
||||
show.value = true;
|
||||
} else {
|
||||
// Check local storage just in case
|
||||
const hasAgreed = uni.getStorageSync("hasAgreedPrivacy");
|
||||
if (!hasAgreed) {
|
||||
uni.setStorageSync("hasAgreedPrivacy", true);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: () => {},
|
||||
});
|
||||
}
|
||||
});
|
||||
// onMounted(() => {
|
||||
// check();
|
||||
// });
|
||||
// #endif
|
||||
|
||||
const openPrivacyContract = () => {
|
||||
@@ -65,14 +78,24 @@ const openPrivacyContract = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleAgree = async () => {
|
||||
const handleAgree = async (e) => {
|
||||
if (!show.value) return; // Prevent double execution
|
||||
console.log("handleAgree triggered", e);
|
||||
// 1. Save to local storage
|
||||
uni.setStorageSync("hasAgreedPrivacy", true);
|
||||
|
||||
// 2. Hide popup
|
||||
show.value = false;
|
||||
|
||||
// 3. Call server API
|
||||
emit("agree");
|
||||
|
||||
// 3. Resolve the check promise
|
||||
if (resolveCheck) {
|
||||
resolveCheck(true);
|
||||
resolveCheck = null;
|
||||
}
|
||||
|
||||
// 4. Call server API
|
||||
try {
|
||||
await reportPrivacy();
|
||||
} catch (e) {
|
||||
@@ -90,6 +113,10 @@ const handleDisagree = () => {
|
||||
});
|
||||
// #endif
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
check,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user