2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-24 02:10:35 +03:00

feat: add prop getYearPanel (#526)

This commit is contained in:
mengxiong10
2020-11-18 15:38:41 +08:00
parent c504b1dafe
commit 7fc299a5e5
2 changed files with 19 additions and 5 deletions
+4
View File
@@ -49,6 +49,9 @@ export default {
type: Boolean, type: Boolean,
default: undefined, default: undefined,
}, },
getYearPanel: {
type: Function,
},
titleFormat: { titleFormat: {
type: String, type: String,
default: 'YYYY-MM-DD', default: 'YYYY-MM-DD',
@@ -226,6 +229,7 @@ export default {
<TableYear <TableYear
calendar={innerCalendar} calendar={innerCalendar}
getCellClasses={this.getYearClasses} getCellClasses={this.getYearClasses}
getYearPanel={this.getYearPanel}
onSelect={this.handleSelectYear} onSelect={this.handleSelectYear}
onChangecalendar={this.handleCalendarChange} onChangecalendar={this.handleCalendarChange}
/> />
+15 -5
View File
@@ -49,15 +49,17 @@ export default {
type: Function, type: Function,
default: () => [], default: () => [],
}, },
getYearPanel: {
type: Function,
},
}, },
computed: { computed: {
years() { years() {
const firstYear = Math.floor(this.calendar.getFullYear() / 10) * 10; const calendar = new Date(this.calendar);
const years = []; if (typeof this.getYearPanel === 'function') {
for (let i = 0; i < 10; i++) { return this.getYearPanel(calendar);
years.push(firstYear + i);
} }
return chunk(years, 2); return this.getYears(calendar);
}, },
firstYear() { firstYear() {
return this.years[0][0]; return this.years[0][0];
@@ -68,6 +70,14 @@ export default {
}, },
}, },
methods: { methods: {
getYears(calendar) {
const firstYear = Math.floor(calendar.getFullYear() / 10) * 10;
const years = [];
for (let i = 0; i < 10; i++) {
years.push(firstYear + i);
}
return chunk(years, 2);
},
getNextCalendar(diffYear) { getNextCalendar(diffYear) {
const year = this.calendar.getFullYear(); const year = this.calendar.getFullYear();
const month = this.calendar.getMonth(); const month = this.calendar.getMonth();