diff --git a/pages/index.vue b/pages/index.vue index 005b158..b61d962 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2,6 +2,42 @@ import { Icon } from '@iconify/vue' import { siteConfig } from '~/config/site' +const now = new Date() +const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()) + +// 下一个周六或周日 +const dayOfWeek = today.getDay() +const daysToSat = dayOfWeek === 6 ? 0 : (6 - dayOfWeek + 7) % 7 +const nextWeekend = new Date(today) +nextWeekend.setDate(today.getDate() + daysToSat) + +const weekendDays = daysUntil(nextWeekend) + +// 从 API 获取法定节假日 +const { data: holidaysData } = await useAsyncData('holidays', () => + $fetch('https://timor.tech/api/holiday/year/' + today.getFullYear()).catch(() => null) +) + +const nextHoliday = computed(() => { + if (!holidaysData.value) return null + const list = holidaysData.value?.holiday + if (!list) return null + const entries = Object.values(list) as any[] + const upcoming = entries + .filter((h: any) => h.date && new Date(h.date + 'T00:00:00') >= today) + .sort((a: any, b: any) => a.date.localeCompare(b.date)) + return upcoming[0] || null +}) + +const holidayDays = computed(() => { + if (!nextHoliday.value) return null + return daysUntil(new Date(nextHoliday.value.date + 'T00:00:00')) +}) + +function daysUntil(d: Date): number { + return Math.ceil((d.getTime() - today.getTime()) / 86400000) +} + useHead({ script: [ { src: '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js', async: true, defer: true }, @@ -80,8 +116,29 @@ onMounted(() => {
+ +