@@ -115,18 +115,8 @@ export default {
115115 const getRowArr = (N , i = 1 ) => {
116116 return Array .from (new Array (N ), (val , index ) => index + i)
117117 }
118- const mapDayObj = (list , classname ) => {
118+ const mapDayObj = (list , classname , year , month ) => {
119119 return list .map (item => {
120- let month = this .month
121- let year = this .year
122- const months = 12
123- if (classname === ' lastmonth' ) {
124- year = + this .month === 0 ? (this .year - 1 ) : this .year
125- month = (this .month - 1 + months) % months
126- } else if (classname === ' nextmonth' ) {
127- year = + this .month === 11 ? (this .year + 1 ) : this .year
128- month = (this .month + 1 ) % months
129- }
130120 return {
131121 class: classname,
132122 day: item,
@@ -135,17 +125,25 @@ export default {
135125 }
136126 })
137127 }
138- const currentMonthDays = new Date (this .year , this .month + 1 , 0 ).getDate ()
139- const lastMonthDays = new Date (this .year , this .month , 0 ).getDate ()
128+ const lastDayOfCurrentMonth = new Date (this .year , this .month + 1 , 0 )
129+ const dayCountOfCurrentMonth = lastDayOfCurrentMonth .getDate ()
130+ const lastDayOfLastMonth = new Date (this .year , this .month , 0 )
131+ const dayCountOfLastMonth = lastDayOfLastMonth .getDate ()
132+ const yearOfLastMonth = lastDayOfLastMonth .getFullYear ()
133+ const monthOfLastMonth = lastDayOfLastMonth .getMonth ()
134+ const lastDayOfNextMonth = new Date (this .year , this .month + 2 , 0 )
135+ const yearOfNextMonth = lastDayOfNextMonth .getFullYear ()
136+ const monthOfNextMonth = lastDayOfNextMonth .getMonth ()
137+
140138 const startWeek = new Date (this .year , this .month , 1 ).getDay ()
141139 const lastMonthDayCount = startWeek || weekDays
142- const nextMonthDays = allDays - lastMonthDayCount - currentMonthDays
140+ const nextMonthDays = allDays - lastMonthDayCount - dayCountOfCurrentMonth
143141 const lastMonthDates = mapDayObj (
144- getRowArr (lastMonthDays ).slice (- lastMonthDayCount),
145- ' lastmonth' )
146- const currentMonthDates = mapDayObj (getRowArr (currentMonthDays ),
147- ' curmonth' )
148- const nextMonthDates = mapDayObj (getRowArr (nextMonthDays), ' nextmonth' )
142+ getRowArr (dayCountOfLastMonth ).slice (- lastMonthDayCount),
143+ ' lastmonth' , yearOfLastMonth, monthOfLastMonth )
144+ const currentMonthDates = mapDayObj (getRowArr (dayCountOfCurrentMonth ),
145+ ' curmonth' , this . year , this . month )
146+ const nextMonthDates = mapDayObj (getRowArr (nextMonthDays), ' nextmonth' , yearOfNextMonth, monthOfNextMonth )
149147 const allDate = [
150148 ... lastMonthDates,
151149 ... currentMonthDates,
0 commit comments