Skip to content

Commit a072b7e

Browse files
fix(calendar): fix calendar range issues (#3759)
* fix(calendar): 修复了当设定日历的range值为同一年内时,终止月份之后的月份选项没有正常禁用的问题 * fix(calendar): 修正了错误使用的rangeFromTo * fix(calendar): 修复了年份选项错误地使用了月份选项禁用范围判定逻辑的问题 Co-Authored-By: 刘宇轩 (刘lyxAndy) <[email protected]> --------- Co-authored-by: 刘宇轩 (刘lyxAndy) <[email protected]>
1 parent d865070 commit a072b7e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/calendar/calendar.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,10 @@ export default mixins(getConfigReceiverMixins<Vue, CalendarConfig>('calendar')).
206206
}
207207

208208
for (let i = begin; i <= end; i++) {
209-
const disabled = this.checkMonthAndYearSelectorDisabled(i, this.curSelectedMonth);
210209
re.push({
211210
value: i,
212211
label: this.t(this.global.yearSelection, { year: i }),
213-
disabled,
212+
disabled: false,
214213
});
215214
}
216215
return re;
@@ -535,13 +534,19 @@ export default mixins(getConfigReceiverMixins<Vue, CalendarConfig>('calendar')).
535534
checkMonthAndYearSelectorDisabled(year: number, month: number): boolean {
536535
let disabled = false;
537536
if (this.rangeFromTo && this.rangeFromTo.from && this.rangeFromTo.to) {
537+
// 读取起止年份
538538
const beginYear = dayjs(this.rangeFromTo.from).year();
539539
const endYear = dayjs(this.rangeFromTo.to).year();
540-
if (year === beginYear) {
541-
const beginMon = parseInt(dayjs(this.rangeFromTo.from).format('M'), 10);
540+
// 读取起止月份
541+
const beginMon = parseInt(dayjs(this.rangeFromTo.from).format('M'), 10);
542+
const endMon = parseInt(dayjs(this.rangeFromTo.to).format('M'), 10);
543+
544+
if (beginYear === endYear) {
545+
// 同一年内,禁用开始月份至结束月份之外的月份选项
546+
disabled = month < beginMon || month > endMon;
547+
} else if (year === beginYear) {
542548
disabled = month < beginMon;
543549
} else if (year === endYear) {
544-
const endMon = parseInt(dayjs(this.rangeFromTo.to).format('M'), 10);
545550
disabled = month > endMon;
546551
}
547552
}

0 commit comments

Comments
 (0)