From ee6946dca7558bce4992b5932c5ab818f4e53142 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsin@users.noreply.github.com> Date: Thu, 22 Apr 2021 10:25:41 +0800 Subject: [PATCH] update --- dist/laydate.js | 4 +- dist/theme/default/laydate.css | 2 +- package.json | 2 +- src/laydate.js | 142 +++++++++++++++++++++++++++++---- src/theme/default/laydate.css | 4 +- 5 files changed, 133 insertions(+), 21 deletions(-) diff --git a/dist/laydate.js b/dist/laydate.js index 96afe95..0fd3bbe 100644 --- a/dist/laydate.js +++ b/dist/laydate.js @@ -1,2 +1,2 @@ -/*! layDate v5.2.0 | 日期与时间组件 | The MIT License */ - ;!function(){"use strict";var e="lay",t=window.document,n=function(e){return new a(e)},a=function(e){for(var n=0,a="object"==typeof e?[e]:(this.selector=e,t.querySelectorAll(e||null));n0;i--)if("interactive"===n[i].readyState){e=n[i].src;break}return e||n[a].src}();return e.substring(0,e.lastIndexOf("/")+1)},n.stope=function(e){e=e||window.event,e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},n.each=function(e,t){var n,a=this;if("function"!=typeof t)return a;if(e=e||[],e.constructor===Object){for(n in e)if(t.call(e[n],n,e[n]))break}else for(n=0;n80?window.console&&console.error(o+".css: Invalid"):void(1989===parseInt(n.getStyle(t.getElementById(s),"width"))?a():setTimeout(y,100))}()},n.hasScrollbar=function(){return t.body.scrollHeight>(window.innerHeight||t.documentElement.clientHeight)},n.position=function(e,a,i){if(a){i=i||{},e!==t&&e!==n("body")[0]||(i.clickType="right");var r="right"===i.clickType?function(){var e=i.e||window.event||{};return{left:e.clientX,top:e.clientY,right:e.clientX,bottom:e.clientY}}():e.getBoundingClientRect(),l=a.offsetWidth,o=a.offsetHeight,s=function(e){return e=e?"scrollLeft":"scrollTop",t.body[e]|t.documentElement[e]},c=function(e){return t.documentElement[e?"clientWidth":"clientHeight"]},y=5,d=r.left,u=r.bottom;d+l+y>c("width")&&(d=c("width")-l-y),u+o+y>c()&&(r.top>o+y?u=r.top-o-2*y:"right"===i.clickType&&(u=c()-o-2*y,u<0&&(u=0)));var m=i.position;if(m&&(a.style.position=m),a.style.left=d+("fixed"===m?0:s(1))+"px",a.style.top=u+("fixed"===m?0:s())+"px",!n.hasScrollbar()){var h=a.getBoundingClientRect();!i.SYSTEM_RELOAD&&h.bottom+y>c()&&(i.SYSTEM_RELOAD=!0,setTimeout(function(){n.position(e,a,i)},50))}}},n.options=function(e,t){var a=n(e),i=t||"lay-options";try{return new Function("return "+(a.attr(i)||"{}"))()}catch(r){return hint.error("parseerror:"+r,"error"),{}}},n.isTopElem=function(e){var a=[t,n("body")[0]],i=!1;return n.each(a,function(t,n){if(n===e)return i=!0}),i},a.addStr=function(e,t){return e=e.replace(/\s+/," "),t=t.replace(/\s+/," ").split(" "),n.each(t,function(t,n){new RegExp("\\b"+n+"\\b").test(e)||(e=e+" "+n)}),e.replace(/^\s|\s$/,"")},a.removeStr=function(e,t){return e=e.replace(/\s+/," "),t=t.replace(/\s+/," ").split(" "),n.each(t,function(t,n){var a=new RegExp("\\b"+n+"\\b");a.test(e)&&(e=e.replace(a,""))}),e.replace(/\s+/," ").replace(/^\s|\s$/,"")},a.prototype.find=function(e){var t=this,a=0,i=[],r="object"==typeof e;return this.each(function(n,l){for(var o=r?[e]:l.querySelectorAll(e||null);a0)return a[0].style[e]}():a.each(function(a,r){"object"==typeof e?n.each(e,function(e,t){r.style[e]=i(t)}):r.style[e]=i(t)})},a.prototype.width=function(e){var t=this;return void 0===e?function(){if(t.length>0)return t[0].offsetWidth}():t.each(function(n,a){t.css("width",e)})},a.prototype.height=function(e){var t=this;return void 0===e?function(){if(t.length>0)return t[0].offsetHeight}():t.each(function(n,a){t.css("height",e)})},a.prototype.attr=function(e,t){var n=this;return void 0===t?function(){if(n.length>0)return n[0].getAttribute(e)}():n.each(function(n,a){a.setAttribute(e,t)})},a.prototype.removeAttr=function(e){return this.each(function(t,n){n.removeAttribute(e)})},a.prototype.html=function(e){return this.each(function(t,n){n.innerHTML=e})},a.prototype.val=function(e){return this.each(function(t,n){n.value=e})},a.prototype.append=function(e){return this.each(function(t,n){"object"==typeof e?n.appendChild(e):n.innerHTML=n.innerHTML+e})},a.prototype.remove=function(e){return this.each(function(t,n){e?n.removeChild(e):n.parentNode.removeChild(n)})},a.prototype.on=function(e,t){return this.each(function(n,a){a.attachEvent?a.attachEvent("on"+e,function(e){e.target=e.srcElement,t.call(a,e)}):a.addEventListener(e,t,!1)})},a.prototype.off=function(e,t){return this.each(function(n,a){a.detachEvent?a.detachEvent("on"+e,t):a.removeEventListener(e,t,!1)})},window.lay=n,window.layui&&layui.define&&layui.define(function(t){t(e,n)})}(),!function(e){"use strict";var t=e.layui&&layui.define,n={getPath:e.lay&&lay.getPath?lay.getPath():"",link:function(t,n,i){a.path&&e.lay&&lay.link&&lay.link(a.path+t,n,i)}},a={v:"5.2.0",config:{},index:e.laydate&&e.laydate.v?1e5:0,path:n.getPath,set:function(e){var t=this;return t.config=lay.extend({},t.config,e),t},ready:function(e){var i="laydate",r="",l=(t?"modules/laydate/":"theme/")+"default/laydate.css?v="+a.v+r;return t?layui.addcss(l,e,i):n.link(l,e,i),this}},i=function(){var e=this;return{hint:function(t){e.hint.call(e,t)},config:e.config}},r="laydate",l=".layui-laydate",o="layui-this",s="laydate-disabled",c=[100,2e5],y="layui-laydate-static",d="layui-laydate-list",u="layui-laydate-hint",m="layui-laydate-footer",h=".laydate-btns-confirm",f="laydate-time-text",p=".laydate-btns-time",g=function(e){var t=this;t.index=++a.index,t.config=lay.extend({},t.config,a.config,e),a.ready(function(){t.init()})};g.isLeapYear=function(e){return e%4===0&&e%100!==0||e%400===0},g.prototype.config={type:"date",range:!1,format:"yyyy-MM-dd",value:null,isInitValue:!0,min:"1900-1-1",max:"2099-12-31",trigger:"click",show:!1,showBottom:!0,btns:["clear","now","confirm"],lang:"cn",theme:"default",position:null,calendar:!1,mark:{},zIndex:null,done:null,change:null},g.prototype.lang=function(){var e=this,t=e.config,n={cn:{weeks:["日","一","二","三","四","五","六"],time:["时","分","秒"],timeTips:"选择时间",startTime:"开始时间",endTime:"结束时间",dateTips:"返回日期",month:["一","二","三","四","五","六","七","八","九","十","十一","十二"],tools:{confirm:"确定",clear:"清空",now:"现在"},timeout:"结束时间不能早于开始时间
请重新选择",invalidDate:"不在有效日期或时间范围内",formatError:["日期格式不合法
必须遵循下述格式:
","
已为你重置"]},en:{weeks:["Su","Mo","Tu","We","Th","Fr","Sa"],time:["Hours","Minutes","Seconds"],timeTips:"Select Time",startTime:"Start Time",endTime:"End Time",dateTips:"Select Date",month:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],tools:{confirm:"Confirm",clear:"Clear",now:"Now"},timeout:"End time cannot be less than start Time
Please re-select",invalidDate:"Invalid date",formatError:["The date format error
Must be followed:
","
It has been reset"]}};return n[t.lang]||n.cn},g.prototype.init=function(){var t=this,n=t.config,a="yyyy|y|MM|M|dd|d|HH|H|mm|m|ss|s",i="static"===n.position,r={year:"yyyy",month:"yyyy-MM",date:"yyyy-MM-dd",time:"HH:mm:ss",datetime:"yyyy-MM-dd HH:mm:ss"};n.elem=lay(n.elem),n.eventElem=lay(n.eventElem),n.elem[0]&&(n.range===!0&&(n.range="-"),r[n.type]||(e.console&&console.error&&console.error("laydate type error:'"+n.type+"' is not supported"),n.type="date"),n.format===r.date&&(n.format=r[n.type]||r.date),t.format=n.format.match(new RegExp(a+"|.","g"))||[],t.EXP_IF="",t.EXP_SPLIT="",lay.each(t.format,function(e,n){var i=new RegExp(a).test(n)?"\\d{"+function(){return new RegExp(a).test(t.format[0===e?e+1:e-1]||"")?/^yyyy|y$/.test(n)?4:n.length:/^yyyy$/.test(n)?"1,4":/^y$/.test(n)?"1,308":"1,2"}()+"}":"\\"+n;t.EXP_IF=t.EXP_IF+i,t.EXP_SPLIT=t.EXP_SPLIT+"("+i+")"}),t.EXP_IF=new RegExp("^"+(n.range?t.EXP_IF+"\\s\\"+n.range+"\\s"+t.EXP_IF:t.EXP_IF)+"$"),t.EXP_SPLIT=new RegExp("^"+t.EXP_SPLIT+"$",""),t.isInput(n.elem[0])||"focus"===n.trigger&&(n.trigger="click"),n.elem.attr("lay-key")||(n.elem.attr("lay-key",t.index),n.eventElem.attr("lay-key",t.index)),n.mark=lay.extend({},n.calendar&&"cn"===n.lang?{"0-1-1":"元旦","0-2-14":"情人","0-3-8":"妇女","0-3-12":"植树","0-4-1":"愚人","0-5-1":"劳动","0-5-4":"青年","0-6-1":"儿童","0-9-10":"教师","0-9-18":"国耻","0-10-1":"国庆","0-12-25":"圣诞"}:{},n.mark),lay.each(["min","max"],function(e,t){var a=[],i=[];if("number"==typeof n[t]){var r=n[t],l=(new Date).getTime(),o=864e5,s=new Date(r?r0)return!0;var a=lay.elem("div",{"class":"layui-laydate-header"}),i=[function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-prev-y"});return e.innerHTML="",e}(),function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-prev-m"});return e.innerHTML="",e}(),function(){var e=lay.elem("div",{"class":"laydate-set-ym"}),t=lay.elem("span"),n=lay.elem("span");return e.appendChild(t),e.appendChild(n),e}(),function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-next-m"});return e.innerHTML="",e}(),function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-next-y"});return e.innerHTML="",e}()],c=lay.elem("div",{"class":"layui-laydate-content"}),y=lay.elem("table"),d=lay.elem("thead"),u=lay.elem("tr");lay.each(i,function(e,t){a.appendChild(t)}),d.appendChild(u),lay.each(new Array(6),function(e){var t=y.insertRow(0);lay.each(new Array(7),function(a){if(0===e){var i=lay.elem("th");i.innerHTML=n.weeks[a],u.appendChild(i)}t.insertCell(a)})}),y.insertBefore(d,y.children[0]),c.appendChild(y),r[e]=lay.elem("div",{"class":"layui-laydate-main laydate-main-list-"+e}),r[e].appendChild(a),r[e].appendChild(c),l.push(i),o.push(c),s.push(y)}),lay(c).html(function(){var e=[],i=[];return"datetime"===t.type&&e.push(''+n.timeTips+""),lay.each(t.btns,function(e,r){var l=n.tools[r]||"btn";t.range&&"now"===r||(a&&"clear"===r&&(l="cn"===t.lang?"重置":"Reset"),i.push(''+l+""))}),e.push('"),e.join("")}()),lay.each(r,function(e,t){i.appendChild(t)}),t.showBottom&&i.appendChild(c),/^#/.test(t.theme)){var d=lay.elem("style"),u=["#{{id}} .layui-laydate-header{background-color:{{theme}};}","#{{id}} .layui-this{background-color:{{theme}} !important;}"].join("").replace(/{{id}}/g,e.elemID).replace(/{{theme}}/g,t.theme);"styleSheet"in d?(d.setAttribute("type","text/css"),d.styleSheet.cssText=u):d.innerHTML=u,lay(i).addClass("laydate-theme-molv"),i.appendChild(d)}e.remove(g.thisElemDate),a?t.elem.append(i):(document.body.appendChild(i),e.position()),e.checkDate().calendar(null,0,"init"),e.changeEvent(),g.thisElemDate=e.elemID,"function"==typeof t.ready&&t.ready(lay.extend({},t.dateTime,{month:t.dateTime.month+1}))},g.prototype.remove=function(e){var t=this,n=(t.config,lay("#"+(e||t.elemID)));return n[0]?(n.hasClass(y)||t.checkDate(function(){n.remove(),delete t.endDate}),t):t},g.prototype.position=function(){var e=this,t=e.config;return lay.position(e.bindElem||t.elem[0],e.elem,{position:t.position}),e},g.prototype.hint=function(e){var t=this,n=(t.config,lay.elem("div",{"class":u}));t.elem&&(n.innerHTML=e||"",lay(t.elem).find("."+u).remove(),t.elem.appendChild(n),clearTimeout(t.hinTimer),t.hinTimer=setTimeout(function(){lay(t.elem).find("."+u).remove()},3e3))},g.prototype.getAsYM=function(e,t,n){return n?t--:t++,t<0&&(t=11,e--),t>11&&(t=0,e++),[e,t]},g.prototype.systemDate=function(e){var t=e||new Date;return{year:t.getFullYear(),month:t.getMonth(),date:t.getDate(),hours:e?e.getHours():0,minutes:e?e.getMinutes():0,seconds:e?e.getSeconds():0}},g.prototype.checkDate=function(e){var t,n,i=this,r=(new Date,i.config),l=i.lang(),o=r.dateTime=r.dateTime||i.systemDate(),s=i.bindElem||r.elem[0],y=(i.isInput(s)?"val":"html",i.isInput(s)?s.value:"static"===r.position?"":s.innerHTML),d=function(e){e.year>c[1]&&(e.year=c[1],n=!0),e.month>11&&(e.month=11,n=!0),e.hours>23&&(e.hours=0,n=!0),e.minutes>59&&(e.minutes=0,e.hours++,n=!0),e.seconds>59&&(e.seconds=0,e.minutes++,n=!0),t=a.getEndDate(e.month+1,e.year),e.date>t&&(e.date=t,n=!0)},u=function(e,t,a){var l=["startTime","endTime"];t=(t.match(i.EXP_SPLIT)||[]).slice(1),a=a||0,r.range&&(i[l[a]]=i[l[a]]||{}),lay.each(i.format,function(o,s){var y=parseFloat(t[o]);t[o].length'+n+""),a},g.prototype.limit=function(e,t,n,a){var i,r=this,l=r.config,o={},c=l[n>41?"endDate":"dateTime"],y=lay.extend({},c,t||{});return lay.each({now:y,min:l.min,max:l.max},function(e,t){o[e]=r.newDate(lay.extend({year:t.year,month:t.month,date:t.date},function(){var e={};return lay.each(a,function(n,a){e[a]=t[a]}),e}())).getTime()}),i=o.nowo.max,e&&e[i?"addClass":"removeClass"](s),i},g.prototype.thisDateTime=function(e){var t=this,n=t.config;return e?t.endDate:n.dateTime},g.prototype.calendar=function(e,t,n){var i,r,l,s=this,y=s.config,t=t?1:0,d=e||s.thisDateTime(t),u=new Date,m=s.lang(),f="date"!==y.type&&"datetime"!==y.type,p=lay(s.table[t]).find("td"),g=lay(s.elemHeader[t][2]).find("span");return d.yearc[1]&&(d.year=c[1],s.hint(m.invalidDate)),s.firstDate||(s.firstDate=lay.extend({},d)),u.setFullYear(d.year,d.month,1),i=u.getDay(),r=a.getEndDate(d.month||12,d.year),l=a.getEndDate(d.month+1,d.year),lay.each(p,function(e,t){var n=[d.year,d.month],a=0;t=lay(t),t.removeAttr("class"),e=i&&e=n.firstDate.year&&(r.month=a.max.month,r.date=a.max.date),n.limit(lay(i),r,t),x++}),lay(u[v?0:1]).attr("lay-ym",x-8+"-"+D[1]).html(M+T+" - "+(x-1+T))}else if("month"===e)lay.each(new Array(12),function(e){var i=lay.elem("li",{"lay-ym":e}),l={year:D[0],month:e};e+1==D[1]&&lay(i).addClass(o),i.innerHTML=r.month[e]+(v?"月":""),c.appendChild(i),D[0]=n.firstDate.year&&(l.date=a.max.date),n.limit(lay(i),l,t)}),lay(u[v?0:1]).attr("lay-ym",D[0]+"-"+D[1]).html(D[0]+T);else if("time"===e){var C=function(){lay(c).find("ol").each(function(e,a){lay(a).find("li").each(function(a,i){n.limit(lay(i),[{hours:a},{hours:n[b].hours,minutes:a},{hours:n[b].hours,minutes:n[b].minutes,seconds:a}][e],t,[["hours"],["hours","minutes"],["hours","minutes","seconds"]][e])})}),a.range||n.limit(lay(n.footer).find(h),n[b],0,["hours","minutes","seconds"])};a.range?n[b]||(n[b]={hours:0,minutes:0,seconds:0}):n[b]=i,lay.each([24,60,60],function(e,t){var a=lay.elem("li"),i=["

"+r.time[e]+"

    "];lay.each(new Array(t),function(t){i.push(""+lay.digit(t,2)+"")}),a.innerHTML=i.join("")+"
",c.appendChild(a)}),C()}if(g&&m.removeChild(g),m.appendChild(c),"year"===e||"month"===e)lay(n.elemMain[t]).addClass("laydate-ym-show"),lay(c).find("li").on("click",function(){var r=0|lay(this).attr("lay-ym");if(!lay(this).hasClass(s)){0===t?(i[e]=r,n.limit(lay(n.footer).find(h),null,0)):n.endDate[e]=r;var y="year"===a.type||"month"===a.type;y?(lay(c).find("."+o).removeClass(o),lay(this).addClass(o),"month"===a.type&&"year"===e&&(n.listYM[t][0]=r,l&&(t?i.year=r:n.endDate.year=r),n.list("month",t))):(n.checkDate("limit").calendar(null,t),n.closeList()),n.setBtnStatus(),a.range||(("month"===a.type&&"month"===e||"year"===a.type&&"year"===e)&&n.setValue(n.parse()).remove().done(),n.done(null,"change")),lay(n.footer).find(p).removeClass(s)}});else{var E=lay.elem("span",{"class":f}),k=function(){lay(c).find("ol").each(function(e){var t=this,a=lay(t).find("li");t.scrollTop=30*(n[b][w[e]]-2),t.scrollTop<=0&&a.each(function(e,n){if(!lay(this).hasClass(s))return t.scrollTop=30*(e-2),!0})})},S=lay(y[2]).find("."+f);k(),E.innerHTML=a.range?[r.startTime,r.endTime][t]:r.timeTips,lay(n.elemMain[t]).addClass("laydate-time-show"),S[0]&&S.remove(),y[2].appendChild(E),lay(c).find("ol").each(function(e){var t=this;lay(t).find("li").on("click",function(){var r=0|this.innerHTML;lay(this).hasClass(s)||(a.range?n[b][w[e]]=r:i[w[e]]=r,lay(t).find("."+o).removeClass(o),lay(this).addClass(o),C(),k(),(n.endDate||"time"===a.type)&&n.done(null,"change"),n.setBtnStatus())})})}return n},g.prototype.listYM=[],g.prototype.closeList=function(){var e=this;e.config;lay.each(e.elemCont,function(t,n){lay(this).find("."+d).remove(),lay(e.elemMain[t]).removeClass("laydate-ym-show laydate-time-show")}),lay(e.elem).find("."+f).remove()},g.prototype.setBtnStatus=function(e,t,n){var a,i=this,r=i.config,l=i.lang(),o=lay(i.footer).find(h);r.range&&"time"!==r.type&&(t=t||r.dateTime,n=n||i.endDate,a=i.newDate(t).getTime()>i.newDate(n).getTime(),i.limit(null,t)||i.limit(null,n)?o.addClass(s):o[a?"addClass":"removeClass"](s),e&&a&&i.hint("string"==typeof e?l.timeout.replace(/日期/g,e):l.timeout))},g.prototype.parse=function(e,t){var n=this,a=n.config,i=t||(e?lay.extend({},n.endDate,n.endTime):a.range?lay.extend({},a.dateTime,n.startTime):a.dateTime),r=n.format.concat();return lay.each(r,function(e,t){/yyyy|y/.test(t)?r[e]=lay.digit(i.year,t.length):/MM|M/.test(t)?r[e]=lay.digit(i.month+1,t.length):/dd|d/.test(t)?r[e]=lay.digit(i.date,t.length):/HH|H/.test(t)?r[e]=lay.digit(i.hours,t.length):/mm|m/.test(t)?r[e]=lay.digit(i.minutes,t.length):/ss|s/.test(t)&&(r[e]=lay.digit(i.seconds,t.length))}),a.range&&!e?r.join("")+" "+a.range+" "+n.parse(1):r.join("")},g.prototype.newDate=function(e){return e=e||{},new Date(e.year||1,e.month||0,e.date||1,e.hours||0,e.minutes||0,e.seconds||0)},g.prototype.setValue=function(e){var t=this,n=t.config,a=t.bindElem||n.elem[0],i=t.isInput(a)?"val":"html";return"static"===n.position||lay(a)[i](e||""),this},g.prototype.done=function(e,t){var n=this,a=n.config,i=lay.extend({},lay.extend(a.dateTime,n.startTime)),r=lay.extend({},lay.extend(n.endDate,n.endTime));return lay.each([i,r],function(e,t){"month"in t&&lay.extend(t,{month:t.month+1})}),e=e||[n.parse(),i,r],"function"==typeof a[t||"done"]&&a[t||"done"].apply(a,e),n},g.prototype.choose=function(e,t){var n=this,a=n.config,i=n.thisDateTime(t),r=(lay(n.elem).find("td"),e.attr("lay-ymd").split("-"));r={year:0|r[0],month:(0|r[1])-1,date:0|r[2]},e.hasClass(s)||(lay.extend(i,r),a.range?(lay.each(["startTime","endTime"],function(e,t){n[t]=n[t]||{hours:0,minutes:0,seconds:0}}),n.calendar(null,t)):"static"===a.position?n.calendar().done().done(null,"change"):"date"===a.type?n.setValue(n.parse()).remove().done():"datetime"===a.type&&n.calendar().done(null,"change"))},g.prototype.tool=function(e,t){var n=this,a=n.config,i=n.lang(),r=a.dateTime,l="static"===a.position,o={datetime:function(){lay(e).hasClass(s)||(n.list("time",0),a.range&&n.list("time",1),lay(e).attr("lay-type","date").html(n.lang().dateTips))},date:function(){n.closeList(),lay(e).attr("lay-type","datetime").html(n.lang().timeTips)},clear:function(){n.setValue("").remove(),l&&(lay.extend(r,n.firstDate),n.calendar()),a.range&&(delete n.endDate,delete n.startTime,delete n.endTime),n.done(["",{},{}])},now:function(){var e=new Date;lay.extend(r,n.systemDate(),{hours:e.getHours(),minutes:e.getMinutes(),seconds:e.getSeconds()}),n.setValue(n.parse()).remove(),l&&n.calendar(),n.done()},confirm:function(){if(a.range){if(lay(e).hasClass(s))return n.hint("time"===a.type?i.timeout.replace(/日期/g,"时间"):i.timeout)}else if(lay(e).hasClass(s))return n.hint(i.invalidDate);n.done(),n.setValue(n.parse()).remove()}};o[t]&&o[t]()},g.prototype.change=function(e){var t=this,n=t.config,a=t.thisDateTime(e),i=n.range&&("year"===n.type||"month"===n.type),r=t.elemCont[e||0],l=t.listYM[e],o=function(o){var s=lay(r).find(".laydate-year-list")[0],c=lay(r).find(".laydate-month-list")[0];return s&&(l[0]=o?l[0]-15:l[0]+15,t.list("year",e)),c&&(o?l[0]--:l[0]++,t.list("month",e)),(s||c)&&(lay.extend(a,{year:l[0]}),i&&(a.year=l[0]),n.range||t.done(null,"change"),n.range||t.limit(lay(t.footer).find(h),{year:l[0]})),t.setBtnStatus(),s||c};return{prevYear:function(){o("sub")||(a.year--,t.checkDate("limit").calendar(null,e),n.range||t.done(null,"change"))},prevMonth:function(){var i=t.getAsYM(a.year,a.month,"sub");lay.extend(a,{year:i[0],month:i[1]}),t.checkDate("limit").calendar(null,e),n.range||t.done(null,"change")},nextMonth:function(){var i=t.getAsYM(a.year,a.month);lay.extend(a,{year:i[0],month:i[1]}),t.checkDate("limit").calendar(null,e),n.range||t.done(null,"change")},nextYear:function(){o()||(a.year++,t.checkDate("limit").calendar(null,e),n.range||t.done(null,"change"))}}},g.prototype.changeEvent=function(){var e=this;e.config;lay(e.elem).on("click",function(e){lay.stope(e)}),lay.each(e.elemHeader,function(t,n){lay(n[0]).on("click",function(n){e.change(t).prevYear()}),lay(n[1]).on("click",function(n){e.change(t).prevMonth()}),lay(n[2]).find("span").on("click",function(n){var a=lay(this),i=a.attr("lay-ym"),r=a.attr("lay-type");i&&(i=i.split("-"),e.listYM[t]=[0|i[0],0|i[1]],e.list(r,t),lay(e.footer).find(p).addClass(s))}),lay(n[3]).on("click",function(n){e.change(t).nextMonth()}),lay(n[4]).on("click",function(n){e.change(t).nextYear()})}),lay.each(e.table,function(t,n){var a=lay(n).find("td");a.on("click",function(){e.choose(lay(this),t)})}),lay(e.footer).find("span").on("click",function(){var t=lay(this).attr("lay-type");e.tool(this,t)})},g.prototype.isInput=function(e){return/input|textarea/.test(e.tagName.toLocaleLowerCase())},g.prototype.events=function(){var t=this,n=t.config,a=function(e,a){e.on(n.trigger,function(){a&&(t.bindElem=this),t.render()})};n.elem[0]&&!n.elem[0].eventHandler&&(a(n.elem,"bind"),a(n.eventElem),lay(document).on("click",function(e){e.target!==n.elem[0]&&e.target!==n.eventElem[0]&&e.target!==lay(n.closeStop)[0]&&t.remove()}).on("keydown",function(e){13===e.keyCode&&lay("#"+t.elemID)[0]&&t.elemID===g.thisElemDate&&(e.preventDefault(),lay(t.footer).find(h)[0].click())}),lay(e).on("resize",function(){return!(!t.elem||!lay(l)[0])&&void t.position()}),n.elem[0].eventHandler=!0)},a.render=function(e){var t=new g(e);return i.call(t)},a.getEndDate=function(e,t){var n=new Date;return n.setFullYear(t||n.getFullYear(),e||n.getMonth()+1,1),new Date(n.getTime()-864e5).getDate()},t?(a.ready(),layui.define("lay",function(e){a.path=layui.cache.dir,e(r,a)})):"function"==typeof define&&define.amd?define(function(){return a}):function(){a.ready(),e.laydate=a}()}(window); \ No newline at end of file +/*! layDate v5.2.1 | 日期与时间组件 | The MIT License */ + ;!function(){"use strict";var e="lay",t=window.document,n=function(e){return new a(e)},a=function(e){for(var n=0,a="object"==typeof e?[e]:(this.selector=e,t.querySelectorAll(e||null));n0;i--)if("interactive"===n[i].readyState){e=n[i].src;break}return e||n[a].src}();return e.substring(0,e.lastIndexOf("/")+1)},n.stope=function(e){e=e||window.event,e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},n.each=function(e,t){var n,a=this;if("function"!=typeof t)return a;if(e=e||[],e.constructor===Object){for(n in e)if(t.call(e[n],n,e[n]))break}else for(n=0;n1e4/i?window.console&&console.error(o+".css: Invalid"):void(1989===parseInt(n.getStyle(r,"width"))?(e===y&&r.removeAttribute("lay-status"),r.getAttribute("lay-status")===y?setTimeout(d,i):a()):(r.setAttribute("lay-status",y),setTimeout(function(){d(y)},i)))}()},n.hasScrollbar=function(){return t.body.scrollHeight>(window.innerHeight||t.documentElement.clientHeight)},n.position=function(e,a,i){if(a){i=i||{},e!==t&&e!==n("body")[0]||(i.clickType="right");var r="right"===i.clickType?function(){var e=i.e||window.event||{};return{left:e.clientX,top:e.clientY,right:e.clientX,bottom:e.clientY}}():e.getBoundingClientRect(),l=a.offsetWidth,o=a.offsetHeight,s=function(e){return e=e?"scrollLeft":"scrollTop",t.body[e]|t.documentElement[e]},y=function(e){return t.documentElement[e?"clientWidth":"clientHeight"]},c=5,d=r.left,u=r.bottom;d+l+c>y("width")&&(d=y("width")-l-c),u+o+c>y()&&(r.top>o+c?u=r.top-o-2*c:"right"===i.clickType&&(u=y()-o-2*c,u<0&&(u=0)));var m=i.position;if(m&&(a.style.position=m),a.style.left=d+("fixed"===m?0:s(1))+"px",a.style.top=u+("fixed"===m?0:s())+"px",!n.hasScrollbar()){var h=a.getBoundingClientRect();!i.SYSTEM_RELOAD&&h.bottom+c>y()&&(i.SYSTEM_RELOAD=!0,setTimeout(function(){n.position(e,a,i)},50))}}},n.options=function(e,t){var a=n(e),i=t||"lay-options";try{return new Function("return "+(a.attr(i)||"{}"))()}catch(r){return hint.error("parseerror:"+r,"error"),{}}},n.isTopElem=function(e){var a=[t,n("body")[0]],i=!1;return n.each(a,function(t,n){if(n===e)return i=!0}),i},a.addStr=function(e,t){return e=e.replace(/\s+/," "),t=t.replace(/\s+/," ").split(" "),n.each(t,function(t,n){new RegExp("\\b"+n+"\\b").test(e)||(e=e+" "+n)}),e.replace(/^\s|\s$/,"")},a.removeStr=function(e,t){return e=e.replace(/\s+/," "),t=t.replace(/\s+/," ").split(" "),n.each(t,function(t,n){var a=new RegExp("\\b"+n+"\\b");a.test(e)&&(e=e.replace(a,""))}),e.replace(/\s+/," ").replace(/^\s|\s$/,"")},a.prototype.find=function(e){var t=this,a=0,i=[],r="object"==typeof e;return this.each(function(n,l){for(var o=r?[e]:l.querySelectorAll(e||null);a0)return a[0].style[e]}():a.each(function(a,r){"object"==typeof e?n.each(e,function(e,t){r.style[e]=i(t)}):r.style[e]=i(t)})},a.prototype.width=function(e){var t=this;return void 0===e?function(){if(t.length>0)return t[0].offsetWidth}():t.each(function(n,a){t.css("width",e)})},a.prototype.height=function(e){var t=this;return void 0===e?function(){if(t.length>0)return t[0].offsetHeight}():t.each(function(n,a){t.css("height",e)})},a.prototype.attr=function(e,t){var n=this;return void 0===t?function(){if(n.length>0)return n[0].getAttribute(e)}():n.each(function(n,a){a.setAttribute(e,t)})},a.prototype.removeAttr=function(e){return this.each(function(t,n){n.removeAttribute(e)})},a.prototype.html=function(e){var t=this;return void 0===e?function(){if(t.length>0)return t[0].innerHTML}():this.each(function(t,n){n.innerHTML=e})},a.prototype.val=function(e){return void 0===e?function(){if(that.length>0)return that[0].value}():this.each(function(t,n){n.value=e})},a.prototype.append=function(e){return this.each(function(t,n){"object"==typeof e?n.appendChild(e):n.innerHTML=n.innerHTML+e})},a.prototype.remove=function(e){return this.each(function(t,n){e?n.removeChild(e):n.parentNode.removeChild(n)})},a.prototype.on=function(e,t){return this.each(function(n,a){a.attachEvent?a.attachEvent("on"+e,function(e){e.target=e.srcElement,t.call(a,e)}):a.addEventListener(e,t,!1)})},a.prototype.off=function(e,t){return this.each(function(n,a){a.detachEvent?a.detachEvent("on"+e,t):a.removeEventListener(e,t,!1)})},window.lay=n,window.layui&&layui.define&&layui.define(function(t){t(e,n)})}(),!function(e){"use strict";var t=e.layui&&layui.define,n={getPath:e.lay&&lay.getPath?lay.getPath():"",link:function(t,n,i){a.path&&e.lay&&lay.link&&lay.link(a.path+t,n,i)}},a={v:"5.2.1",config:{},index:e.laydate&&e.laydate.v?1e5:0,path:n.getPath,set:function(e){var t=this;return t.config=lay.extend({},t.config,e),t},ready:function(e){var i="laydate",r="",l=(t?"modules/laydate/":"theme/")+"default/laydate.css?v="+a.v+r;return t?layui.addcss(l,e,i):n.link(l,e,i),this}},i=function(){var e=this;return{hint:function(t){e.hint.call(e,t)},config:e.config}},r="laydate",l=".layui-laydate",o="layui-this",s="laydate-disabled",y=[100,2e5],c="layui-laydate-static",d="layui-laydate-list",u="laydate-selected",m="layui-laydate-hint",h="layui-laydate-footer",f=".laydate-btns-confirm",p="laydate-time-text",g=".laydate-btns-time",v=function(e){var t=this;t.index=++a.index,t.config=lay.extend({},t.config,a.config,e),a.ready(function(){t.init()})};v.isLeapYear=function(e){return e%4===0&&e%100!==0||e%400===0},v.prototype.config={type:"date",range:!1,format:"yyyy-MM-dd",value:null,isInitValue:!0,min:"1900-1-1",max:"2099-12-31",trigger:"click",show:!1,showBottom:!0,btns:["clear","now","confirm"],lang:"cn",theme:"default",position:null,calendar:!1,mark:{},zIndex:null,done:null,change:null},v.prototype.lang=function(){var e=this,t=e.config,n={cn:{weeks:["日","一","二","三","四","五","六"],time:["时","分","秒"],timeTips:"选择时间",startTime:"开始时间",endTime:"结束时间",dateTips:"返回日期",month:["一","二","三","四","五","六","七","八","九","十","十一","十二"],tools:{confirm:"确定",clear:"清空",now:"现在"},timeout:"结束时间不能早于开始时间
请重新选择",invalidDate:"不在有效日期或时间范围内",formatError:["日期格式不合法
必须遵循下述格式:
","
已为你重置"]},en:{weeks:["Su","Mo","Tu","We","Th","Fr","Sa"],time:["Hours","Minutes","Seconds"],timeTips:"Select Time",startTime:"Start Time",endTime:"End Time",dateTips:"Select Date",month:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],tools:{confirm:"Confirm",clear:"Clear",now:"Now"},timeout:"End time cannot be less than start Time
Please re-select",invalidDate:"Invalid date",formatError:["The date format error
Must be followed:
","
It has been reset"]}};return n[t.lang]||n.cn},v.prototype.init=function(){var t=this,n=t.config,a="yyyy|y|MM|M|dd|d|HH|H|mm|m|ss|s",i="static"===n.position,r={year:"yyyy",month:"yyyy-MM",date:"yyyy-MM-dd",time:"HH:mm:ss",datetime:"yyyy-MM-dd HH:mm:ss"};n.elem=lay(n.elem),n.eventElem=lay(n.eventElem),n.elem[0]&&(n.range===!0&&(n.range="-"),r[n.type]||(e.console&&console.error&&console.error("laydate type error:'"+n.type+"' is not supported"),n.type="date"),n.format===r.date&&(n.format=r[n.type]||r.date),t.format=n.format.match(new RegExp(a+"|.","g"))||[],t.EXP_IF="",t.EXP_SPLIT="",lay.each(t.format,function(e,n){var i=new RegExp(a).test(n)?"\\d{"+function(){return new RegExp(a).test(t.format[0===e?e+1:e-1]||"")?/^yyyy|y$/.test(n)?4:n.length:/^yyyy$/.test(n)?"1,4":/^y$/.test(n)?"1,308":"1,2"}()+"}":"\\"+n;t.EXP_IF=t.EXP_IF+i,t.EXP_SPLIT=t.EXP_SPLIT+"("+i+")"}),t.EXP_IF=new RegExp("^"+(n.range?t.EXP_IF+"\\s\\"+n.range+"\\s"+t.EXP_IF:t.EXP_IF)+"$"),t.EXP_SPLIT=new RegExp("^"+t.EXP_SPLIT+"$",""),t.isInput(n.elem[0])||"focus"===n.trigger&&(n.trigger="click"),n.elem.attr("lay-key")||(n.elem.attr("lay-key",t.index),n.eventElem.attr("lay-key",t.index)),n.mark=lay.extend({},n.calendar&&"cn"===n.lang?{"0-1-1":"元旦","0-2-14":"情人","0-3-8":"妇女","0-3-12":"植树","0-4-1":"愚人","0-5-1":"劳动","0-5-4":"青年","0-6-1":"儿童","0-9-10":"教师","0-9-18":"国耻","0-10-1":"国庆","0-12-25":"圣诞"}:{},n.mark),lay.each(["min","max"],function(e,t){var a=[],i=[];if("number"==typeof n[t]){var r=n[t],l=(new Date).getTime(),o=864e5,s=new Date(r?r0)return!0;var a=lay.elem("div",{"class":"layui-laydate-header"}),i=[function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-prev-y"});return e.innerHTML="",e}(),function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-prev-m"});return e.innerHTML="",e}(),function(){var e=lay.elem("div",{"class":"laydate-set-ym"}),t=lay.elem("span"),n=lay.elem("span");return e.appendChild(t),e.appendChild(n),e}(),function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-next-m"});return e.innerHTML="",e}(),function(){var e=lay.elem("i",{"class":"layui-icon laydate-icon laydate-next-y"});return e.innerHTML="",e}()],y=lay.elem("div",{"class":"layui-laydate-content"}),c=lay.elem("table"),d=lay.elem("thead"),u=lay.elem("tr");lay.each(i,function(e,t){a.appendChild(t)}),d.appendChild(u),lay.each(new Array(6),function(e){var t=c.insertRow(0);lay.each(new Array(7),function(a){if(0===e){var i=lay.elem("th");i.innerHTML=n.weeks[a],u.appendChild(i)}t.insertCell(a)})}),c.insertBefore(d,c.children[0]),y.appendChild(c),r[e]=lay.elem("div",{"class":"layui-laydate-main laydate-main-list-"+e}),r[e].appendChild(a),r[e].appendChild(y),l.push(i),o.push(y),s.push(c)}),lay(y).html(function(){var e=[],i=[];return"datetime"===t.type&&e.push(''+n.timeTips+""),lay.each(t.btns,function(e,r){var l=n.tools[r]||"btn";t.range&&"now"===r||(a&&"clear"===r&&(l="cn"===t.lang?"重置":"Reset"),i.push(''+l+""))}),e.push('"),e.join("")}()),lay.each(r,function(e,t){i.appendChild(t)}),t.showBottom&&i.appendChild(y),/^#/.test(t.theme)){var d=lay.elem("style"),u=["#{{id}} .layui-laydate-header{background-color:{{theme}};}","#{{id}} .layui-this{background-color:{{theme}} !important;}"].join("").replace(/{{id}}/g,e.elemID).replace(/{{theme}}/g,t.theme);"styleSheet"in d?(d.setAttribute("type","text/css"),d.styleSheet.cssText=u):d.innerHTML=u,lay(i).addClass("laydate-theme-molv"),i.appendChild(d)}e.remove(v.thisElemDate),a?t.elem.append(i):(document.body.appendChild(i),e.position()),e.checkDate().calendar(null,0,"init"),e.changeEvent(),v.thisElemDate=e.elemID,"function"==typeof t.ready&&t.ready(lay.extend({},t.dateTime,{month:t.dateTime.month+1}))},v.prototype.remove=function(e){var t=this,n=(t.config,lay("#"+(e||t.elemID)));return n[0]?(n.hasClass(c)||t.checkDate(function(){n.remove(),delete t.endDate}),t):t},v.prototype.position=function(){var e=this,t=e.config;return lay.position(e.bindElem||t.elem[0],e.elem,{position:t.position}),e},v.prototype.hint=function(e){var t=this,n=(t.config,lay.elem("div",{"class":m}));t.elem&&(n.innerHTML=e||"",lay(t.elem).find("."+m).remove(),t.elem.appendChild(n),clearTimeout(t.hinTimer),t.hinTimer=setTimeout(function(){lay(t.elem).find("."+m).remove()},3e3))},v.prototype.getAsYM=function(e,t,n){return n?t--:t++,t<0&&(t=11,e--),t>11&&(t=0,e++),[e,t]},v.prototype.systemDate=function(e){var t=e||new Date;return{year:t.getFullYear(),month:t.getMonth(),date:t.getDate(),hours:e?e.getHours():0,minutes:e?e.getMinutes():0,seconds:e?e.getSeconds():0}},v.prototype.checkDate=function(e){var t,n,i=this,r=(new Date,i.config),l=i.lang(),o=r.dateTime=r.dateTime||i.systemDate(),s=i.bindElem||r.elem[0],c=(i.isInput(s)?"val":"html",i.isInput(s)?s.value:"static"===r.position?"":s.innerHTML),d=function(e){e.year>y[1]&&(e.year=y[1],n=!0),e.month>11&&(e.month=11,n=!0),e.hours>23&&(e.hours=0,n=!0),e.minutes>59&&(e.minutes=0,e.hours++,n=!0),e.seconds>59&&(e.seconds=0,e.minutes++,n=!0),t=a.getEndDate(e.month+1,e.year),e.date>t&&(e.date=t,n=!0)},u=function(e,t,a){var l=["startTime","endTime"];t=(t.match(i.EXP_SPLIT)||[]).slice(1),a=a||0,r.range&&(i[l[a]]=i[l[a]]||{}),lay.each(i.format,function(o,s){var c=parseFloat(t[o]);t[o].length'+n+""),a},v.prototype.limit=function(e,t,n,a){var i,r=this,l=r.config,o={},y=l[n>41?"endDate":"dateTime"],c=lay.extend({},y,t||{});return lay.each({now:c,min:l.min,max:l.max},function(e,t){o[e]=r.newDate(lay.extend({year:t.year,month:t.month,date:t.date},function(){var e={};return lay.each(a,function(n,a){e[a]=t[a]}),e}())).getTime()}),i=o.nowo.max,e&&e[i?"addClass":"removeClass"](s),i},v.prototype.thisDateTime=function(e){var t=this,n=t.config;return e?t.endDate:n.dateTime},v.prototype.calendar=function(e,t,n){var i,r,l,s=this,c=s.config,t=t?1:0,d=e||s.thisDateTime(t),u=new Date,m=s.lang(),h="date"!==c.type&&"datetime"!==c.type,p=lay(s.table[t]).find("td"),g=lay(s.elemHeader[t][2]).find("span");return d.yeary[1]&&(d.year=y[1],s.hint(m.invalidDate)),s.firstDate||(s.firstDate=lay.extend({},d)),u.setFullYear(d.year,d.month,1),i=u.getDay(),r=a.getEndDate(d.month||12,d.year),l=a.getEndDate(d.month+1,d.year),lay.each(p,function(e,t){var n=[d.year,d.month],a=0;t=lay(t),t.removeAttr("class"),e=i&&e=n.firstDate.year&&(r.month=a.max.month,r.date=a.max.date),n.limit(lay(i),r,t),x++}),lay(u[v?0:1]).attr("lay-ym",x-8+"-"+D[1]).html(C+T+" - "+(x-1+T))}else if("month"===e)lay.each(new Array(12),function(e){var i=lay.elem("li",{"lay-ym":e}),l={year:D[0],month:e};e+1==D[1]&&lay(i).addClass(o),i.innerHTML=r.month[e]+(v?"月":""),y.appendChild(i),D[0]=n.firstDate.year&&(l.date=a.max.date),n.limit(lay(i),l,t)}),lay(u[v?0:1]).attr("lay-ym",D[0]+"-"+D[1]).html(D[0]+T);else if("time"===e){var M=function(){lay(y).find("ol").each(function(e,a){lay(a).find("li").each(function(a,i){n.limit(lay(i),[{hours:a},{hours:n[b].hours,minutes:a},{hours:n[b].hours,minutes:n[b].minutes,seconds:a}][e],t,[["hours"],["hours","minutes"],["hours","minutes","seconds"]][e])})}),a.range||n.limit(lay(n.footer).find(f),n[b],0,["hours","minutes","seconds"])};a.range?n[b]||(n[b]={hours:0,minutes:0,seconds:0}):n[b]=i,lay.each([24,60,60],function(e,t){var a=lay.elem("li"),i=["

"+r.time[e]+"

    "];lay.each(new Array(t),function(t){i.push(""+lay.digit(t,2)+"")}),a.innerHTML=i.join("")+"
",y.appendChild(a)}),M()}if(h&&m.removeChild(h),m.appendChild(y),"year"===e||"month"===e)lay(n.elemMain[t]).addClass("laydate-ym-show"),lay(y).find("li").on("click",function(){var r=0|lay(this).attr("lay-ym");if(!lay(this).hasClass(s)){0===t?(i[e]=r,n.limit(lay(n.footer).find(f),null,0)):n.endDate[e]=r;var c="year"===a.type||"month"===a.type;c?(lay(y).find("."+o).removeClass(o),lay(this).addClass(o),"month"===a.type&&"year"===e&&(n.listYM[t][0]=r,l&&(t?i.year=r:n.endDate.year=r),n.list("month",t))):(n.checkDate("limit").calendar(null,t),n.closeList()),n.setBtnStatus(),a.range||(("month"===a.type&&"month"===e||"year"===a.type&&"year"===e)&&n.setValue(n.parse()).remove().done(),n.done(null,"change")),lay(n.footer).find(g).removeClass(s)}});else{var E=lay.elem("span",{"class":p}),k=function(){lay(y).find("ol").each(function(e){var t=this,a=lay(t).find("li");t.scrollTop=30*(n[b][w[e]]-2),t.scrollTop<=0&&a.each(function(e,n){if(!lay(this).hasClass(s))return t.scrollTop=30*(e-2),!0})})},S=lay(c[2]).find("."+p);k(),E.innerHTML=a.range?[r.startTime,r.endTime][t]:r.timeTips,lay(n.elemMain[t]).addClass("laydate-time-show"),S[0]&&S.remove(),c[2].appendChild(E),lay(y).find("ol").each(function(e){var t=this;lay(t).find("li").on("click",function(){var r=0|this.innerHTML;lay(this).hasClass(s)||(a.range?n[b][w[e]]=r:i[w[e]]=r,lay(t).find("."+o).removeClass(o),lay(this).addClass(o),M(),k(),(n.endDate||"time"===a.type)&&n.done(null,"change"),n.setBtnStatus())})})}return n},v.prototype.listYM=[],v.prototype.closeList=function(){var e=this;e.config;lay.each(e.elemCont,function(t,n){lay(this).find("."+d).remove(),lay(e.elemMain[t]).removeClass("laydate-ym-show laydate-time-show")}),lay(e.elem).find("."+p).remove()},v.prototype.setBtnStatus=function(e,t,n){var a,i=this,r=i.config,l=i.lang(),o=lay(i.footer).find(f);r.range&&"time"!==r.type&&(t=t||r.dateTime,n=n||i.endDate,a=i.newDate(t).getTime()>i.newDate(n).getTime(),i.limit(null,t)||i.limit(null,n)?o.addClass(s):o[a?"addClass":"removeClass"](s),e&&a&&i.hint("string"==typeof e?l.timeout.replace(/日期/g,e):l.timeout))},v.prototype.parse=function(e,t){var n=this,a=n.config,i=t||(e?lay.extend({},n.endDate,n.endTime):a.range?lay.extend({},a.dateTime,n.startTime):a.dateTime),r=n.format.concat();return lay.each(r,function(e,t){/yyyy|y/.test(t)?r[e]=lay.digit(i.year,t.length):/MM|M/.test(t)?r[e]=lay.digit(i.month+1,t.length):/dd|d/.test(t)?r[e]=lay.digit(i.date,t.length):/HH|H/.test(t)?r[e]=lay.digit(i.hours,t.length):/mm|m/.test(t)?r[e]=lay.digit(i.minutes,t.length):/ss|s/.test(t)&&(r[e]=lay.digit(i.seconds,t.length))}),a.range&&!e?r.join("")+" "+a.range+" "+n.parse(1):r.join("")},v.prototype.newDate=function(e){return e=e||{},new Date(e.year||1,e.month||0,e.date||1,e.hours||0,e.minutes||0,e.seconds||0)},v.prototype.setValue=function(e){var t=this,n=t.config,a=t.bindElem||n.elem[0],i=t.isInput(a)?"val":"html";return"static"===n.position||lay(a)[i](e||""),this},v.prototype.stampRange=function(e,t){var n,a,i=this,r=i.config;r.range&&(n=i.newDate(r.dateTime).getTime(),a=i.newDate(i.endDate).getTime(),lay.each(t,function(t,r){var l=lay(r).attr("lay-ymd").split("-"),o=i.newDate({year:l[0],month:l[1]-1,date:l[2]}).getTime();0==e?o>n&&lay(r).addClass(u):oli,.layui-laydate-range .layui-laydate-main{display:inline-block;vertical-align:middle}.layui-laydate-list{position:absolute;left:0;top:0;width:100%;height:100%;padding:10px;background-color:#fff}.layui-laydate-list>li{position:relative;width:33.3%;height:36px;line-height:36px;margin:3px 0;text-align:center;cursor:pointer}.laydate-month-list>li{width:25%;margin:17px 0}.laydate-time-list>li{height:100%;margin:0;line-height:normal;cursor:default}.laydate-time-list p{position:relative;top:-4px;line-height:29px}.laydate-time-list ol{height:181px;overflow:hidden}.laydate-time-list>li:hover ol{overflow-y:auto}.laydate-time-list ol li{width:130%;padding-left:33px;line-height:30px;text-align:left;cursor:pointer}.layui-laydate-hint{position:absolute;top:115px;left:50%;width:250px;margin-left:-125px;line-height:20px;padding:15px;text-align:center;font-size:12px}.layui-laydate-range{width:546px}.layui-laydate-range .laydate-main-list-1 .layui-laydate-content,.layui-laydate-range .laydate-main-list-1 .layui-laydate-header{border-left:1px solid #e2e2e2}.layui-laydate,.layui-laydate-hint{border:1px solid #d2d2d2;box-shadow:0 2px 4px rgba(0,0,0,.12);background-color:#fff;color:#666}.layui-laydate-header{border-bottom:1px solid #e2e2e2}.layui-laydate-header i:hover,.layui-laydate-header span:hover{color:#5FB878}.layui-laydate-content{border-top:none 0;border-bottom:none 0}.layui-laydate-content th{font-weight:400;color:#333}.layui-laydate-content td{color:#666}.layui-laydate-content td.laydate-selected{background-color:#00F7DE}.laydate-selected:hover{background-color:#00F7DE!important}.layui-laydate-content td:hover,.layui-laydate-list li:hover{background-color:#eaeaea;color:#333}.laydate-time-list li ol{margin:0;padding:0;border:1px solid #e2e2e2;border-left-width:0}.laydate-time-list li:first-child ol{border-left-width:1px}.laydate-time-list>li:hover{background:0 0}.layui-laydate-content .laydate-day-next,.layui-laydate-content .laydate-day-prev{color:#d2d2d2}.laydate-selected.laydate-day-next,.laydate-selected.laydate-day-prev{background-color:#f8f8f8!important}.layui-laydate-footer{border-top:1px solid #e2e2e2}.layui-laydate-hint{color:#FF5722}.laydate-day-mark::after{background-color:#5FB878}.layui-laydate-content td.layui-this .laydate-day-mark::after{display:none}.layui-laydate-footer span[lay-type=date]{color:#5FB878}.layui-laydate .layui-this{background-color:#009688!important;color:#fff!important}.layui-laydate .laydate-disabled,.layui-laydate .laydate-disabled:hover{background:0 0!important;color:#d2d2d2!important;cursor:not-allowed!important;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.laydate-theme-molv{border:none}.laydate-theme-molv.layui-laydate-range{width:548px}.laydate-theme-molv .layui-laydate-main{width:274px}.laydate-theme-molv .layui-laydate-header{border:none;background-color:#009688}.laydate-theme-molv .layui-laydate-header i,.laydate-theme-molv .layui-laydate-header span{color:#f6f6f6}.laydate-theme-molv .layui-laydate-header i:hover,.laydate-theme-molv .layui-laydate-header span:hover{color:#fff}.laydate-theme-molv .layui-laydate-content{border:1px solid #e2e2e2;border-top:none;border-bottom:none}.laydate-theme-molv .laydate-main-list-1 .layui-laydate-content{border-left:none}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li,.laydate-theme-grid .layui-laydate-content td,.laydate-theme-grid .layui-laydate-content thead,.laydate-theme-molv .layui-laydate-footer{border:1px solid #e2e2e2}.laydate-theme-grid .laydate-selected,.laydate-theme-grid .laydate-selected:hover{background-color:#f2f2f2!important;color:#009688!important}.laydate-theme-grid .laydate-selected.laydate-day-next,.laydate-theme-grid .laydate-selected.laydate-day-prev{color:#d2d2d2!important}.laydate-theme-grid .laydate-month-list,.laydate-theme-grid .laydate-year-list{margin:1px 0 0 1px}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li{margin:0 -1px -1px 0}.laydate-theme-grid .laydate-year-list>li{height:43px;line-height:43px}.laydate-theme-grid .laydate-month-list>li{height:71px;line-height:71px}@font-face{font-family:laydate-icon;src:url(font/iconfont.eot);src:url(font/iconfont.eot#iefix) format('embedded-opentype'),url(font/iconfont.svg#iconfont) format('svg'),url(font/iconfont.woff) format('woff'),url(font/iconfont.ttf) format('truetype')}.laydate-icon{font-family:laydate-icon!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale} \ No newline at end of file +.laydate-set-ym,.layui-laydate,.layui-laydate *,.layui-laydate-list{box-sizing:border-box}html #layuicss-laydate{display:none;position:absolute;width:1989px}.layui-laydate *{margin:0;padding:0}.layui-laydate{position:absolute;z-index:66666666;margin:5px 0;border-radius:2px;font-size:14px;-webkit-animation-duration:.2s;animation-duration:.2s;-webkit-animation-fill-mode:both;animation-fill-mode:both;animation-name:laydate-downbit}.layui-laydate-main{width:272px}.layui-laydate-content td,.layui-laydate-header *,.layui-laydate-list li{transition-duration:.3s;-webkit-transition-duration:.3s}@keyframes laydate-downbit{0%{opacity:.3;transform:translate3d(0,-5px,0)}100%{opacity:1;transform:translate3d(0,0,0)}}.layui-laydate-static{position:relative;z-index:0;display:inline-block;margin:0;-webkit-animation:none;animation:none}.laydate-ym-show .laydate-next-m,.laydate-ym-show .laydate-prev-m{display:none!important}.laydate-ym-show .laydate-next-y,.laydate-ym-show .laydate-prev-y{display:inline-block!important}.laydate-time-show .laydate-set-ym span[lay-type=month],.laydate-time-show .laydate-set-ym span[lay-type=year],.laydate-time-show .layui-laydate-header .layui-icon,.laydate-ym-show .laydate-set-ym span[lay-type=month]{display:none!important}.layui-laydate-header{position:relative;line-height:30px;padding:10px 70px 5px}.laydate-set-ym span,.layui-laydate-header i{padding:0 5px;cursor:pointer}.layui-laydate-header *{display:inline-block;vertical-align:bottom}.layui-laydate-header i{position:absolute;top:10px;color:#999;font-size:18px}.layui-laydate-header i.laydate-prev-y{left:15px}.layui-laydate-header i.laydate-prev-m{left:45px}.layui-laydate-header i.laydate-next-y{right:15px}.layui-laydate-header i.laydate-next-m{right:45px}.laydate-set-ym{width:100%;text-align:center;text-overflow:ellipsis;overflow:hidden;white-space:nowrap}.laydate-time-text{cursor:default!important}.layui-laydate-content{position:relative;padding:10px;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.layui-laydate-content table{border-collapse:collapse;border-spacing:0}.layui-laydate-content td,.layui-laydate-content th{width:36px;height:30px;padding:5px;text-align:center}.layui-laydate-content td{position:relative;cursor:pointer}.laydate-day-mark{position:absolute;left:0;top:0;width:100%;height:100%;line-height:30px;font-size:12px;overflow:hidden}.laydate-day-mark::after{position:absolute;content:'';right:2px;top:2px;width:5px;height:5px;border-radius:50%}.layui-laydate-footer{position:relative;height:46px;line-height:26px;padding:10px 20px}.layui-laydate-footer span{margin-right:15px;display:inline-block;cursor:pointer;font-size:12px}.layui-laydate-footer span:hover{color:#5FB878}.laydate-footer-btns{position:absolute;right:10px;top:10px}.laydate-footer-btns span{height:26px;line-height:26px;margin:0 0 0 -1px;padding:0 10px;border:1px solid #C9C9C9;background-color:#fff;white-space:nowrap;vertical-align:top;border-radius:2px}.layui-laydate-list>li,.layui-laydate-range .layui-laydate-main{display:inline-block;vertical-align:middle}.layui-laydate-list{position:absolute;left:0;top:0;width:100%;height:100%;padding:10px;background-color:#fff}.layui-laydate-list>li{position:relative;width:33.3%;height:36px;line-height:36px;margin:3px 0;text-align:center;cursor:pointer}.laydate-month-list>li{width:25%;margin:17px 0}.laydate-time-list>li{height:100%;margin:0;line-height:normal;cursor:default}.laydate-time-list p{position:relative;top:-4px;line-height:29px}.laydate-time-list ol{height:181px;overflow:hidden}.laydate-time-list>li:hover ol{overflow-y:auto}.laydate-time-list ol li{width:130%;padding-left:33px;line-height:30px;text-align:left;cursor:pointer}.layui-laydate-hint{position:absolute;top:115px;left:50%;width:250px;margin-left:-125px;line-height:20px;padding:15px;text-align:center;font-size:12px}.layui-laydate-range{width:546px}.layui-laydate-range .laydate-main-list-1 .layui-laydate-content,.layui-laydate-range .laydate-main-list-1 .layui-laydate-header{border-left:1px solid #e2e2e2}.layui-laydate,.layui-laydate-hint{border:1px solid #d2d2d2;box-shadow:0 2px 4px rgba(0,0,0,.12);background-color:#fff;color:#666}.layui-laydate-header{border-bottom:1px solid #e2e2e2}.layui-laydate-header i:hover,.layui-laydate-header span:hover{color:#5FB878}.layui-laydate-content{border-top:none 0;border-bottom:none 0}.layui-laydate-content th{font-weight:400;color:#333}.layui-laydate-content td{color:#666}.layui-laydate-content td.laydate-selected{background-color:#B5FFF8}.laydate-selected:hover{background-color:#00F7DE!important}.layui-laydate-content td:hover,.layui-laydate-list li:hover{background-color:#eee;color:#333}.laydate-time-list li ol{margin:0;padding:0;border:1px solid #e2e2e2;border-left-width:0}.laydate-time-list li:first-child ol{border-left-width:1px}.laydate-time-list>li:hover{background:0 0}.layui-laydate-content .laydate-day-next,.layui-laydate-content .laydate-day-prev{color:#d2d2d2}.laydate-selected.laydate-day-next,.laydate-selected.laydate-day-prev{background-color:#f8f8f8!important}.layui-laydate-footer{border-top:1px solid #e2e2e2}.layui-laydate-hint{color:#FF5722}.laydate-day-mark::after{background-color:#5FB878}.layui-laydate-content td.layui-this .laydate-day-mark::after{display:none}.layui-laydate-footer span[lay-type=date]{color:#5FB878}.layui-laydate .layui-this{background-color:#009688!important;color:#fff!important}.layui-laydate .laydate-disabled,.layui-laydate .laydate-disabled:hover{background:0 0!important;color:#d2d2d2!important;cursor:not-allowed!important;-moz-user-select:none;-webkit-user-select:none;-ms-user-select:none}.laydate-theme-molv{border:none}.laydate-theme-molv.layui-laydate-range{width:548px}.laydate-theme-molv .layui-laydate-main{width:274px}.laydate-theme-molv .layui-laydate-header{border:none;background-color:#009688}.laydate-theme-molv .layui-laydate-header i,.laydate-theme-molv .layui-laydate-header span{color:#f6f6f6}.laydate-theme-molv .layui-laydate-header i:hover,.laydate-theme-molv .layui-laydate-header span:hover{color:#fff}.laydate-theme-molv .layui-laydate-content{border:1px solid #e2e2e2;border-top:none;border-bottom:none}.laydate-theme-molv .laydate-main-list-1 .layui-laydate-content{border-left:none}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li,.laydate-theme-grid .layui-laydate-content td,.laydate-theme-grid .layui-laydate-content thead,.laydate-theme-molv .layui-laydate-footer{border:1px solid #e2e2e2}.laydate-theme-grid .laydate-selected,.laydate-theme-grid .laydate-selected:hover{background-color:#f2f2f2!important;color:#009688!important}.laydate-theme-grid .laydate-selected.laydate-day-next,.laydate-theme-grid .laydate-selected.laydate-day-prev{color:#d2d2d2!important}.laydate-theme-grid .laydate-month-list,.laydate-theme-grid .laydate-year-list{margin:1px 0 0 1px}.laydate-theme-grid .laydate-month-list>li,.laydate-theme-grid .laydate-year-list>li{margin:0 -1px -1px 0}.laydate-theme-grid .laydate-year-list>li{height:43px;line-height:43px}.laydate-theme-grid .laydate-month-list>li{height:71px;line-height:71px}@font-face{font-family:laydate-icon;src:url(font/iconfont.eot);src:url(font/iconfont.eot#iefix) format('embedded-opentype'),url(font/iconfont.svg#iconfont) format('svg'),url(font/iconfont.woff) format('woff'),url(font/iconfont.ttf) format('truetype')}.laydate-icon{font-family:laydate-icon!important;font-size:16px;font-style:normal;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale} \ No newline at end of file diff --git a/package.json b/package.json index 4a7747a..59749e9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "layui-laydate", "realname": "layDate", - "version": "5.2.0", + "version": "5.2.1", "description": "日期与时间组件", "main": "src/laydate.js", "license": "MIT", diff --git a/src/laydate.js b/src/laydate.js index 31c3112..88cd4f7 100644 --- a/src/laydate.js +++ b/src/laydate.js @@ -141,10 +141,17 @@ //载入 CSS 依赖 lay.link = function(href, fn, cssname){ - var head = document.getElementsByTagName("head")[0], link = document.createElement('link'); + var head = document.getElementsByTagName("head")[0] + ,link = document.createElement('link'); + if(typeof fn === 'string') cssname = fn; + var app = (cssname || href).replace(/\.|\//g, ''); - var id = 'layuicss-'+ app, timeout = 0; + var id = 'layuicss-'+ app + ,STAUTS_NAME = 'creating' + ,timeout = 0; + + link.rel = 'stylesheet'; link.href = href; @@ -153,15 +160,31 @@ if(!document.getElementById(id)){ head.appendChild(link); } - + if(typeof fn !== 'function') return; - - //轮询css是否加载完毕 - (function poll() { - if(++timeout > 8 * 1000 / 100){ - return window.console && console.error(app + '.css: Invalid'); + + //轮询 css 是否加载完毕 + (function poll(status) { + var delay = 100 + ,getLinkElem = document.getElementById(id); //获取动态插入的 link 元素 + + //如果轮询超过指定秒数,则视为请求文件失败或 css 文件不符合规范 + if(++timeout > 10 * 1000 / delay){ + return window.console && console.error(app +'.css: Invalid'); }; - parseInt(lay.getStyle(document.getElementById(id), 'width')) === 1989 ? fn() : setTimeout(poll, 100); + + //css 加载就绪 + if(parseInt(lay.getStyle(getLinkElem, 'width')) === 1989){ + //如果参数来自于初始轮询(即未加载就绪时的),则移除 link 标签状态 + if(status === STAUTS_NAME) getLinkElem.removeAttribute('lay-status'); + //如果 link 标签的状态仍为「创建中」,则继续进入轮询,直到状态改变,则执行回调 + getLinkElem.getAttribute('lay-status') === STAUTS_NAME ? setTimeout(poll, delay) : fn(); + } else { + getLinkElem.setAttribute('lay-status', STAUTS_NAME); + setTimeout(function(){ + poll(STAUTS_NAME); + }, delay); + } }()); }; @@ -398,16 +421,21 @@ }); }; - //设置HTML内容 + //设置或获取 HTML 内容 LAY.prototype.html = function(html){ - return this.each(function(index, item){ + var that = this; + return html === undefined ? function(){ + if(that.length > 0) return that[0].innerHTML; + }() : this.each(function(index, item){ item.innerHTML = html; }); }; - //设置值 + //设置或获取值 LAY.prototype.val = function(value){ - return this.each(function(index, item){ + return value === undefined ? function(){ + if(that.length > 0) return that[0].value; + }() : this.each(function(index, item){ item.value = value; }); }; @@ -481,7 +509,7 @@ } ,laydate = { - v: '5.2.0' + v: '5.2.1' ,config: {} //全局配置项 ,index: (window.laydate && window.laydate.v) ? 100000 : 0 ,path: ready.getPath @@ -1265,6 +1293,7 @@ //同步按钮可点状态 that.setBtnStatus(); + that.stampRange(index, tds); //标记范围内的日期 return that; }; @@ -1577,7 +1606,90 @@ return this; }; - //执行done/change回调 + //标记范围内的日期 + Class.prototype.stampRange = function(index, tds){ + var that = this + ,options = that.config + ,startTime, endTime; + + if(!options.range) return; + + startTime = that.newDate(options.dateTime).getTime(); + endTime = that.newDate(that.endDate).getTime(); + + //标记范围样式 + lay.each(tds, function(i, item){ + var ymd = lay(item).attr('lay-ymd').split('-') + ,thisTime = that.newDate({ + year: ymd[0] + ,month: ymd[1] - 1 + ,date: ymd[2] + }).getTime(); + + if(index == 0){ + if(thisTime > startTime){ + lay(item).addClass(ELEM_SELECTED); + } + } else { + if(thisTime < endTime){ + lay(item).addClass(ELEM_SELECTED); + } + } + + return; + if(thisTime === startTime || thisTime === endTime){ + lay(item).addClass( + lay(item).hasClass(ELEM_PREV) || lay(item).hasClass(ELEM_NEXT) + ? ELEM_SELECTED + : THIS + ); + } + if(thisTime > startTime && thisTime < endTime){ + lay(item).addClass(ELEM_SELECTED); + } + }); + + return; + + if(options.range && !that.endDate) lay(that.footer).find(ELEM_CONFIRM).addClass(DISABLED); + if(!that.endDate) return; + + startTime = that.newDate({ + year: that.startDate.year + ,month: that.startDate.month + ,date: that.startDate.date + }).getTime(); + + endTime = that.newDate({ + year: that.endDate.year + ,month: that.endDate.month + ,date: that.endDate.date + }).getTime(); + + if(startTime > endTime) return that.hint(TIPS_OUT); + + lay.each(tds, function(i, item){ + var ymd = lay(item).attr('lay-ymd').split('-') + ,thisTime = that.newDate({ + year: ymd[0] + ,month: ymd[1] - 1 + ,date: ymd[2] + }).getTime(); + lay(item).removeClass(ELEM_SELECTED + ' ' + THIS); + if(thisTime === startTime || thisTime === endTime){ + lay(item).addClass( + lay(item).hasClass(ELEM_PREV) || lay(item).hasClass(ELEM_NEXT) + ? ELEM_SELECTED + : THIS + ); + } + if(thisTime > startTime && thisTime < endTime){ + lay(item).addClass(ELEM_SELECTED); + } + }); + }; + + //执行 done/change 回调 Class.prototype.done = function(param, type){ var that = this ,options = that.config diff --git a/src/theme/default/laydate.css b/src/theme/default/laydate.css index 6fc9499..d6e8eef 100644 --- a/src/theme/default/laydate.css +++ b/src/theme/default/laydate.css @@ -98,10 +98,10 @@ html #layuicss-laydate{display: none; position: absolute; width: 1989px;} .layui-laydate-content{border-top: none 0; border-bottom: none 0;} .layui-laydate-content th{color: #333;} .layui-laydate-content td{color: #666;} -.layui-laydate-content td.laydate-selected{background-color: #00F7DE;} +.layui-laydate-content td.laydate-selected{background-color: #B5FFF8;} .laydate-selected:hover{background-color: #00F7DE !important;} .layui-laydate-content td:hover, -.layui-laydate-list li:hover{background-color: #eaeaea; color: #333;} +.layui-laydate-list li:hover{background-color: #eee; color: #333;} .laydate-time-list li ol{margin: 0; padding: 0; border: 1px solid #e2e2e2; border-left-width: 0;} .laydate-time-list li:first-child ol{border-left-width: 1px;} .laydate-time-list>li:hover{background: none;}