Skip to content

Commit e79cced

Browse files
author
luchunyu
committed
fix(datepicker): update datepicker td render and remove console
1 parent 2ad02f4 commit e79cced

4 files changed

Lines changed: 17 additions & 25 deletions

File tree

src/components/calendar/date-table.vue

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

src/components/calendar/index.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ export default {
132132
if (this.type === 'month') {
133133
const date = `${this.year}-${this.fixZero(this.month + 1)}`
134134
this.date = new Date(date).format(this.format)
135-
console.log(this.date)
136135
this.$emit('update', this.date)
137136
}
138137
},

src/components/datepicker/daterange.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ export default {
269269
this.$emit('change', this.value)
270270
},
271271
confirmRange () {
272-
console.log('confirm range')
273272
if (this.start && this.end) {
274273
this.$emit('change', [this.start, this.end])
275274
} else {

src/components/datepicker/index.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ export default {
274274
const dates = value.split(separtor)
275275
const reg = new RegExp('^\\d{4}' + separtor + '\\d{2}' + separtor + '\\d{2}$')
276276
const valueValid = reg.test(value)
277-
console.log(value)
278277
if (valueValid) {
279278
const year = parseInt(dates[0])
280279
const month = parseInt(dates[1])
@@ -289,7 +288,6 @@ export default {
289288
}
290289
},
291290
dateChange (value) {
292-
console.log(value)
293291
const dateValid = this.checkDateValid(value)
294292
if (dateValid) {
295293
this.date = value
@@ -310,12 +308,10 @@ export default {
310308
},
311309
setDateRange (daterange) {
312310
this.date = daterange
313-
console.log(daterange)
314311
this.$emit('change', this.date)
315312
this.close()
316313
},
317314
setDate (date, notClose) {
318-
console.log(date)
319315
this.showDate = date
320316
this.$emit('change', date)
321317
!notClose && this.close()

0 commit comments

Comments
 (0)