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:
@@ -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}
|
||||
/>
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user