From f487d11f3bcaf97b3662f3561623865a51e274d5 Mon Sep 17 00:00:00 2001 From: mengxiong10 <15623530290@163.com> Date: Sun, 12 Jun 2022 10:36:32 +0800 Subject: [PATCH] feat: add disabledCalendarChanger (#628) --- src/calendar/calendar-panel.js | 33 ++++++++++++++++++---- src/calendar/icon-button.vue | 9 +++++- src/calendar/table-date.vue | 50 +++++++++++++++++++++++++++++++--- src/calendar/table-month.vue | 33 ++++++++++++++++++++-- src/calendar/table-year.vue | 33 ++++++++++++++++++++-- src/style/btn.scss | 5 ++++ 6 files changed, 146 insertions(+), 17 deletions(-) diff --git a/src/calendar/calendar-panel.js b/src/calendar/calendar-panel.js index f9dec48..f4ba2fc 100644 --- a/src/calendar/calendar-panel.js +++ b/src/calendar/calendar-panel.js @@ -33,6 +33,10 @@ export default { defaultPanel: { type: String, }, + disabledCalendarChanger: { + type: Function, + default: () => false, + }, disabledDate: { type: Function, default: () => false, @@ -185,19 +189,33 @@ export default { return classes.concat(this.getClasses(cellDate, this.innerValue, classes.join(' '))); }, getMonthClasses(month) { - if (this.type !== 'month') { - return this.calendarMonth === month ? 'active' : ''; - } const classes = []; + if (this.type !== 'month') { + if (this.calendarMonth === month) { + classes.push('active'); + } + const cellDate = this.getMonthCellDate(month); + if (this.disabledCalendarChanger(cellDate, 'month')) { + classes.push('disabled'); + } + return classes; + } const cellDate = this.getMonthCellDate(month); classes.push(this.getStateClass(cellDate)); return classes.concat(this.getClasses(cellDate, this.innerValue, classes.join(' '))); }, getYearClasses(year) { - if (this.type !== 'year') { - return this.calendarYear === year ? 'active' : ''; - } const classes = []; + if (this.type !== 'year') { + if (this.calendarYear === year) { + classes.push('active'); + } + const cellDate = this.getYearCellDate(year); + if (this.disabledCalendarChanger(cellDate, 'year')) { + classes.push('disabled'); + } + return classes; + } const cellDate = this.getYearCellDate(year); classes.push(this.getStateClass(cellDate)); return classes.concat(this.getClasses(cellDate, this.innerValue, classes.join(' '))); @@ -227,6 +245,7 @@ export default { if (panel === 'year') { return (