From 22a9b7d0b5f13ddd173350efb5cedd3e9701f3a0 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <470459819@qq.com> Date: Sun, 18 Sep 2022 23:30:18 +0800 Subject: [PATCH] =?UTF-8?q?laydate=20=E4=BF=AE=E5=A4=8D=E5=BF=AB=E6=8D=B7?= =?UTF-8?q?=E6=A0=8F=E7=9A=84=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/laydate.js | 47 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/modules/laydate.js b/src/modules/laydate.js index f29f07cf..2b110822 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -93,7 +93,8 @@ var ELEM_TIME_TEXT = 'laydate-time-text'; var ELEM_TIME_BTN = 'laydate-btns-time'; var ELEM_PREVIEW = 'layui-laydate-preview'; - + var ELEM_MAIN = 'layui-laydate-main'; + // 组件构造器 var Class = function(options){ var that = this; @@ -497,7 +498,7 @@ divContent.appendChild(table); elemMain[i] = lay.elem('div', { - "class": 'layui-laydate-main laydate-main-list-'+ i + "class": ELEM_MAIN + ' laydate-main-list-'+ i }); elemMain[i].appendChild(divHeader); @@ -543,16 +544,50 @@ if (!layui.isArray(value)) { value = [value]; } + var type = options.type; lay.each(value, function (i, item) { - lay.extend([options.dateTime, that.endDate][i], that.systemDate(layui.type(item) === 'date' ? item : new Date(item))) - that.checkDate('limit').calendar(null,i); + var dateTime = [options.dateTime, that.endDate][i]; + if (type === 'time' && layui.type(item) !== 'date') { + if (that.EXP_IF.test(item)) { + item = (item.match(that.EXP_SPLIT) || []).slice(1); + lay.extend(dateTime, {hours: item[0] | 0, minutes: item[2] | 0, seconds: item[4] | 0}) + } + } else { + lay.extend(dateTime, that.systemDate(layui.type(item) === 'date' ? item : new Date(item))) + } + + if (type === 'time') { + that[['startTime', 'endTime'][i]] = { + hours: dateTime.hours, + minutes: dateTime.minutes, + seconds: dateTime.seconds, + } + } + if (type === 'year' || type === 'month' || type === 'time') { + that.listYM[i] = [dateTime.year, dateTime.month + 1]; + that.checkDate('limit').calendar(null,i); + that.list(type, i); + } else { + that.checkDate('limit').calendar(null,i); + that.closeList(); + } }); - that.closeList(); + var timeBtn = lay(that.footer).find('.'+ ELEM_TIME_BTN).removeClass(DISABLED); - timeBtn.attr('lay-type') === 'date' && timeBtn.click(); + timeBtn && timeBtn.attr('lay-type') === 'date' && timeBtn[0].click(); that.done(null, 'change'); lay(this).addClass(THIS); + + if (options.position !== 'static' && !options.range) { + if (type === 'date') { + that.choose(lay(elem).find('td.layui-this')) + } else if (type === 'year' || type === 'month') { + if(lay(elemMain[0]).find('.' + ELEM_MAIN + ' li.' + THIS + ':not(.laydate-disabled)')[0]) { + that.setValue(that.parse()).remove().done(); + } + } + } }) }