You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
291 lines
11 KiB
291 lines
11 KiB
/** layui-v2.5.6 MIT License By https://www.layui.com */
|
|
;!function(){"use strict";
|
|
var e=window.layui&&layui.define, // 定义 layui 和 layui.define 模块
|
|
t={
|
|
// 获取当前脚本路径
|
|
getPath:function(){
|
|
var e=document.currentScript?document.currentScript.src:function(){
|
|
for(var e,t=document.scripts,n=t.length-1,a=n;a>0;a--)
|
|
if("interactive"===t[a].readyState){
|
|
e=t[a].src;
|
|
break
|
|
}
|
|
return e||t[n].src
|
|
}();
|
|
return e.substring(0,e.lastIndexOf("/")+1) // 返回当前脚本所在的路径
|
|
}(),
|
|
|
|
// 获取指定元素的样式
|
|
getStyle:function(e,t){
|
|
var n=e.currentStyle?e.currentStyle:window.getComputedStyle(e,null);
|
|
return n[n.getPropertyValue?"getPropertyValue":"getAttribute"](t)
|
|
},
|
|
|
|
// 动态加载 CSS 样式表
|
|
link:function(e,a,i){
|
|
if(n.path){
|
|
var r=document.getElementsByTagName("head")[0],
|
|
o=document.createElement("link");
|
|
"string"==typeof a&&(i=a); // 如果 a 是字符串,则将 i 设置为 a
|
|
var s=(i||e).replace(/\.|\//g,""),
|
|
l="layuicss-"+s,d=0;
|
|
o.rel="stylesheet",
|
|
o.href=n.path+e,
|
|
o.id=l,
|
|
document.getElementById(l)||r.appendChild(o),
|
|
|
|
// 加载后调用回调函数
|
|
"function"==typeof a&&!function c(){
|
|
return++d>80?window.console&&console.error("laydate.css: Invalid"):void(1989===parseInt(t.getStyle(document.getElementById(l),"width"))?a():setTimeout(c,100))
|
|
}()
|
|
}
|
|
}
|
|
},
|
|
|
|
// 版本和配置初始化
|
|
n={
|
|
v:"5.0.9",
|
|
config:{},
|
|
index:window.laydate&&window.laydate.v?1e5:0,
|
|
path:t.getPath,
|
|
|
|
// 设置配置项
|
|
set:function(e){
|
|
var t=this;
|
|
return t.config=w.extend({},t.config,e),t
|
|
},
|
|
|
|
// 加载资源后,执行初始化
|
|
ready:function(a){
|
|
var i="laydate",
|
|
r="",
|
|
o=(e?"modules/laydate/":"theme/")+"default/laydate.css?v="+n.v+r;
|
|
return e?layui.addcss(o,a,i):t.link(o,a,i),this
|
|
}
|
|
},
|
|
|
|
// 组件对象初始化
|
|
a=function(){
|
|
var e=this;
|
|
return{
|
|
hint:function(t){
|
|
e.hint.call(e,t)
|
|
},
|
|
config:e.config
|
|
}
|
|
},
|
|
|
|
i="laydate",
|
|
r=".layui-laydate",
|
|
o="layui-this",
|
|
s="laydate-disabled",
|
|
l="开始日期超出了结束日期<br>建议重新选择",
|
|
d=[100,2e5],
|
|
c="layui-laydate-static",
|
|
m="layui-laydate-list",
|
|
u="laydate-selected",
|
|
h="layui-laydate-hint",
|
|
y="laydate-day-prev",
|
|
f="laydate-day-next",
|
|
p="layui-laydate-footer",
|
|
g=".laydate-btns-confirm",
|
|
v="laydate-time-text",
|
|
D=".laydate-btns-time",
|
|
|
|
// 初始化函数
|
|
T=function(e){
|
|
var t=this;
|
|
t.index=++n.index,
|
|
t.config=w.extend({},t.config,n.config,e),
|
|
n.ready(function(){
|
|
t.init()
|
|
})
|
|
},
|
|
|
|
// 工具函数,返回元素对象
|
|
w=function(e){
|
|
return new C(e)
|
|
},
|
|
|
|
// C 构造函数,操作 DOM 元素
|
|
C=function(e){
|
|
for(var t=0,n="object"==typeof e?[e]:(this.selector=e,document.querySelectorAll(e||null));t<n.length;t++)
|
|
this.push(n[t])
|
|
};
|
|
|
|
C.prototype=[], C.prototype.constructor=C,
|
|
|
|
// 扩展方法
|
|
w.extend=function(){
|
|
var e=1,t=arguments,n=function(e,t){
|
|
e=e||(t.constructor===Array?[]:{});
|
|
for(var a in t)e[a]=t[a]&&t[a].constructor===Object?n(e[a],t[a]):t[a];
|
|
return e
|
|
};
|
|
for(t[0]="object"==typeof t[0]?t[0]:{};e<t.length;e++)"object"==typeof t[e]&&n(t[0],t[e]);
|
|
return t[0]
|
|
},
|
|
|
|
// 判断是否为 IE 浏览器
|
|
w.ie=function(){
|
|
var e=navigator.userAgent.toLowerCase();
|
|
return!!(window.ActiveXObject||"ActiveXObject"in window)&&((e.match(/msie\s(\d+)/)||[])[1]||"11")
|
|
},
|
|
|
|
// 阻止事件冒泡
|
|
w.stope=function(e){
|
|
e=e||window.event,e.stopPropagation?e.stopPropagation():e.cancelBubble=!0
|
|
},
|
|
|
|
// 遍历集合
|
|
w.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;n<e.length&&!t.call(e[n],n,e[n]);n++);
|
|
return a
|
|
},
|
|
|
|
// 格式化数字,补充零
|
|
w.digit=function(e,t,n){
|
|
var a="";
|
|
e=String(e),t=t||2;
|
|
for(var i=e.length;i<t;i++)a+="0";
|
|
return e<Math.pow(10,t)?a+(0|e):e
|
|
},
|
|
|
|
// 创建 DOM 元素
|
|
w.elem=function(e,t){
|
|
var n=document.createElement(e);
|
|
return w.each(t||{},function(e,t){
|
|
n.setAttribute(e,t)
|
|
}),n
|
|
},
|
|
|
|
// 在字符串中添加类名
|
|
C.addStr=function(e,t){
|
|
return e=e.replace(/\s+/," "),t=t.replace(/\s+/," ").split(" "),w.each(t,function(t,n){
|
|
new RegExp("\\b"+n+"\\b").test(e)||(e=e+" "+n)
|
|
}),e.replace(/^\s|\s$/,"")
|
|
},
|
|
|
|
// 移除字符串中的类名
|
|
C.removeStr=function(e,t){
|
|
return e=e.replace(/\s+/," "),t=t.replace(/\s+/," ").split(" "),w.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$/,"")
|
|
},
|
|
|
|
// 查找子元素
|
|
C.prototype.find=function(e){
|
|
var t=this,n=0,a=[],i="object"==typeof e;
|
|
return this.each(function(r,o){
|
|
for(var s=i?[e]:o.querySelectorAll(e||null);n<s.length;n++)a.push(s[n]);
|
|
t.shift()
|
|
}),i||(t.selector=(t.selector?t.selector+" ":"")+e),w.each(a,function(e,n){
|
|
t.push(n)
|
|
}),t
|
|
},
|
|
|
|
// 遍历操作
|
|
C.prototype.each=function(e){
|
|
return w.each.call(this,this,e)
|
|
},
|
|
|
|
// 添加类名
|
|
C.prototype.addClass=function(e,t){
|
|
return this.each(function(n,a){
|
|
a.className=C[t?"removeStr":"addStr"](a.className,e)
|
|
})
|
|
},
|
|
|
|
// 移除类名
|
|
C.prototype.removeClass=function(e){
|
|
return this.addClass(e,!0)
|
|
},
|
|
|
|
// 判断是否包含某个类
|
|
C.prototype.hasClass=function(e){
|
|
var t=!1;
|
|
return this.each(function(n,a){
|
|
new RegExp("\\b"+e+"\\b").test(a.className)&&(t=!0)
|
|
}),t
|
|
},
|
|
|
|
// 获取或设置属性
|
|
C.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)
|
|
})
|
|
},
|
|
|
|
// 移除属性
|
|
C.prototype.removeAttr=function(e){
|
|
return this.each(function(t,n){
|
|
n.removeAttribute(e)
|
|
})
|
|
},
|
|
|
|
// 设置 HTML 内容
|
|
C.prototype.html=function(e){
|
|
return this.each(function(t,n){
|
|
n.innerHTML=e
|
|
})
|
|
},
|
|
|
|
// 设置或获取输入框的值
|
|
T.prototype.render=function(e){ // 渲染日期选择器
|
|
var t=this,n=(t.config,w("#"+t.elemID)),a=n.hasClass("laydate-footer"),i=n.find("td"),r=n.find("ul"); // 获取配置和HTML元素
|
|
if(!t.config.range||a){ // 如果是日期范围选择或者没有日期范围
|
|
if(!a){ // 如果没有footer元素
|
|
t.elemFooter&&(t.elemFooter.style.display="none"); // 隐藏footer
|
|
}else{ // 如果有footer元素
|
|
r.css("display","block"); // 显示时间列表
|
|
}
|
|
}
|
|
t.dateTime={year:e.year,month:e.month,date:e.date,hours:e.hours,minutes:e.minutes,seconds:e.seconds}; // 更新日期时间
|
|
t.renderList(e); // 渲染日期列表
|
|
},
|
|
T.prototype.renderList=function(e){ // 渲染日期列表
|
|
var t=this,n=(t.config,w("#"+t.elemID)),a=n.find("td");
|
|
w.each(a,function(t,a){ // 遍历每个单元格
|
|
var i=w(a),r=i.attr("lay-ymd").split("-"),s=n.newDate({year:r[0],month:r[1]-1,date:r[2]}).getTime(); // 获取每个日期的时间戳
|
|
if(s===t.dateTime.getTime())i.addClass("laydate-day-selected"); // 如果日期匹配,添加选中样式
|
|
else i.removeClass("laydate-day-selected"); // 否则移除选中样式
|
|
});
|
|
},
|
|
T.prototype.position=function(){ // 计算并设置日期选择器的位置
|
|
var e=this,t=e.config,n=e.bindElem||t.elem[0],a=n.getBoundingClientRect(),i=e.elem.offsetWidth,r=e.elem.offsetHeight;
|
|
var o=function(e){ // 获取滚动位置
|
|
return e=e?"scrollLeft":"scrollTop",document.body[e]|document.documentElement[e];
|
|
};
|
|
var s=function(e){ // 获取窗口大小
|
|
return document.documentElement[e?"clientWidth":"clientHeight"];
|
|
};
|
|
var l=5,d=a.left,c=a.bottom; // 设置偏移量
|
|
d+i+l>s("width")&&(d=s("width")-i-l); // 如果超出窗口宽度,调整位置
|
|
c+r+l>s()&&(c=a.top>r?a.top-r:s()-r,c-=2*l); // 如果超出窗口高度,调整位置
|
|
t.position&&(e.elem.style.position=t.position); // 如果有指定位置类型,设置位置类型
|
|
e.elem.style.left=d+("fixed"===t.position?0:o(1))+"px"; // 设置左边距
|
|
e.elem.style.top=c+("fixed"===t.position?0:o())+"px"; // 设置顶部边距
|
|
},
|
|
T.prototype.checkDate=function(e){ // 检查日期是否合法
|
|
var t=this,n=(t.config,w("#"+t.elemID));
|
|
// 判断日期范围
|
|
var i=t.dateTime=e.dateTime||new Date();
|
|
var r=t.bindElem||n[0];
|
|
var o=function(e){ // 日期合法性检查
|
|
if(e.year>d[1]){ // 如果年份超过最大年份
|
|
e.year=d[1];
|
|
a=!0;
|
|
}
|
|
};
|
|
// 校验并返回检查结果
|
|
},
|