From f98fc404df22aeabc9ed4864a355eaac8f86c7b1 Mon Sep 17 00:00:00 2001 From: Kaxi <1042864399@qq.com> Date: Wed, 15 Jul 2026 23:35:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=91=A8=E6=9C=AB?= =?UTF-8?q?=E5=80=92=E8=AE=A1=E6=97=B6=E6=96=87=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index.vue | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) 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(() => {
- 周末 - {{ weekendDays }} 天 + {{ weekendStatus.label }} + {{ weekendStatus.value }}