From 07d748cb0acfb4722408e680204880e82f067142 Mon Sep 17 00:00:00 2001 From: rsgltzyd Date: Tue, 17 Sep 2024 12:06:45 +0800 Subject: [PATCH] fix CustomCalendar --- src/components/CustomCalendar.js | 5 ++++- src/components/CustomCalendar.vue | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/components/CustomCalendar.js b/src/components/CustomCalendar.js index 183f44a..425fc56 100644 --- a/src/components/CustomCalendar.js +++ b/src/components/CustomCalendar.js @@ -40,12 +40,15 @@ function initDay(currentDays = new Array(42), year = defaultYear, month = defaul } const days = currentDays; + const lastDayOfLastMonth = new Date(year, month, 0); const firstDayOfMonth = new Date(year, month, 1); const lastDayOfMonth = new Date(year, month + 1, 0); const currentDaysOfMonth = lastDayOfMonth.getDate(); + const daysOfLastMonth = lastDayOfLastMonth.getDate(); for (let i = 0; i < firstDayOfMonth.getDay(); i++) { - days[i] = new Day('', ''); + const weekDay = firstDayOfMonth.getDay() - 1; + days[i] = new Day(year, month - 1, daysOfLastMonth - weekDay + i, week_zh_cn[i]); } for (let i = 0; i < currentDaysOfMonth; i++) { diff --git a/src/components/CustomCalendar.vue b/src/components/CustomCalendar.vue index 5aebb36..1c70180 100644 --- a/src/components/CustomCalendar.vue +++ b/src/components/CustomCalendar.vue @@ -25,7 +25,8 @@ const editMonth = { const handleDayClick = (date) => { year.value = date.month >= 12 ? date.year + 1 : date.year - month.value = date.month % 12 + year.value = date.month < 0 ? date.year - 1 : year.value + month.value = date.month < 0 ? 11 : date.month % 12 day.value = date.day dayArray.value = initDay(dayArray.value, year.value, month.value, day.value) }