Files
one-pipe-system/src/composables/useCeremony.ts
sexygoat e04a283319
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 4m38s
fix: 新增代理系列授权-建议售价使用套餐
2026-06-12 10:41:37 +08:00

85 lines
2.4 KiB
TypeScript

import { useTimeoutFn, useIntervalFn } from '@vueuse/core'
import { useDateFormat } from '@vueuse/core'
import { useSettingStore } from '@/store/modules/setting'
import { storeToRefs } from 'pinia'
import { computed } from 'vue'
import { mittBus } from '@/utils/sys'
import { festivalConfigList } from '@/config/festival'
// 节日庆祝相关配置
export function useCeremony() {
const settingStore = useSettingStore()
const { holidayFireworksLoaded, isShowFireworks } = storeToRefs(settingStore)
// 烟花间隔引用,用于清理
let fireworksInterval: { pause: () => void } | null = null
// 判断当前日期是否是节日
const currentFestivalData = computed(() => {
const currentDate = useDateFormat(new Date(), 'YYYY-MM-DD').value
return festivalConfigList.find((item) => item.date === currentDate)
})
// 节日庆祝相关配置
const FESTIVAL_CONFIG = {
INITIAL_DELAY: 300, // 初始延迟时间,单位毫秒
FIREWORK_INTERVAL: 1000, // 烟花效果触发间隔,单位毫秒
TEXT_DELAY: 2000, // 文本显示延迟时间,单位毫秒
MAX_TRIGGERS: 6 // 最大触发次数
} as const
// 根据节日列表显示节日祝福
const openFestival = () => {
// 没有节日数据,不显示
if (!currentFestivalData.value) return
// 礼花效果结束,不显示
if (!isShowFireworks.value) return
let triggers = 0
const { start: startFireworks } = useTimeoutFn(() => {
const { pause } = useIntervalFn(() => {
mittBus.emit('triggerFireworks')
triggers++
if (triggers >= FESTIVAL_CONFIG.MAX_TRIGGERS) {
pause()
settingStore.setholidayFireworksLoaded(true)
// 主页显示节日文本
useTimeoutFn(() => {
settingStore.setShowFestivalText(true)
setFestivalDate()
}, FESTIVAL_CONFIG.TEXT_DELAY)
}
}, FESTIVAL_CONFIG.FIREWORK_INTERVAL)
fireworksInterval = { pause }
}, FESTIVAL_CONFIG.INITIAL_DELAY)
startFireworks()
}
// 清理函数
const cleanup = () => {
if (fireworksInterval) {
fireworksInterval.pause()
settingStore.setShowFestivalText(false)
setFestivalDate()
}
}
// 设置节日日期
const setFestivalDate = () => {
settingStore.setFestivalDate(currentFestivalData.value?.date || '')
}
return {
openFestival,
cleanup,
holidayFireworksLoaded,
currentFestivalData,
isShowFireworks
}
}