fix: update page
This commit is contained in:
@@ -1,32 +1,37 @@
|
||||
<template>
|
||||
<uni-popup ref="popupRef" type="bottom" :safe-area="false">
|
||||
<view class="popup-container">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">登录授权</text>
|
||||
</view>
|
||||
<view>
|
||||
<uni-popup ref="popupRef" type="bottom" :safe-area="false">
|
||||
<view class="popup-container">
|
||||
<view class="popup-header">
|
||||
<text class="popup-title">登录授权</text>
|
||||
</view>
|
||||
|
||||
<view class="avatar-nickname">
|
||||
<button
|
||||
open-type="chooseAvatar"
|
||||
@chooseavatar="onChooseAvatar"
|
||||
class="avatar-selector custom-button"
|
||||
>
|
||||
<image v-if="avatarUrl" :src="avatarUrl" class="avatar-preview" />
|
||||
<text v-else>点击获取头像</text>
|
||||
<view class="avatar-nickname">
|
||||
<button
|
||||
open-type="chooseAvatar"
|
||||
@chooseavatar="onChooseAvatar"
|
||||
class="avatar-selector custom-button"
|
||||
>
|
||||
<image v-if="avatarUrl" :src="avatarUrl" class="avatar-preview" />
|
||||
<text v-else>点击获取头像</text>
|
||||
</button>
|
||||
<input
|
||||
class="nickname-input"
|
||||
type="nickname"
|
||||
v-model="nickname"
|
||||
placeholder="请输入昵称"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<button class="confirm-btn custom-button" @tap="confirmLogin">
|
||||
确认登录
|
||||
</button>
|
||||
<input
|
||||
class="nickname-input"
|
||||
type="nickname"
|
||||
v-model="nickname"
|
||||
placeholder="请输入昵称"
|
||||
/>
|
||||
</view>
|
||||
</uni-popup>
|
||||
|
||||
<button class="confirm-btn custom-button" @tap="confirmLogin">
|
||||
确认登录
|
||||
</button>
|
||||
</view>
|
||||
</uni-popup>
|
||||
<!-- 隐私协议弹窗 -->
|
||||
<PrivacyPopup ref="privacyRef" @agree="onPrivacyAgree" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -36,8 +41,10 @@ import { getPlatformProvider } from "@/utils/system";
|
||||
import { uploadImage } from "@/utils/common";
|
||||
import { apiLogin } from "@/api/auth.js";
|
||||
import { wxLogin } from "@/utils/login.js";
|
||||
import PrivacyPopup from "@/components/PrivacyPopup/PrivacyPopup.vue";
|
||||
|
||||
const popupRef = ref(null);
|
||||
const privacyRef = ref(null);
|
||||
const avatarUrl = ref("");
|
||||
const nickname = ref("");
|
||||
|
||||
@@ -46,19 +53,65 @@ const userStore = useUserStore();
|
||||
const emit = defineEmits(["logind"]);
|
||||
|
||||
const festivalNames = [
|
||||
'春意','福星','小福','新禧','瑞雪','花灯','喜乐','元宝','春芽','年年',
|
||||
'花灯','月圆','灯影','小灯','星灯','彩灯',
|
||||
'清风','微风','小晴','碧波','流泉',
|
||||
'月光','玉轮','桂香','秋叶','星河','小月','露华','秋水',
|
||||
'雪落','冰晶','暖阳','小雪','冬影','雪花','松影'
|
||||
"春意",
|
||||
"福星",
|
||||
"小福",
|
||||
"新禧",
|
||||
"瑞雪",
|
||||
"花灯",
|
||||
"喜乐",
|
||||
"元宝",
|
||||
"春芽",
|
||||
"年年",
|
||||
"花灯",
|
||||
"月圆",
|
||||
"灯影",
|
||||
"小灯",
|
||||
"星灯",
|
||||
"彩灯",
|
||||
"清风",
|
||||
"微风",
|
||||
"小晴",
|
||||
"碧波",
|
||||
"流泉",
|
||||
"月光",
|
||||
"玉轮",
|
||||
"桂香",
|
||||
"秋叶",
|
||||
"星河",
|
||||
"小月",
|
||||
"露华",
|
||||
"秋水",
|
||||
"雪落",
|
||||
"冰晶",
|
||||
"暖阳",
|
||||
"小雪",
|
||||
"冬影",
|
||||
"雪花",
|
||||
"松影",
|
||||
];
|
||||
|
||||
const getFestivalName = () => {
|
||||
const idx = Math.floor(Math.random() * festivalNames.length);
|
||||
return festivalNames[idx];
|
||||
}
|
||||
};
|
||||
|
||||
const open = () => {
|
||||
const open = async () => {
|
||||
console.log(22223333);
|
||||
// #ifdef MP-WEIXIN
|
||||
const isAgreed = await privacyRef.value.check();
|
||||
console.log(1111, isAgreed);
|
||||
if (isAgreed) {
|
||||
popupRef.value.open();
|
||||
}
|
||||
// #endif
|
||||
|
||||
// #ifndef MP-WEIXIN
|
||||
popupRef.value.open();
|
||||
// #endif
|
||||
};
|
||||
|
||||
const onPrivacyAgree = () => {
|
||||
popupRef.value.open();
|
||||
};
|
||||
|
||||
@@ -75,7 +128,9 @@ const confirmLogin = async () => {
|
||||
const platform = getPlatformProvider();
|
||||
if (platform === "mp-weixin") {
|
||||
const code = await wxLogin();
|
||||
const imageUrl = avatarUrl.value ? await uploadImage(avatarUrl.value) : "";
|
||||
const imageUrl = avatarUrl.value
|
||||
? await uploadImage(avatarUrl.value)
|
||||
: "";
|
||||
|
||||
const loginRes = await apiLogin({
|
||||
code,
|
||||
|
||||
@@ -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