//MSG:内容,ICON:1(正确)0(警告)2(错误) function LayerMsg(msg,icon,offset){ if(typeof msg === 'object' && msg !== null){ //对象才进行转换 变成空的 免得报错 msg = JSON.stringify(msg); } layer.open({ skin: "error-warn-class", content:msg, icon: icon, offset:offset == undefined ? "10%":offset, //定位弹出位置(距离body顶部10px) success:function (layero,index) { $("input").blur(); indexLyaerMsg = index; } }); } //input表格编辑提示 function LayerInputMsg(msg,icon,date){ if(Object.prototype.toString.call(msg)){ msg = JSON.stringify(msg); } layer.open({ skin: "error-warn-class", content:msg, icon: icon, end : function(){ $(date).css("border","solid 1px #FF0000"); $(date).find("input").focus(); } }); } /** 支持回调的msg方法 */ function LayerMsgAndCallback(msg,icon,offset,callback){ if(Object.prototype.toString.call(msg)){ msg = JSON.stringify(msg); } layer.open({ skin: "error-warn-class", content:msg, icon: icon, offset:offset == undefined ? "10%":offset, //定位弹出位置(距离body顶部10px) success:function (layero,index) { $("input").blur(); indexLyaerMsg = index; } , end: function () { if (typeof callback === 'function') { callback(); } } }); } //直接输出原始内容 不进行加工 function LayerMsgInit(msg,icon,offset){ if(Object.prototype.toString.call(msg)){ msg = JSON.stringify(msg); } layer.open({ skin: "error-warn-class", content:msg, icon: icon, offset:offset == undefined ? "10%":offset, //定位弹出位置(距离body顶部10px) success:function (layero,index) { $("input").blur(); indexLyaerMsg = index; } }); } /** * 封装layer弹出层方法 */ var wnMessage = (function () { var model = {}; /**************************start 基础(普通)消息提示*******************************/ /** * 基础成功提示 * @param msg 提示信息 */ model.baseSuccess = function (msg) { layer.msg(msg,{icon: 1}); } /** * 基础成功提示 * @param msg 提示信息 */ model.baseError = function (msg) { layer.msg(msg,{icon: 2}); } /** * 基础成功提示 * @param msg 提示信息 */ model.baseWarning = function (msg) { layer.msg(msg,{icon: 0}); } /**************************end 基础(普通)消息提示*******************************/ /**************************start 右上角消息提示(可关闭)*******************************/ /** * 右上角消息提示成功(可关闭) * @param msg 提示信息 * @param timeout 超时时间(毫秒) */ model.success =function (msg,timeout) { messageTip(msg,1,timeout); } /** * 右上角消息提示错误(可关闭) * @param msg 提示信息 * @param timeout 超时时间(毫秒) */ model.error = function (msg,timeout) { messageTip(msg,2,timeout); } /** * 右上角消息提示警告(可关闭) * @param msg 提示信息 * @param timeout 超时时间(毫秒) */ model.warning = function (msg,timeout) { messageTip(msg,0,timeout); } /** * 消息提示 * @param msg 提示信息 * @param icon 图标 1:成功,0:警告,2:错误 * @param timeout 超时时间(毫秒) */ function messageTip(msg,icon,timeout) { var options = { title: "", message: msg, position: 'topRight', timeout: timeout ? timeout : 5000, transitionIn: 'flipInX', transitionOut: 'flipOutX' } switch (icon) { case 0: // 警告 iziToast.warning(options); break; case 1: // 成功 iziToast.success(options); break; case 2: // 错误 iziToast.error(options); break; } } /**************************end 右上角消息提示(可关闭)*******************************/ /**************************start 弹出框消息*******************************/ /** * 弹出框成功 * @param msg 提示 * @param callback 回调函数 */ model.alertSuccess = function (msg, callback) { wnLayerMsg(msg, 1, callback); }; /** * 弹出框错误 * @param msg 提示 * @param callback 回调函数 */ model.alertError = function (msg, callback) { wnLayerMsg(msg, 2, callback); }; /** * 弹出框警告 * @param msg 提示 * @param callback 回调函数 */ model.alertWarning = function (msg, callback) { wnLayerMsg(msg, '0', callback); }; /** * 弹出层方法 * @param msg 信息 * @param icon 图标 1:成功,0:警告,2:错误 * @param callback 回调函数 * @param noBtn 是否不显示按钮 */ function wnLayerMsg(msg,icon,callback) { layer.open({ skin: "error-warn-class", title: "按【esc】关闭", content: msg, icon: icon ? icon - 0 : 2, offset: '35%', btn:[], end: function (index) { callback && callback(); layer.close(index); } }); } /**************************end 弹出框消息*******************************/ /**************************start 其他类型消息提示*******************************/ /** * 询问框 * @param msg 询问信息 * @param confirm 确认回调函数 * @param cancel 取消回调函数 * @param btn 自定义按钮 */ model.confirm = function (msg, confirm, cancel,btn) { layer.confirm(msg, { skin: 'layui-layer-lan' ,title: "按【esc】关闭" , btn: btn?btn:['确定', '取消'] , btn1: function (index) { confirm && confirm(); layer.close(index); }, btn2: function (index) { cancel && cancel(); layer.close(index); } }); } /**************************end 其他类型消息提示*******************************/ return model; })();