/**
|
* 封装layer.js的常用方法
|
*/
|
layui.use(['layer'], function () {
|
var layer = layui.layer,
|
$ = layui.$;
|
layer.oriMsg = layer.msg;
|
layer.msg = function (msg, timeSecond, icon, callback) {
|
timeSecond = (typeof timeSecond !== 'undefined') ? timeSecond : 1.5;
|
icon = (typeof icon !== 'undefined') ? icon : 6;
|
callback = (typeof callback !== 'undefined') ? callback : function () { };
|
|
//兼容原本layui.use(['layer'])的layer.msg()用法
|
if (typeof (timeSecond) == 'object') {
|
if (typeof (icon) == 'function') {
|
return layer.oriMsg(msg, timeSecond, icon);
|
} else {
|
return layer.oriMsg(msg, timeSecond);
|
}
|
}
|
|
var tm = timeSecond * 1000;
|
if (icon == 8) {
|
icon = 2;
|
}
|
if (icon == 9) {
|
icon = 1;
|
}
|
console.log(icon);
|
return layer.msg(msg,
|
{
|
time: tm,
|
icon: icon,
|
shade: [0.8, '#393D49'] //加过滤层黑色透明背景
|
},
|
function () {
|
callback();
|
}
|
);
|
};//end layer.msg
|
|
//加载动画加遮罩层
|
layer.oriLoad = layer.load;
|
layer.load = function (icon, options) {
|
icon = (typeof icon !== 'undefined') ? icon : 0;
|
options = (typeof options == 'object') ? options : {};
|
|
options.shade = [0.8, '#393D49'];
|
return layer.oriLoad(icon, options);
|
};
|
|
//alert对话框
|
layer.oriAlert = layer.alert;
|
layer.alert = function (msg, icon, title, callback) {
|
if (typeof icon == 'object') {
|
//layui的layer模块原本调用方式
|
if (typeof title == 'function') {
|
return layer.oriAlert(msg, icon, title);
|
} else {
|
return layer.oriAlert(msg, icon);
|
}
|
} else if (typeof icon != 'undefined' && typeof title == 'undefined') {
|
//兼容layer.min.js的调用方式
|
return layer.msg(msg, 1.5, icon);
|
} else if (typeof callback == 'function') {
|
return layer.oriAlert(msg, { title: title }, callback);
|
} else {
|
return layer.oriAlert(msg);
|
}
|
}
|
|
/**
|
* 【页面层(和父窗口属于同一个html页面)】 封装layer.open({type:1})
|
*
|
* content : 展示的内容 : html代码(字符串),dom节点(例如:$("#id") )
|
* area : ['300px', '200px']
|
* offset : ['100px', '50px'] , 'auto', 'r' 等
|
* options : {} 其他layui文档中的参数
|
*/
|
// layer.page = function (content, title, area, offset = 'auto', options = {}){
|
layer.page = function (content, title, area, offset, options) {
|
offset = (typeof offset !== 'undefined') ? offset : 'auto';
|
options = (typeof options !== 'undefined') ? options : {};
|
|
options.type = 1;
|
options.content = content;
|
options.area = area;
|
options.offset = offset;
|
options.title = title;
|
|
return layer.open(options);
|
};
|
|
//封装layer.open({type:2})【iframe页面层】
|
// layer.iframe = function (url, title, area, offset = 'auto', options = {}){
|
layer.iframe = function (url, title, area, offset, options) {//浏览器兼容写法
|
offset = (typeof offset !== 'undefined') ? offset : 'auto';
|
options = (typeof options !== 'undefined') ? options : {};
|
|
options.type = 2;
|
options.content = url;
|
options.area = area;
|
options.offset = offset;
|
options.title = title;
|
|
return layer.open(options);
|
};
|
});//end layui.use()
|
|
function monthclick(laydate, elem, hasdone) {
|
var timestamp = new Date();
|
nowyear = timestamp.getFullYear(),
|
nowmonth = timestamp.getMonth() + 1;
|
if (nowmonth < 10) {
|
nowmonth = "0" + nowmonth;
|
}
|
nowday = timestamp.getDate();
|
var max = '';
|
if (elem == '#eduedate' || elem.indexOf("#edu_edate") >= 0) {
|
max = '2099-12-30';
|
} else {
|
max = nowyear + '-' + nowmonth + '-' + nowday;
|
}
|
laydateobj =
|
laydate.render({
|
elem: elem,
|
type: 'month',
|
trigger: 'click',
|
max: max,
|
change: function (value, date, endDate) {
|
var nowtimestr = nowyear + '-' + nowmonth;
|
var oldVal = $(elem).val();
|
if (nowtimestr >= value) {
|
$(elem).val(value);
|
} else {
|
$(elem).val(nowtimestr);
|
}
|
if (oldVal.substr(0, 4) == value.substr(0, 4) || nowyear == value.substr(0, 4)) {
|
$('.laydate-btns-confirm').click();
|
}
|
},
|
done: function (value, date, endDate) {
|
if (hasdone == 1) {
|
var id = elem.replace('#', '');
|
//checkonblur(id);
|
}
|
}
|
});
|
}
|
if (typeof ($) !== 'undefined') {
|
$.layer = function (obj) {
|
var retval;
|
layui.use(['layer'], function () {
|
var layer = layui.layer,
|
$ = layui.$;
|
|
var offset = 'auto';
|
if (obj.offset) {
|
offset = obj.offset;
|
}
|
|
var content = '';
|
if (obj.page) {
|
if (obj.page.dom) {
|
content = $(obj.page.dom);
|
} else if (obj.page.html) {
|
content = obj.page.html;
|
}
|
} else if (obj.iframe) {
|
if (obj.iframe.src) {
|
content = obj.iframe.src;
|
}
|
}
|
|
var id = obj.id ? obj.id : '';
|
|
var close = obj.close ? obj.close : function () { };
|
var laydata = {
|
content: content,
|
offset: offset,
|
id: id,
|
end: close
|
};
|
if (obj.type) {
|
laydata.type = obj.type;
|
}
|
if (obj.title) {
|
laydata.title = obj.title;
|
}
|
if (obj.area) {
|
laydata.area = obj.area;
|
}
|
if (obj.zIndex) {
|
laydata.zIndex = obj.zIndex;
|
}
|
if (obj.success) {
|
laydata.success = obj.success;
|
}
|
retval = layer.open(laydata);
|
});//
|
|
return retval;
|
};//end $.layer
|
}
|