Add invite code points activity

This commit is contained in:
Tim
2025-08-17 11:37:21 +08:00
parent ce94cd7e73
commit 901b3f344a
3 changed files with 48 additions and 1 deletions

View File

@@ -1,5 +1,11 @@
<template>
<div>
<ActivityPopup
:visible="showInvitePointsPopup"
:icon="invitePointsIcon"
text="邀请码送积分活动火热进行中,快来邀请好友吧!"
@close="closeInvitePointsPopup"
/>
<ActivityPopup
:visible="showMilkTeaPopup"
:icon="milkTeaIcon"
@@ -20,6 +26,8 @@ import { authState } from '~/utils/auth'
const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl
const showInvitePointsPopup = ref(false)
const invitePointsIcon = ref('')
const showMilkTeaPopup = ref(false)
const milkTeaIcon = ref('')
const showNotificationPopup = ref(false)
@@ -27,6 +35,9 @@ const showMedalPopup = ref(false)
const newMedals = ref([])
onMounted(async () => {
await checkInvitePointsActivity()
if (showInvitePointsPopup.value) return
await checkMilkTeaActivity()
if (showMilkTeaPopup.value) return
@@ -59,6 +70,29 @@ const closeMilkTeaPopup = () => {
showMilkTeaPopup.value = false
checkNotificationSetting()
}
const checkInvitePointsActivity = async () => {
if (!process.client) return
if (localStorage.getItem('invitePointsActivityPopupShown')) return
try {
const res = await fetch(`${API_BASE_URL}/api/activities`)
if (res.ok) {
const list = await res.json()
const a = list.find((i) => i.type === 'INVITE_POINTS' && !i.ended)
if (a) {
invitePointsIcon.value = a.icon
showInvitePointsPopup.value = true
}
}
} catch (e) {
// ignore network errors
}
}
const closeInvitePointsPopup = () => {
if (!process.client) return
localStorage.setItem('invitePointsActivityPopupShown', 'true')
showInvitePointsPopup.value = false
checkMilkTeaActivity()
}
const checkNotificationSetting = async () => {
if (!process.client) return
if (!authState.loggedIn) return