fix(laydate): 修复开启 rangeLinked 时,选择同一日期,某些情况时间会反选的问题 (#1517)

* fix(laydate): 修复 laydate 开启 rangeLinked 时,选择同一日期,某些情况时间会反选的问题

* chore(laydate): 简化代码

* update code

* update code
pull/1523/head^2
morning-star 2023-12-31 23:15:23 +08:00 committed by GitHub
parent c324802a25
commit 153576cf99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -1802,7 +1802,6 @@
// 重新选择或者第一次选择
index = 0;
that.endState = false;
that.endDate = {};
} else {
index = 1;
that.endState = true;
@ -1860,18 +1859,22 @@
if (that.endState && that.autoCalendarModel.auto) {
isChange = that.autoCalendarModel();
}
if ((isChange || that.rangeLinked && that.endState) && that.newDate(that.startDate) > that.newDate(that.endDate)) {
// 判断是否反选
var needSwapDate = (isChange || that.rangeLinked && that.endState) && that.newDate(that.startDate) > that.newDate(that.endDate);
if (needSwapDate){
var isSameDate = that.startDate.year === that.endDate.year && that.startDate.month === that.endDate.month && that.startDate.date === that.endDate.date;
// 判断是否反选
var startDate = that.startDate;
that.startDate = lay.extend({}, that.endDate, isSameDate ? {} : that.startTime);
var startDate;
// 如果是同一天并且出现了反选证明是时分秒出现开始时间大于结束时间的现象
if(isSameDate){
startDate = that.startTime;
that.startTime = that.endTime;
that.endTime = startDate;
}
// 当出现反向选择时(即“后点击”的日期比“先点击”的日期小),重新提取区间
startDate = that.startDate;
that.startDate = lay.extend({}, that.endDate, that.startTime);
options.dateTime = lay.extend({}, that.startDate);
that.endDate = lay.extend({}, startDate, isSameDate ? {} : that.endTime);
isSameDate && ( // 如果是同一天并且出现了反选证明是时分秒出现开始时间大于结束时间的现象
startDate = that.startTime,
that.startTime = that.endTime,
that.endTime = startDate
)
that.endDate = lay.extend({}, startDate, that.endTime);
}
isChange && (options.dateTime = lay.extend({}, that.startDate));
}