mirror of https://github.com/ElemeFE/element
date-picker : fix disabledDate bug 。
未改之前,设置禁用日期后,年和月的禁用状态不准。因为只选取了年和月的某一天进行判断。修改为年和月的每一天都进行判断。pull/5899/merge
parent
be6cc78004
commit
3cf5fd94c6
|
@ -63,11 +63,29 @@
|
||||||
methods: {
|
methods: {
|
||||||
getCellStyle(month) {
|
getCellStyle(month) {
|
||||||
const style = {};
|
const style = {};
|
||||||
const date = new Date(this.date);
|
|
||||||
|
|
||||||
|
var year = this.date.getFullYear();
|
||||||
|
var date = new Date(0);
|
||||||
|
date.setFullYear(year);
|
||||||
date.setMonth(month);
|
date.setMonth(month);
|
||||||
style.disabled = typeof this.disabledDate === 'function' &&
|
date.setHours(0);
|
||||||
this.disabledDate(date);
|
var nextMonth = new Date(date);
|
||||||
|
nextMonth.setMonth(month + 1);
|
||||||
|
|
||||||
|
var flag = false;
|
||||||
|
if (typeof this.disabledDate === 'function') {
|
||||||
|
|
||||||
|
while (date < nextMonth) {
|
||||||
|
if (this.disabledDate(date)) {
|
||||||
|
date = new Date(date.getTime() + 8.64e7);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((date - nextMonth) === 0) flag = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
style.disabled = flag;
|
||||||
style.current = this.month === month;
|
style.current = this.month === month;
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
|
|
|
@ -62,11 +62,28 @@
|
||||||
methods: {
|
methods: {
|
||||||
getCellStyle(year) {
|
getCellStyle(year) {
|
||||||
const style = {};
|
const style = {};
|
||||||
const date = new Date(this.date);
|
|
||||||
|
|
||||||
|
var date = new Date(0);
|
||||||
date.setFullYear(year);
|
date.setFullYear(year);
|
||||||
style.disabled = typeof this.disabledDate === 'function' &&
|
date.setHours(0);
|
||||||
this.disabledDate(date);
|
var nextYear = new Date(date);
|
||||||
|
nextYear.setFullYear(year + 1);
|
||||||
|
|
||||||
|
var flag = false;
|
||||||
|
if (typeof this.disabledDate === 'function') {
|
||||||
|
|
||||||
|
while (date < nextYear) {
|
||||||
|
if (this.disabledDate(date)) {
|
||||||
|
date = new Date(date.getTime() + 8.64e7);
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((date - nextYear) === 0) flag = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
style.disabled = flag;
|
||||||
style.current = Number(this.year) === year;
|
style.current = Number(this.year) === year;
|
||||||
|
|
||||||
return style;
|
return style;
|
||||||
|
|
Loading…
Reference in New Issue