diff --git a/pages/index.vue b/pages/index.vue index b61d962..e5ea28e 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -5,13 +5,14 @@ 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) +const weekendStatus = getWeekendStatus(dayOfWeek) + +type WeekendStatus = { + label: string + value: string +} // 从 API 获取法定节假日 const { data: holidaysData } = await useAsyncData('holidays', () => @@ -38,6 +39,17 @@ function daysUntil(d: Date): number { return Math.ceil((d.getTime() - today.getTime()) / 86400000) } +function getWeekendStatus(dayOfWeek: number): WeekendStatus { + if (dayOfWeek === 5) return { label: '周末', value: '明天就是' } + if (dayOfWeek === 6) return { label: '周末', value: '周末愉快' } + if (dayOfWeek === 0) return { label: '周末', value: '余额 1 天' } + + return { + label: '周末', + value: `还有 ${(6 - dayOfWeek + 7) % 7} 天`, + } +} + useHead({ script: [ { src: '//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js', async: true, defer: true }, @@ -122,8 +134,8 @@ onMounted(() => {