1
lxl
2022-09-16 cb746cca26fa024018d7ce772ba6a96557ea768b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
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);
        $("<div class=\"datagrid-mask\"></div>").css({
            display: "block",
            width: wrap.width(),
            height: wrap.height()
        }).appendTo(wrap);
        $("<div class=\"datagrid-mask-msg\"></div>").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();
        }
    };
}();