Skip to content

Commit

Permalink
feat: add prop getYearPanel (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxiong10 committed Nov 18, 2020
1 parent c504b1d commit 7fc299a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/calendar/calendar-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export default {
type: Boolean,
default: undefined,
},
getYearPanel: {
type: Function,
},
titleFormat: {
type: String,
default: 'YYYY-MM-DD',
Expand Down Expand Up @@ -226,6 +229,7 @@ export default {
<TableYear
calendar={innerCalendar}
getCellClasses={this.getYearClasses}
getYearPanel={this.getYearPanel}
onSelect={this.handleSelectYear}
onChangecalendar={this.handleCalendarChange}
/>
Expand Down
20 changes: 15 additions & 5 deletions src/calendar/table-year.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,17 @@ export default {
type: Function,
default: () => [],
},
getYearPanel: {
type: Function,
},
},
computed: {
years() {
const firstYear = Math.floor(this.calendar.getFullYear() / 10) * 10;
const years = [];
for (let i = 0; i < 10; i++) {
years.push(firstYear + i);
const calendar = new Date(this.calendar);
if (typeof this.getYearPanel === 'function') {
return this.getYearPanel(calendar);
}
return chunk(years, 2);
return this.getYears(calendar);
},
firstYear() {
return this.years[0][0];
Expand All @@ -68,6 +70,14 @@ export default {
},
},
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) {
const year = this.calendar.getFullYear();
const month = this.calendar.getMonth();
Expand Down

0 comments on commit 7fc299a

Please sign in to comment.