Skip to content

Commit 7fc299a

Browse files
committed
feat: add prop getYearPanel (#526)
1 parent c504b1d commit 7fc299a

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/calendar/calendar-panel.js

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export default {
4949
type: Boolean,
5050
default: undefined,
5151
},
52+
getYearPanel: {
53+
type: Function,
54+
},
5255
titleFormat: {
5356
type: String,
5457
default: 'YYYY-MM-DD',
@@ -226,6 +229,7 @@ export default {
226229
<TableYear
227230
calendar={innerCalendar}
228231
getCellClasses={this.getYearClasses}
232+
getYearPanel={this.getYearPanel}
229233
onSelect={this.handleSelectYear}
230234
onChangecalendar={this.handleCalendarChange}
231235
/>

src/calendar/table-year.vue

+15-5
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@ export default {
4949
type: Function,
5050
default: () => [],
5151
},
52+
getYearPanel: {
53+
type: Function,
54+
},
5255
},
5356
computed: {
5457
years() {
55-
const firstYear = Math.floor(this.calendar.getFullYear() / 10) * 10;
56-
const years = [];
57-
for (let i = 0; i < 10; i++) {
58-
years.push(firstYear + i);
58+
const calendar = new Date(this.calendar);
59+
if (typeof this.getYearPanel === 'function') {
60+
return this.getYearPanel(calendar);
5961
}
60-
return chunk(years, 2);
62+
return this.getYears(calendar);
6163
},
6264
firstYear() {
6365
return this.years[0][0];
@@ -68,6 +70,14 @@ export default {
6870
},
6971
},
7072
methods: {
73+
getYears(calendar) {
74+
const firstYear = Math.floor(calendar.getFullYear() / 10) * 10;
75+
const years = [];
76+
for (let i = 0; i < 10; i++) {
77+
years.push(firstYear + i);
78+
}
79+
return chunk(years, 2);
80+
},
7181
getNextCalendar(diffYear) {
7282
const year = this.calendar.getFullYear();
7383
const month = this.calendar.getMonth();

0 commit comments

Comments
 (0)