Skip to content

Commit be83af1

Browse files
authored
refactor(calendar): 优化起止月份的计算时机
1 parent 5d9d073 commit be83af1

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

packages/components/calendar/Calendar.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,17 @@ const Calendar = forwardRef<CalendarMethods, CalendarProps>((props, ref) => {
195195
// 读取起止年份
196196
const beginYear = dayjs(rangeFromTo.from).year();
197197
const endYear = dayjs(rangeFromTo.to).year();
198-
// 读取起止月份
199-
const beginMon = parseInt(dayjs(rangeFromTo.from).format('M'), 10);
200-
const endMon = parseInt(dayjs(rangeFromTo.to).format('M'), 10);
201-
198+
202199
if (beginYear === endYear) {
203200
// 同一年内,禁用开始月份至结束月份之外的月份选项
204201
return monthIn < beginMon || monthIn > endMon;
205202
}
206203
if (yearIn === beginYear) {
204+
const beginMon = parseInt(dayjs(rangeFromTo.from).format('M'), 10);
207205
return monthIn < beginMon;
208206
}
209207
if (yearIn === endYear) {
208+
const endMon = parseInt(dayjs(rangeFromTo.to).format('M'), 10);
210209
return monthIn > endMon;
211210
}
212211
}

0 commit comments

Comments
 (0)