2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-11 22:12:27 +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,
default: undefined,
},
getYearPanel: {
type: Function,
},
titleFormat: {
type: String,
default: 'YYYY-MM-DD',
@@ -226,6 +229,7 @@ export default {
<TableYear
calendar={innerCalendar}
getCellClasses={this.getYearClasses}
getYearPanel={this.getYearPanel}
onSelect={this.handleSelectYear}
onChangecalendar={this.handleCalendarChange}
/>
+15 -5
View File
@@ -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];
@@ -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();