$(function () { if (window.parent == window) { setLayoutInit(); } else { setTimeout(ajaxLoader, 200); setTimeout(setLayoutInit, 200); } }); function setLayoutInit() { findParent(); objToastr.options = { "closeButton": true, "debug": false, "progressBar": true, "positionClass": "toast-bottom-right", "onclick": null, "showDuration": "400", "hideDuration": "1000", "timeOut": "5000", "extendedTimeOut": "1000", "showEasing": "swing", "hideEasing": "linear", "showMethod": "fadeIn", "hideMethod": "fadeOut" }; if (window.location.pathname.length > 2) { console.log("执行绑定事件"); // $(".J_menuItem").unbind() $(".J_menuItem").unbind("click").unbind("click").on("click", appendTab); } } var objToastr = new Object(); //通知 var objLayer = new Object(); //弹窗 var objWindow = new Object(); //window对象 function findParent() { //window.location.pathname //window.location.search //alert($(window.document).contents().find(".J_iframe").length); //首页 //alert($(window.document).contents().find(".layui-layer-iframe").length); //页面 if (window.parent == window || window.location.pathname === "/" || window.location.pathname.toLocaleLowerCase() === "/home" || window.location.pathname.toLocaleLowerCase() === "/home/index") { objToastr = toastr; objLayer = layer; objWindow = window; } else if (window.parent.location.pathname === "/" || window.parent.location.pathname.toLocaleLowerCase() === "/home" || window.parent.location.pathname.toLocaleLowerCase() === "/home/index") { objToastr = parent.toastr; objLayer = parent.layer; objWindow = parent.window; } else if (window.parent.parent.location.pathname === "/" || window.parent.parent.location.pathname.toLocaleLowerCase() === "/home" || window.parent.parent.location.pathname.toLocaleLowerCase() === "/home/index") { objToastr = parent.parent.toastr; objLayer = parent.parent.layer; objWindow = parent.parent.window; } else if (window.parent.parent.parent.location.pathname === "/" || window.parent.parent.parent.location.pathname.toLocaleLowerCase() === "/home" || window.parent.parent.parent.location.pathname.toLocaleLowerCase() === "/home/index") { objToastr = parent.parent.parent.toastr; objLayer = parent.parent.parent.layer; objWindow = parent.parent.parent.window; } } !(function ($) { $.getUrlParam = function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return ''; }; $.isValid = function (value) { if (value === null || value === '' || value === undefined) { return false; } return true; }; $.hasValue = function (value) { if (value === null || value === '' || value === undefined) { return false; } return true; }; $.isNumber = function (value) { if (value === null || value === '' || value === undefined) { return false; } return !isNaN(value); }; $.isTrue = function (value) { if (value != null && value != undefined && (value === true || value.toString().toLocaleLowerCase() === 'true')) { return true; } return false; }; $.getPercent = function (divisor, dividend) { if ($.isNumber(divisor) && $.isNumber(dividend) && dividend !== 0) { return (divisor / dividend * 100).toFixed(2) + '%'; } return ''; }; $.getQtyDiff = function (subtrahend, minuend) { if ($.isNumber(subtrahend) && $.isNumber(minuend)) { return subtrahend - minuend; } return 0; }; $.fn.resetForm = function () { $(':input', this).not(':button, :submit, :reset, :hidden, :file,.unclear').val('') .removeAttr('checked'); //.removeAttr('selected'); }; })(jQuery); function ajaxJson(url, postData, callBack) { $.ajax({ url: url, type: "post", data: postData, success: function (data) { callBack(data); } }); }; function ajaxSyncJson(url, postData, callBack) { $.ajax({ url: url, type: "post", data: postData, async: false, //异步 默认true success: function (data) { callBack(data); } }); }; function ajaxLoader() { var imgLoad = new Object(); jQuery(document).ajaxStart(function () { imgLoad = parent.layer.load(2, { shade: [0.2, '#fff'] }); //0.1透明度的白色背景 }).ajaxStop(function () { if ($.isNumber(imgLoad)) { parent.layer.close(imgLoad); } }).ajaxError(function (a, b, e, s) { if ($.isNumber(imgLoad)) { parent.layer.close(imgLoad); } }); }; $.ajaxSetup({ statusCode: { 477: function (data) { msg.toacinfo('抱歉,您当前无数据权限,如需要请联系管理员'); }, 488: function (data) { msg.toacinfo('抱歉,你不具有当前操作的权限!'); }, 499: function (data) { msg.tologin('登录过期,请重新登录'); }, 500: function (data) { msg.toexinfo('服务异常,请联系管理员'); } } }); //----------------------------------------------------- // 通知 //----------------------------------------------------- var msg = {}; msg.suc = function (msgs, title) { if (msgs == null) { msgs = ""; } if (title == null) { title = ""; } objToastr.success(msgs, title); }; msg.info = function (msgs, title) { if (msgs == null) { msgs = ""; } if (title == null) { title = ""; } objToastr.info(msgs, title); }; msg.warn = function (msgs, title, op) { if (msgs == null) { msgs = ""; } if (title == null) { title = ""; } if ($.isValid(op) && (op === 1 || op === "1")) { if (!$.isValid(title)) { title = "提示"; } objLayer.alert(msgs, { title: '' + title + '', icon: 8, skin: 'layer-ext-moon' }); } else { objToastr.warning(msgs, title); } }; msg.err = function (msgs) { if (msgs == null) { msgs = ""; } objLayer.alert(msgs, { title: '错误', icon: 2, skin: 'layer-ext-moon' }); }; //对应LoginAuthAttribute var lockNumber = 0; msg.tologin = function (msgs) { var wdoc = new Object(); if ($(window.document).find("#hidLockMsg").length > 0) { wdoc = window.document; } else if ($(parent.window.document).find("#hidLockMsg").length > 0) { wdoc = parent.window.document; } else if ($(parent.parent.window.document).find("#hidLockMsg").length > 0) { wdoc = parent.parent.window.document; } else if ($(parent.parent.parent.window.document).find("#hidLockMsg").length > 0) { wdoc = parent.parent.parent.window.document; } if ($(wdoc).find("#hidLockMsg").length > 0) { var hidLockMsg = $(wdoc).find("#hidLockMsg"); var hidLockUser = $(wdoc).find("#hidLockUser"); if ($(hidLockMsg).val() === "") { $(hidLockMsg).val(lockNumber); var html = '
'; html += '
'; html += ''; html += ''; html += ''; html += ''; html += '
'; html += ''; html += ''; html += '
'; $.ajax({ url: "/Home/LoginLockInit", type: "post", data: { txtID: $(hidLockUser).val() } }); objLayer.open({ type: 1 //Page层类型 , area: ['420px', '200px'] , title: '  已锁定:' + ((lockNumber > 0) ? msgs + " " + lockNumber : msgs) + '' , shade: 0.8 //遮罩透明度 , maxmin: false //允许全屏最小化 , anim: 1 //0-6的动画形式,-1不开启 , content: html //, yes: function (index) { } , cancel: function (index) { $("#txtLoginPwd").focus(); return false; } }); };//end if };//end if } //msg.tologin = function (msgs) { // var fmContents = $(objWindow.document).contents(); // if (fmContents.find("#hidLockMsg").length > 0) { // var hidLockMsg = fmContents.find("#hidLockMsg"); // if ($(hidLockMsg).val() === "") { // $(hidLockMsg).val("lock"); // objLayer.alert(msgs, { // title: '登录验证', // icon: 5, // skin: 'layer-ext-moon', // yes: function (index) { // objLayer.close(index); // top.location.href = "/home/login?m=" + escape(msgs); // $(hidLockMsg).val(""); // }, // cancel: function (index) { // top.location.href = "/home/login?m=" + escape(msgs); // $(hidLockMsg).val(""); // } // }); // };//end if // };//end if //} //对应AuthAttribute msg.toacinfo = function (msgs) { if (typeof objToastr.warning === "function") { objToastr.warning(msgs); } else { setTimeout(function () { objToastr.warning(msgs); }, 200); } } //对应ExceptionAttribute msg.toexinfo = function (msgs) { if (typeof objToastr.error === "function") { objToastr.error(msgs, "System Error"); } else { setTimeout(function () { objToastr.error(msgs, "System Error"); }, 200); } } msg.confirm = function (msgs, funSuc, funCal) { objLayer.confirm(msgs, { icon: 3, skin: 'layer-ext-moon', btn: ['确定', '取消'] }, function (index) { objLayer.close(index); if (funSuc || funSuc != undefined) { funSuc(); } }, function (index) { objLayer.close(index); if (funCal || funCal != undefined) { funCal(); } }); }; msg.yesno = function (msgs, funYes, funNo) { objLayer.confirm(msgs, { icon: 3, skin: 'layer-ext-moon', btn: ['是', '否'] }, function (index) { objLayer.close(index); if (funYes || funYes != undefined) { funYes(); } }, function (index) { objLayer.close(index); if (funNo || funNo != undefined) { funNo(); } }); }; var tab = {}; tab.close = function (url) { if (window.top != null) { window.top._CloseTab(url); } else { _CloseTab(url); } } tab.refresh = function (url) { if (window.top != null) { window.top._RefreshTab(url); } else { _RefreshTab(url); } } //----------------------------------------------------- // 弹窗 //----------------------------------------------------- var dlog = {}; dlog.open = function (title, btns, size, url, funYes, funCancel, funBtn2, funBtn3, funBtn4) { var winwidth = $(objWindow).width(); var winheight = $(objWindow).height(); var isMove = '.layui-layer-title'; if (!$.isValid(url)) { return false; } if (size === "full" || $(parent.window).width() < 500) { isMove = false; winwidth = $(objWindow).width(); winheight = $(objWindow).height(); } else if (size === "lg") { winwidth = Math.min(900, $(objWindow).width()); winheight = Math.min(600, $(objWindow).height()); } else if (size === "sm") { winwidth = Math.min(500, $(objWindow).width()); winheight = Math.min(450, $(objWindow).height()); } var areas = [(winwidth - 1) + 'px', (winheight - 1) + 'px']; objLayer.open({ title: title, type: 2, content: url, area: areas, shade: 0.3, btn: btns, move: isMove, yes: function (index) { if (typeof (objWindow["layui-layer-iframe" + index].dlogBtnYes) === "function") { var res = objWindow["layui-layer-iframe" + index].dlogBtnYes(index); if (res === false) { } else { if (funYes(res) === false) { } else { objLayer.close(index); } } } else { if (funYes(res) === false) { } else { objLayer.close(index); } } }, cancel: function (index) { if (typeof (objWindow["layui-layer-iframe" + index].dlogBtnCancel) === "function") { var res = objWindow["layui-layer-iframe" + index].dlogBtnCancel(index); if (res === false) { } else { if (funCancel || funCancel != undefined) { return funCancel(res); } } } else { if (funCancel || funCancel != undefined) { return funCancel(res); } } }, btn2: function (index) { if (typeof (objWindow["layui-layer-iframe" + index].dlogBtn2) === "function") { var res = objWindow["layui-layer-iframe" + index].dlogBtn2(index); if (res === false) { } else { if (funBtn2 || funBtn2 != undefined) { funBtn2(res); } } } else { if (funBtn2 || funBtn2 != undefined) { funBtn2(res); } } }, btn3: function (index) { if (typeof (objWindow["layui-layer-iframe" + index].dlogBtn3) === "function") { var res = objWindow["layui-layer-iframe" + index].dlogBtn3(index); if (res === false) { } else { if (funBtn3 || funBtn3 != undefined) { funBtn3(res); } } } else { if (funBtn2 || funBtn2 != undefined) { funBtn2(res); } } }, btn4: function (index) { if (typeof (objWindow["layui-layer-iframe" + index].dlogBtn4) === "function") { var res = ["layui-layer-iframe" + index].dlogBtn4(index); if (res === false) { } else { if (funBtn4 || funBtn4 != undefined) { funBtn4(res); } } } else { if (funBtn2 || funBtn2 != undefined) { funBtn2(res); } } } }); }; dlog.win = function (title, size, url, funYes) { var winwidth = $(objWindow).width(); var winheight = $(objWindow).height(); var isMove = '.layui-layer-title'; if (!$.isValid(url)) { return false; } if (size === "full" || $(parent.window).width() < 500) { isMove = false; winwidth = $(objWindow).width(); winheight = $(objWindow).height(); } else if (size === "lg") { winwidth = Math.min(900, $(objWindow).width()); winheight = Math.min(600, $(objWindow).height()); } else if (size === "sm") { winwidth = Math.min(500, $(objWindow).width()); winheight = Math.min(450, $(objWindow).height()); } var areas = [(winwidth - 1) + 'px', (winheight - 1) + 'px']; objLayer.isRefresh = false; var onpenindex = objLayer.open({ title: title, type: 2, content: url, area: areas, shade: 0.3, btn: [], move: isMove, end: function (avsx) { if (typeof (funYes) === "function") { if (objLayer.isRefresh == true) { funYes(objLayer.isRefresh); } } }, yes: function (index) { }, cancel: function (index) { }, }); }; dlog.closeAll = function () { objLayer.closeAll('iframe'); ////type: ["dialog", "page", "iframe", "loading", "tips"] } dlog.closeLogin = function () { objLayer.closeAll('page'); } dlog.close = function (index) { if ($.isValid(index)) { objLayer.close(index); } }; dlog.Index = function () { var fm = $(window.parent.document).contents().find(".layui-layer-iframe"); if (fm.length > 0) { var ifm = fm.find("iframe:first"); if (ifm.length > 0) { return ifm.attr("id").replace("layui-layer-iframe", ""); } } return 0; }; //----------------------------------------------------- // 新增选项卡 目前仅支持一级子页面 //----------------------------------------------------- var dotime=null; function appendTab() { try { var o = $(this).attr("href"), m = $(this).data("index"), l = $.trim($(this).text()), k = true; if (o == undefined || $.trim(o).length == 0) { return false } var tt = $(this).attr("title"); if (tt != undefined && tt != "") { l = tt; } var isopendlog = $(this).attr("dlog"); if (isopendlog != undefined && isopendlog == "true") { var now = new Date(); // //2次执行时间是否超过1秒 if (dotime != null) { if (parseInt(now - dotime) <= 1000) { return false; } } dotime = now; var sizes = $(this).attr("winsize"); if (sizes == undefined || sizes == "") { sizes = "lg"; } dlog.win(tt, sizes, o, function (res) { if (typeof (_reloadPageData) === "function") { _reloadPageData() } }); return false; } var fmContents = $(objWindow.document).contents(); if (fmContents.find(".J_menuTab").length <= 0) { msg.warn("未找到父级页面或者没有选项卡控件"); return false; } //$(".J_menuTab").each(function () { fmContents.find(".J_menuTab").each(function () { if ($(this).data("id") == o) { if (!$(this).hasClass("active")) { $(this).addClass("active").siblings(".J_menuTab").removeClass("active"); //g(this); fmContents.find(".J_mainContent .J_iframe").each(function () { if ($(this).data("id") == o) { $(this).show().siblings(".J_iframe").hide(); return false } }) } k = false; return false } }); if (k) { var p = '' + l + ' '; fmContents.find(".J_menuTab").removeClass("active"); var n = ''; fmContents.find(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(n); fmContents.find(".J_menuTabs .page-tabs-content").append(p); //g($(".J_menuTab.active")) } return false; } catch (e) { msg.warn(e); return false; } } function appendTabByUrl(url, text) { try { var o = url, m = $(this).data("index"), l = text, k = true; if (o == undefined || $.trim(o).length == 0) { return false } var tt = $(this).attr("title"); if (tt != undefined && tt != "" && (l == undefined || l == "")) { l = tt; } var isopendlog = $(this).attr("dlog"); if (isopendlog != undefined && isopendlog == "true") { var now = new Date(); // //2次执行时间是否超过1秒 if (dotime != null) { if (parseInt(now - dotime) <= 1000) { return false; } } dotime = now; var sizes = $(this).attr("winsize"); if (sizes == undefined || sizes == "") { sizes = "lg"; } dlog.win(tt, sizes, o, function (res) { if (typeof (_reloadPageData) === "function") { _reloadPageData() } }); return false; } var fmContents = $(objWindow.document).contents(); if (fmContents.find(".J_menuTab").length <= 0) { msg.warn("未找到父级页面或者没有选项卡控件"); return false; } //$(".J_menuTab").each(function () { fmContents.find(".J_menuTab").each(function () { if ($(this).data("id") == o) { if (!$(this).hasClass("active")) { $(this).addClass("active").siblings(".J_menuTab").removeClass("active"); //g(this); fmContents.find(".J_mainContent .J_iframe").each(function () { if ($(this).data("id") == o) { $(this).show().siblings(".J_iframe").hide(); return false } }) } k = false; return false } }); if (k) { var p = '' + l + ' '; fmContents.find(".J_menuTab").removeClass("active"); var n = ''; fmContents.find(".J_mainContent").find("iframe.J_iframe").hide().parents(".J_mainContent").append(n); fmContents.find(".J_menuTabs .page-tabs-content").append(p); //g($(".J_menuTab.active")) } return false; } catch (e) { msg.warn(e); return false; } } //----------------------------------------------------- // 动态加入JS CSS //----------------------------------------------------- var dynamicLoading = { css: function (path) { if (!path || path.length === 0) { throw new Error('argument "path" is required !'); } var head = document.getElementsByTagName('head')[0]; var link = document.createElement('link'); link.href = path; link.rel = 'stylesheet'; link.type = 'text/css'; head.appendChild(link); alert(path); }, js: function (path) { if (!path || path.length === 0) { throw new Error('argument "path" is required !'); } var head = document.getElementsByTagName('head')[0]; var script = document.createElement('script'); script.src = path; script.type = 'text/javascript'; head.appendChild(script); alert(path); } };