From 4d9365e4f1ab35794450686d4a42610bf6b8d79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:23:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20laydate=20=E5=BC=80?= =?UTF-8?q?=E5=90=AF=20`rangeLinked`=20=E5=B1=9E=E6=80=A7=E5=90=8E?= =?UTF-8?q?=EF=BC=8Cdone=20=E5=87=BD=E6=95=B0=E7=AC=AC=E4=BA=8C=E4=B8=AA?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=9C=AA=E8=83=BD=E6=AD=A3=E7=A1=AE=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=BC=80=E5=A7=8B=E6=97=A5=E6=9C=9F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 48 +++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index 36973a07..7afccf78 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -989,11 +989,11 @@ } })(); - //校验日期有效数字 + // 校验日期有效数字 checkValid(dateTime); if(options.range) checkValid(that.endDate); - //如果初始值格式错误,则纠正初始值 + // 如果初始值格式错误,则纠正初始值 if(error && value){ that.setValue( options.range ? (that.endDate ? that.parse() : '') : that.parse() @@ -1041,6 +1041,7 @@ that.hint('value ' + lang.invalidDate + lang.formatError[1]); } + // 初始赋值 startDate,endState that.startDate = that.startDate || value && lay.extend({}, options.dateTime); // 有默认值才初始化startDate that.autoCalendarModel.auto && that.autoCalendarModel(); that.endState = !options.range || !that.rangeLinked || !!(that.startDate && that.endDate); // 初始化选中范围状态 @@ -1584,21 +1585,22 @@ } }; - //转义为规定格式的日期字符 - Class.prototype.parse = function(state, date){ - var that = this - ,options = that.config - ,dateTime = date || (state == 'end' - ? lay.extend({}, that.endDate, that.endTime) - : ( - options.range - ? lay.extend({}, that.rangeLinked ? that.startDate : options.dateTime, that.startTime) - : options.dateTime) - ) - ,format = laydate.parse(dateTime, that.format, 1); - - //返回日期范围字符 - if(options.range && state === undefined){ + // 转义为规定格式的日期字符 + Class.prototype.parse = function(state, date) { + var that = this; + var options = that.config; + var startDate = (that.rangeLinked ? that.startDate : options.dateTime) + var dateTime = date || ( + state == 'end' ? lay.extend({}, that.endDate, that.endTime) : ( + options.range + ? lay.extend({}, startDate || options.dateTime, that.startTime) + : options.dateTime + ) + ); + var format = laydate.parse(dateTime, that.format, 1); + + // 返回日期范围字符 + if (options.range && state === undefined) { return format + ' '+ that.rangeStr +' ' + that.parse('end'); } @@ -1756,12 +1758,14 @@ }); }; - //执行 done/change 回调 + // 执行 done/change 回调 Class.prototype.done = function(param, type){ - var that = this - ,options = that.config - ,start = lay.extend({}, lay.extend(options.dateTime, that.startTime)) - ,end = lay.extend({}, lay.extend(that.endDate, that.endTime)) + var that = this; + var options = that.config; + var start = lay.extend({}, + lay.extend(that.rangeLinked ? that.startDate : options.dateTime, that.startTime) + ); + var end = lay.extend({}, lay.extend(that.endDate, that.endTime)); lay.each([start, end], function(i, item){ if(!('month' in item)) return;