var FTabPages = function () { var tabKeeper = null; /*e.g. tabKeeper = { container: "" //存放页签的容器jquery名称,如"#div1"、".cssclass" , isErase: true //加载页签前,是否将之前的内容擦除 , url: "" //页签对应页面的URL , params: {} //请求该URL需要附上的参数 , callback: null //页签加载成功后的回调函数 };*/ ////页签切换cxb function TabSwitch(actionJ) { var url = actionJ.url; onTabNoEmpty({ container: "#" + actionJ.Container , isErase: false , url: url , params: {} , callback: actionJ.callback }); } function initTab(tabJson) { tabKeeper = tabJson; } function onTabNoEmpty(tabJson) {//切换页签注意class为tab-pane active不需要设置div.css("display", "block");否则不清空就混乱了 if (tabKeeper != null) { var divPrev = $(tabKeeper.container); if (tabKeeper.isErase) { divPrev.empty(); } } tabKeeper = tabJson; var div = $(tabJson.container); if ($.trim(div.html()).length == 0) {//首次加载或已清空 loadwaiting(); getViewRequest(tabJson.url, tabJson.params, function (data) { removeloading(); div.empty().html(data); initCtrl(); docallback(tabJson.callback); }, function (data) { alert("数据获取超时或失败!\n\r错误代号:" + data.status + "\n\r错误信息:" + data.statusText); removeloading(); }); } else {//非首次加载,隐藏但不清空 docallback(tabJson.callback); } } function onTab(tabJson) {//切换页签 if (tabKeeper != null) { var divPrev = $(tabKeeper.container); if (tabKeeper.isErase) { try { divPrev.empty(); } catch (e) { divPrev[0].innerHTML = ""; } } divPrev.css("display", "none"); } tabKeeper = tabJson; var div = $(tabJson.container); div.css("display", "block"); if ($.trim(div.html()).length == 0) {//首次加载或已清空 loadwaiting(); getViewRequest(tabJson.url, tabJson.params, function (data) { removeloading(); div.empty().html(data); initCtrl(); docallback(tabJson.callback); }, function (xhr, status, data) { alert("数据获取超时或失败!\n\r错误代号:" + xhr.status + "\n\r错误信息:" + xhr.responseText); removeloading(); }); } else {//非首次加载,隐藏但不清空 docallback(tabJson.callback); } } function getViewRequest(url, params, onsuccess, onerror) { $.ajax({ type: 'get', url: url, data: params, contentType: "text/html; charset=utf-8", timeout: 30000, success: function (data) { if (onsuccess != undefined && onsuccess != null) { onsuccess(data); } }, error: function (data) { if (onerror != undefined && onerror != null) { onerror(data); } } }); } function docallback(callback) { if (typeof callback != 'undefined' && callback instanceof Function) { callback(); } } function resetTab() {//刷新当前页签 loadwaiting(); var div = $(tabKeeper.container); getViewRequest(tabKeeper.url, tabKeeper.params, function (data) { removeloading(); div.empty().html(data); div.css("display", ""); initCtrl(); docallback(tabKeeper.callback); }, function (data) { alert("数据获取超时或失败!"); removeloading(); }); } /* -- 等待控件begin -- */ function loadwaiting() {//显示等待信息 var wrap = $(document.body); $("
").css({ display: "block", width: wrap.width(), height: wrap.height() }).appendTo(wrap); $("
").html("数据加载中,请稍候...").appendTo(wrap).css({ display: "block", left: (wrap.width() - $("div.datagrid-mask-msg", wrap).outerWidth()) / 2, top: ($(window).height() - $("div.datagrid-mask-msg", wrap).outerHeight()) / 2 }); } function removeloading() {//隐藏等待信息 var wrap = $(document.body); wrap.find("div.datagrid-mask-msg").remove(); wrap.find("div.datagrid-mask").remove(); } function initloading() {//设置等待控件样式 var css = ".datagrid-mask { "; css += " position: absolute; "; css += " left: 0; "; css += " top: 0; "; css += " width: 100%; "; css += " height: 100%; "; css += " opacity: 0.3; "; css += " filter: alpha(opacity=30); "; css += " display: none; "; css += "} "; css += ".datagrid-mask-msg { "; css += " position: absolute; "; css += " top: 50%; "; css += " margin-top: -20px; "; css += " padding: 10px 5px 10px 10px;"; css += " width: auto; "; css += " height: 16px; "; css += " border-width: 2px; "; css += " border-style: solid; "; css += " display: none; "; css += " box-sizing:content-box; "; css += "}"; if (document.all) { window.style = css; document.createStyleSheet("javascript:style"); } else { var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML = css; document.getElementsByTagName('HEAD').item(0).appendChild(style); } } /* -- 等待控件end -- */ function initCtrl() { //日期在模板页面有初始化,重复;弹窗初始化,IE会报错 蔡昌荣 2016-03-11 //弹窗 //if (typeof fb_init != 'undefined' && fb_init instanceof Function) { // fb_init('a.firstebox', 'tr.firstebox', 'td.firstebox');//弹窗效果初始化,解决局部刷新情况下弹窗无效问题 //} } initloading(); return { //cxb TabSwitch: function (actionJ) { TabSwitch(actionJ); }, onTab: function (tabJson) { onTab(tabJson); } , resetTab: function () { resetTab(); } , init: function (tabJson) { initTab(tabJson); initCtrl(); } }; }();