From 3bec356cb6b53e528e1675c8aca753d03ca1d392 Mon Sep 17 00:00:00 2001 From: sunxiaobin89 <285584806@qq.com> Date: Sun, 17 Jul 2022 17:58:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E6=BB=9Alayer=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=EF=BC=9B=20laydate=20=E4=BF=AE=E5=A4=8D=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E9=80=89=E6=8B=A9=E8=AE=BE=E7=BD=AEmin=20max=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E5=8F=B3=E9=9D=A2=E6=9D=BF=E7=9A=84=E5=8F=AF=E9=80=89?= =?UTF-8?q?=E8=8C=83=E5=9B=B4=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/modules/layer/default/layer.css | 1 - src/modules/laydate.js | 48 ++++++++++++++++++++----- src/modules/layer.js | 46 ++++-------------------- 3 files changed, 45 insertions(+), 50 deletions(-) diff --git a/src/css/modules/layer/default/layer.css b/src/css/modules/layer/default/layer.css index c61fb830..54a6aeee 100644 --- a/src/css/modules/layer/default/layer.css +++ b/src/css/modules/layer/default/layer.css @@ -20,7 +20,6 @@ html #layuicss-layer{display: none; position: absolute; width: 1989px;} .layui-layer-dialog .layui-layer-ico, .layui-layer-setwin a, .layui-layer-btn a{display:inline-block; *display:inline; *zoom:1; vertical-align:top;} -.layui-layer-btn a:focus {border-style: dashed;border-color: rgba(46, 45, 60, 0.84);} .layui-layer-move{display: none; position: fixed; *position: absolute; left: 0px; top: 0px; width: 100%; height: 100%; cursor: move; opacity: 0; filter:alpha(opacity=0); background-color: #fff; z-index: 2147483647;} .layui-layer-resize{position: absolute; width: 15px; height: 15px; right: 0; bottom: 0; cursor: se-resize;} diff --git a/src/modules/laydate.js b/src/modules/laydate.js index dfc94afd..28629e8d 100644 --- a/src/modules/laydate.js +++ b/src/modules/laydate.js @@ -762,22 +762,29 @@ } //如果当前日期不在设定的最大小日期区间,则自动纠正在可选区域 - var getDateTime = function(obj){ - return that.newDate(obj).getTime(); - }; - //校验主面板是否在可选日期区间 - if(getDateTime(dateTime) > getDateTime(options.max)){ //若超出最大日期 + if(that.getDateTime(dateTime) > that.getDateTime(options.max)){ //若超出最大日期 dateTime = options.dateTime = lay.extend({}, options.max); - } else if(getDateTime(dateTime) < getDateTime(options.min)){ //若少于最小日期 + } else if(that.getDateTime(dateTime) < that.getDateTime(options.min)){ //若少于最小日期 dateTime = options.dateTime = lay.extend({}, options.min); } //校验右侧面板是否在可选日期区间 if(options.range){ - if(getDateTime(that.endDate) < getDateTime(options.min) || getDateTime(that.endDate) > getDateTime(options.max)){ + if(that.getDateTime(that.endDate) < that.getDateTime(options.min) || that.getDateTime(that.endDate) > that.getDateTime(options.max)){ that.endDate = lay.extend({}, options.max); } + // 有时间范围的情况下初始化startTime和endTime + that.startTime = { + hours: options.dateTime.hours, + minutes: options.dateTime.minutes, + seconds: options.dateTime.seconds, + } + that.endTime = { + hours: that.endDate.hours, + minutes: that.endDate.minutes, + seconds: that.endDate.seconds, + } } fn && fn(); @@ -826,7 +833,7 @@ Class.prototype.limit = function(elem, date, index, time){ var that = this ,options = that.config, timestrap = {} - ,dateTime = options[index > 41 ? 'endDate' : 'dateTime'] + ,dateTime = index > (time ? 0 : 41) ? that.endDate : options.dateTime ,isOut, thisDateTime = lay.extend({}, dateTime, date || {}); lay.each({ @@ -1284,7 +1291,12 @@ ,dateTime.seconds || 0 ); }; - + + //获得指定日期时间对象时间戳 + Class.prototype.getDateTime = function(obj){ + return this.newDate(obj).getTime(); + } + //赋值 Class.prototype.setValue = function(value){ var that = this @@ -1390,6 +1402,24 @@ ,minutes: i ? 59: 0 ,seconds: i ? 59: 0 }; + if (index === i) { + // 判断选择之后的是否在范围内,超出则需要调整时分秒 + if (that.getDateTime(lay.extend({}, dateTime, that[item])) < that.getDateTime(options.min)) { + that[item] = { + hours: options.min.hours + ,minutes: options.min.minutes + ,seconds: options.min.seconds + }; + lay.extend(dateTime, that[item]); + } else if (that.getDateTime(lay.extend({}, dateTime, that[item])) > that.getDateTime(options.max)) { + that[item] = { + hours: options.max.hours + ,minutes: options.max.minutes + ,seconds: options.max.seconds + }; + lay.extend(dateTime, that[item]); + } + } }); that.calendar(null, index).done(null, 'change'); } else if(options.position === 'static'){ //直接嵌套的选中 diff --git a/src/modules/layer.js b/src/modules/layer.js index 46af8528..edcee5b0 100644 --- a/src/modules/layer.js +++ b/src/modules/layer.js @@ -133,8 +133,7 @@ var layer = { if(type) yes = options; return layer.open($.extend({ content: content, - yes: yes, - autofocus: true + yes: yes }, type ? {} : options)); }, @@ -147,7 +146,6 @@ var layer = { return layer.open($.extend({ content: content, btn: ready.btn, - autofocus: true, yes: yes, btn2: cancel }, type ? {} : options)); @@ -166,7 +164,6 @@ var layer = { title: false, closeBtn: false, btn: false, - autofocus: false, resize: false, end: end }, (type && !ready.config.skin) ? { @@ -182,16 +179,11 @@ var layer = { }, load: function(icon, options){ - var activeElem = document.activeElement; // 记录弹出时的焦点 return layer.open($.extend({ type: 3, icon: icon || 0, resize: false, - shade: 0.01, - autofocus: true, // 加载的时候去掉原来的焦点 - end: function () { - activeElem.focus(); // 恢复加载前的焦点 - } + shade: 0.01 }, options)); }, @@ -200,7 +192,6 @@ var layer = { type: 4, content: [content, follow], closeBtn: false, - autofocus: false, time: 3000, shade: false, resize: false, @@ -676,29 +667,6 @@ Class.pt.move = function(){ Class.pt.callback = function(){ var that = this, layero = that.layero, config = that.config; that.openLayer(); - - var btnElem = layero.find('.'+ doms[6]).children('a'); - - // 根据autofocus设置默认聚焦的按钮 - var autofocus = config.autofocus; - if (autofocus) { - document.activeElement.blur(); - btnElem.attr('href', 'javascript:;'); - var btnFocus; - if (layui.type(autofocus) === 'string') { - var btnNum = parseInt(autofocus.substr(3)) || 1; - btnFocus = btnElem.filter(function (index, item) { - return $(item).hasClass(doms[0] + '-' + autofocus.substr(0, 3) + (btnNum - 1)); - }).first(); - } else { - btnFocus = btnElem.first(); - } - btnFocus && btnFocus.length && btnFocus.focus(); - layero.one('click', function (event) { - btnElem.attr('href', null); - }) - } - if(config.success){ if(config.type == 2){ layero.find('iframe').on('load', function(){ @@ -711,7 +679,7 @@ Class.pt.callback = function(){ layer.ie == 6 && that.IE6(layero); //按钮 - btnElem.on('click', function(){ + layero.find('.'+ doms[6]).children('a').on('click', function(){ var index = $(this).index(); if(index === 0){ if(config.yes){ @@ -1090,7 +1058,6 @@ layer.prompt = function(options, yes){ return layer.open($.extend({ type: 1 ,btn: ['确定','取消'] - ,autofocus: false ,content: content ,skin: 'layui-layer-prompt' + skin('prompt') ,maxWidth: win.width() @@ -1102,10 +1069,9 @@ layer.prompt = function(options, yes){ ,resize: false ,yes: function(index){ var value = prompt.val(); - // if(value === ''){ - // prompt.focus(); - // } else // 允许为空 - if(value.length > (options.maxlength||500)) { + if(value === ''){ + prompt.focus(); + } else if(value.length > (options.maxlength||500)) { layer.tips('最多输入'+ (options.maxlength || 500) +'个字数', prompt, {tips: 1}); } else { yes && yes(value, index, prompt);