//layui 弹出页面 function showlayerwin(t, url, w, h, f, r) { if (!w) { w = 800; } if (!h) { h = ($(window).height() - 50); } if (!t.includes('<')) { t = title(t) } layui.use('layer', function () { var index = layui.layer.open({ type: 2, area: [w + 'px', h + 'px'], fixed: false, shade: 0.4, title: t, content: url, end: function () { if (r == 1 && typeof (reload) === 'function') { reload(); } else if (r == 2) { window.location.reload(); } else if (typeof (r) === 'function') { r(); } } }); if (f) layui.layer.full(index); }); } //layui 弹出顶级页面 function showlayertopwin(t, url, w, h, f, r) { if (!w) { w = ($(window).width() - 340); } if (!h) { h = ($(window).height() - 170); } if (!t.includes('<')) { t = title(t) } top.layui.use('layer', function () { let index = top.layui.layer.open({ type: 2, area: [w + 'px', h + 'px'], fixed: 1, maxmin: t ? 1 : 0, resize: t ? 1 : 0, closebtn: t ? 1 : 0, offset: [(f ? '20px' : ($(window).height() - h) / 2 + 50), (f ? '20px' : ($(window).width() - w) / 2 + 80)], title: t, content: url, /* restore: function (layero) { layero.find('.layui-layer-max').hide(); //还原时隐藏最大化按钮 },*/ end: function () { if (r == 1 && typeof (reload) === 'function') { reload(); } else if (r == 2) { window.location.reload(); } else if (typeof (r) === 'function') { r(); } } }); if (f) top.layui.layer.full(index); }); } //layui 弹出顶级页面 function showlayertopwin1(t, url, w, h, f, r) { if (!w) { w = 60; } if (!h) { h = 80; } if (!t.includes('<')) { t = title(t) } top.layui.use('layer', function () { let index = top.layui.layer.open({ type: 2, area: [w + (w > 100 ? 'px' : '%'), h + (h > 100 ? 'px' : '%')], fixed: 1, maxmin: t ? 1 : 0, resize: t ? 1 : 0, closebtn: t ? 1 : 0, title: t, content: url, end: function () { if (r == 1 && typeof (reload) === 'function') { reload(); } else if (r == 2) { window.location.reload(); } else if (typeof (r) === 'function') { r(); } } }); if (f) top.layui.layer.full(index); }); } function showlayerwindiv(t, content, w, h, f, r) { if (!w) { w = 800; } if (!h) { h = ($(window).height() - 50); } layui.use('layer', function () { var index = layui.layer.open({ type: 1, area: [w + 'px', h + 'px'], fix: false, shade: 0.4, title: t, content: content, end: function () { if (!r) { window.location.reload(); } else if (r === true && typeof (reload) === 'function') { reload(); } if (typeof (r) === 'function') { r(); } } }); if (f) layui.layer.full(index); }); } //关闭弹出框口 function closewin(msg, time) { if (msg) { showmsg(msg, (time ? time : 3000), 1, function () { layerwinclose(); }); } else { layerwinclose(); } } //关闭弹出框口 function layerwinclose() { var index = parent.layer.getframeindex(window.name); parent.layer.close(index); } //关闭指定弹出框口 function layerclose(index) { layer.close(index); } //显示提示信息 function showalert(info, icon, time) { if (time == undefined) time = 0; if (icon == undefined) icon = 8; //layui模块加载 layui.use(['layer'], function () { layui.layer.msg("" + info, { title: '温馨提示', shadeclose: false, time: time, shade: [0.3, '#000'], skin: 'icon-center', btnalign: 'c', icon: icon, area: '400px', btn: ['确定'], yes: function (index) { layer.close(index); } }); }); } function successalert(info, time, icon) { if (time == undefined) time = 3000; if (icon == undefined) icon = 1; //layui模块加载 layui.use(['layer'], function () { layui.layer.msg("" + info, { title: '温馨提示', shadeclose: false, time: 0, shade: [0.3, '#000'], skin: 'icon-center', btnalign: 'c', icon: icon, area: '400px', btn: ['确定'], yes: function (index) { layer.close(index); } }); }); } function showalertcallback(info, callback, time, icon) { if (time == undefined) time = 3000; if (icon == undefined) icon = 1; //layui模块加载 layui.use(['layer'], function () { layui.layer.msg("" + info, { title: '温馨提示', shadeclose: false, time: 0, shade: [0.3, '#000'], skin: 'icon-center', btnalign: 'c', icon: icon, area: '400px', btn: ['确定'], yes: function (index) { layer.close(index); callback(true); }, end: function () { callback(true); } }); }); } //显示一条信息 function showmsg(info, time, icon, callback) { if (icon == undefined) icon = 1; if (time == undefined) time = 20000; return layer.msg(info, { title: '温馨提示', time: time, icon: icon, shade: [0.3, '#000'], btnalign: 'c', area: '400px', skin: 'icon-center', btn: ['确定'] }, function () { callback(); }); } //选择操作 function doconfirm(t, callback) { layui.use(['layer'], function () { layui.layer.msg(t, { title: "温馨提示", shade: [0.3, '#000'], icon: 3, time: 0, shadeclose: true, content: t, skin: 'icon-center', btn: ['确定', '放弃'], yes: function (index, layero) { callback(true); layer.close(index); }, no: function () { callback(false); }, }); }); } function doprompt(t, callback) { layui.use(['layer'], function () { layer.prompt({ formtype: 2, value: t.value, title: t.title, area: ['600px', '280px'], }, function (value, index) { callback(value); layer.close(index); }); }); } //显示正在加载 function showloading(info, time, icon) { if (icon == undefined) icon = 16; if (time == undefined) time = 200000; if (info == undefined) info = '正在加载数据,请稍后...'; return layer.msg(info, { time: time, icon: icon, shade: [0.3, '#000'] }); } //停止显示正在加载加载 function stoploading() { layui.use(['layer'], function () { layer.close(); }); } /** * 判断t的是否为空 * @param t * @returns {boolean} */ function isempty(t) { var pt = /^$/; return pt.test(t); } /** * 判断是否为整数 * @param t * @returns {boolean} */ function isint(t) { return (parseint(t) == t); } /** * 是正整数 * @param t * @returns {boolean} */ function ispostint(t) { return (parseint(t) == t && t > 0); } /** * 是小数 * @param t * @returns {boolean} */ function isdecimal(t) { return parseint(t) != t; } /** * 是正小数 * @param t * @returns {boolean} */ function ispostdecimal(t) { return (parseint(t) != t && t > 0); } /** * 大于零的金额 * @param t * @returns {boolean} */ function ispostprice(t) { return (ispostint(t) || ispostdecimal(t)); } /** * 验证英文名登陆名称 * 字母开始,可带数字 下划线 3到15个 * [g/20150127] */ function isusername(t) { var pt = /^[a-za-z]{1}[a-za-z\d]{3,15}$/; return pt.test(t); } function isenglishname(t) { var pt = /^[a-za-z]{1}[\w\-]{3,31}$/; return pt.test(t); } /** * 验证密码是否合法 * 字母数字组合至少6位最长16位 * [g/20150127] */ function ispassword(t) { if (t == undefined || t.trim().length < 6 || t.trim().length > 16) { return false; } else { return true; } } /** * 验证中文名 * [g/20150127] */ function ischinesename(t) { var pt = /^[\u4e00-\u9fa5]{2,15}$/; return pt.test(t); } /** * 是否全中文 * [g/20150127] */ function ischinesetext(t) { var pt = /^[\u4e00-\u9fa5]+$/; return pt.test(t); } /** * 中文名或英文名 * 英文名称3个到15个,可以有一个空格,首字母后可以带数字 * 中文2个到15个不允许空格 * [g/20150127] */ function isname(t) { var pt = /(^[a-za-z]\w{2,15}[\s]?\w{2,15}$)|(^[\u4e00-\u9fa5]{2,15})$/; return pt.test(t); } /** * jquery 校验扩展 */ function jvalidatorextend() { jquery.validator.addmethod("validatephone", function (value, element) { return isphone(value); }) } /** * 验证 * 13 15 17 18 开头的手机 */ function ismobilephone(t) { var pt = /^(1[3578][\d]{9})$/; return pt.test(t); } /** * 验证联系电话包含 * 13 15 17 18 开头的手机 * 0xx-xxxxxxxx 国内座机 * 400-xxx-xxxx * 800-xxx-xxxx * [g/20150127] */ function isphone(t) { var pt = /^(1[3578][\d]{9})$|(^(400[-|\s](\d{3})[-|\s](\d{4}))|^(800[-|\s](\d{3})[-|\s](\d{4}))|^0\d{2,3}[-|\s](\d{7,8})|^(\d{6,8}[-|\s](\d{2,5}))|^(\d{6,8}))$/; return pt.test(t); } /** * 验证电子邮件地址 * [g/20150127] */ function isemail(t) { var pt = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/; return pt.test(t); } /** * 判断是否是日期型 * @param str * @returns {boolean} */ function isdate(str) { if (str == undefined || str == null || str == "") { return false; } var reg = /^(\d{4})-(\d{1,2})-(\d{1,2})$/; if (reg.test(str) && regexp.$2 <= 12 && regexp.$3 <= 31) { return true; } else { return false; } } //页面直接跳转 function goaction(link, target) { //window.location=link; window.open(link, target); } //执行form function dosubmit(doform, t) { doconfirm(t, function (e) { if (e) { document.all(doform).submit(); } else { showmsg('放弃操作!!'); } }); } //跳转前提示 function doaction(link, t) { doconfirm(t, function (e) { if (e) { window.location = link; } }); } function geturlpara(name) { var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return decodeuri(r[2]); return null; } // 对date的扩展,将 date 转化为指定格式的string // 月(m)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占位符,毫秒(s)只能用 1 个占位符(是 1-3 位的数字) // 例子: // (new date()).format("yyyy-mm-dd hh:mm:ss.s") ==> 2006-07-02 08:09:04.423 // (new date()).format("yyyy-m-d h:m:s.s") ==> 2006-7-2 8:9:4.18 date.prototype.format = function (fmt) { //author: meizz var o = { "m+": this.getmonth() + 1, //月份 "d+": this.getdate(), //日 "h+": this.gethours(), //小时 "m+": this.getminutes(), //分 "s+": this.getseconds(), //秒 "q+": math.floor((this.getmonth() + 3) / 3), //季度 "s": this.getmilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(regexp.$1, (this.getfullyear() + "").substr(4 - regexp.$1.length)); for (var k in o) if (new regexp("(" + k + ")").test(fmt)) fmt = fmt.replace(regexp.$1, (regexp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); return fmt; }; // 控制ctrl键 var ctrlkey = 0; function setctrlkey() { $(document.body).keydown(function (event) { if (event.keycode == '17') ctrlkey = 1; }); $(document.body).keyup(function (event) { if (event.keycode == '17') ctrlkey = 0; }) } //返回时间值可进行比较 function comparedate(date1, date2) { return (date.parse(new date(date1)) - date.parse(new date(date2))); } function comparedatenow(date) { return (getdatetime(date) - date.now()); } function getdatetime(date) { return new date(date.parse(date.replace(/-/g, "/"))).gettime() } date.prototype.now = function () { return typeof (date.now) == 'function' ? date.now() : new date().gettime(); }; //时间加一天 function adddate(date, days) { if (days == undefined || days == '') { days = 1; } var date = new date(date); date.setdate(date.getdate() + days); var month = date.getmonth() + 1; var day = date.getdate(); return date.getfullyear() + '-' + getformatdate(month) + '-' + getformatdate(day); } function addminutes(date, minutes) { if (minutes == undefined || minutes == '') { minutes = 0; } var date = new date(date); date.setminutes(date.getminutes() + minutes); var month = date.getmonth() + 1; var day = date.getdate(); return date.getfullyear() + '-' + getformatdate(month) + '-' + getformatdate(day) + ' ' + getformatdate(date.gethours()) + ':' + getformatdate(date.getminutes()) + ':' + getformatdate(date.getseconds()); } function getformatdate(arg) { if (arg == undefined || arg == '') { return ''; } var re = arg + ''; if (re.length < 2) { re = '0' + re; } return re; } //计算剩余时间 function getremaintime(date1, date2) { let date3 = date2.gettime() - date1.gettime() //时间差的毫秒数 //计算出相差天数 let days = math.floor(date3 / (24 * 3600 * 1000)) //计算出小时数 let leave1 = date3 % (24 * 3600 * 1000) //计算天数后剩余的毫秒数 let hours = math.floor(leave1 / (3600 * 1000)) //计算相差分钟数 let leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数 let minutes = math.floor(leave2 / (60 * 1000)) //计算相差秒数 let leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数 let seconds = math.round(leave3 / 1000) return days + '天' + hours + '小时' + minutes + '分钟' + seconds + '秒' } //html转义 function htmldecode(text) { var temp = document.createelement('div'); temp.innerhtml = text; var output = temp.innertext || temp.textcontent; temp = null; return output; } //html反转义 function htmlencode(html) { var temp = document.createelement('div'); (temp.textcontent != null) ? (temp.textcontent = html) : (temp.innertext = html); var output = temp.innerhtml; temp = null; return output; } string.prototype.hashcode = function () { var hash = 0, i, chr; if (this.length === 0) return hash; for (i = 0; i < this.length; i++) { chr = this.charcodeat(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // convert to 32bit integer } return hash; }; //弹窗标题加样式 function title(title) { return ' ' + title + '' } //数字校验 function inputnum(obj){ obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符 obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字 obj.value = obj.value.replace(/\.{2,}/g,""); //只保留第一个, 清除多余的 obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数 } //打印输出 function ppp(t1,t2,t3){ console.log(t1,t2,t3) }