diff --git a/api/user.js b/api/user.js index 71d8ef8..2ec4d7e 100644 --- a/api/user.js +++ b/api/user.js @@ -13,3 +13,10 @@ export const userSignIn = async () => { method: "POST", }); }; + +export const getUserLuckInfo = async () => { + return request({ + url: "/api/blessing/user/luck-info", + method: "GET", + }); +}; diff --git a/components/LuckyPopup/LuckyPopup.vue b/components/LuckyPopup/LuckyPopup.vue index d5a1cfa..a1d1393 100644 --- a/components/LuckyPopup/LuckyPopup.vue +++ b/components/LuckyPopup/LuckyPopup.vue @@ -150,11 +150,10 @@ const resultData = ref({ const texts = ["好运加载中...", "今日能量汇集中 ✨", "正在计算你的幸运指数..."]; -const open = () => { - isAnimating.value = true; - isFlipping.value = false; - showLight.value = false; - loadingText.value = texts[0]; +const open = (data = null, skipAnimation = false) => { + if (data) { + resultData.value = { ...resultData.value, ...data }; + } const now = new Date(); const y = now.getFullYear(); @@ -165,7 +164,17 @@ const open = () => { popup.value.open(); - startAnimation(); + if (skipAnimation) { + isAnimating.value = false; + isFlipping.value = true; // Ensure flipped state if needed for consistency, though v-else handles view + showLight.value = false; + } else { + isAnimating.value = true; + isFlipping.value = false; + showLight.value = false; + loadingText.value = texts[0]; + startAnimation(); + } }; const close = () => { diff --git a/pages/index/index.vue b/pages/index/index.vue index f0769ac..2d96734 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -257,7 +257,7 @@ import { getRandomRecommendList, getCardSpecialTopic, } from "@/api/system"; -import { getUserSignInfo, userSignIn } from "@/api/user"; +import { getUserSignInfo, userSignIn, getUserLuckInfo } from "@/api/user"; import calendar from "@/utils/lunar"; import LoginPopup from "@/components/LoginPopup/LoginPopup.vue"; @@ -479,10 +479,20 @@ const onOpenLucky = async () => { } if (signInfo.value.isSignedToday) { - luckyPopupRef.value?.open(); + uni.showLoading({ title: "加载中..." }); + try { + const luckRes = await getUserLuckInfo(); + luckyPopupRef.value?.open(luckRes, true); + } catch (e) { + console.error(e); + uni.showToast({ title: "获取好运信息失败", icon: "none" }); + } finally { + uni.hideLoading(); + } return; } + uni.showLoading({ title: "开启好运...", mask: true }); try { const res = await userSignIn(); if (res && res.success) { @@ -493,7 +503,11 @@ const onOpenLucky = async () => { } fetchUserSingInfo(); userStore.fetchUserAssets(); - luckyPopupRef.value?.open(); + + // 获取好运信息 + const luckRes = await getUserLuckInfo(); + luckyPopupRef.value?.open(luckRes, false); + uni.showToast({ title: "获取40积分", icon: "none" }); } else { uni.showToast({ title: "签到失败", icon: "none" });