jyy
2021-04-14 6ada97d503bd93722c081b66a9adcce7599e5536
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
 * ajax请求的代理类 1、系统在一般情况都使用本类进行ajax请求不在使用原生的或者jQuery的ajax 原因:
 * 1、本类对异常信息,错误信息进行了信息提示处理 2、本类与服务器端的AjaxResult.java 对应,接收的数据格式是AjaxResult.java
 * 的json格式数据
 * 
 * author :姜友瑶; 2016-06-02
 */
(function($) {
    $.fn.extend({
        invoke : function(url, callback) {
            $this = this;
            // 是否开启遮罩
            if (this.attr("c")) {
                layer.load(2, {
                    time : 10 * 1000,
                    shade : [ 0.4, '#aeaeae' ]
                });
            }
            var data=this.attr("data");
            if(this.attr("json")){
                data=JSON.stringify(data);
            }
            $.ajax({
                type : this.attr("method"),
                url : url,
                data : data,
                async : this.attr("a"),
                timeout : 60000,
                contentType: this.attr("json")?'application/json;charset=utf-8':'application/x-www-form-urlencoded; charset=UTF-8',
                dataType:this.attr("json")?'json':'',
                success : function(result) {
                    // 全局异常处理器发出的错误信息
                    if (result.status == "200") {
                        $this.attr("result", result);
                        layer.closeAll('loading');
                        if (callback != null) {
                            callback($this,result);
                        }
                    } else if(result=="loginTimeOut..."){
                            layer.closeAll('loading');
                            layer.msg("登陆超时请重新登陆!!", {
                                icon : 2
                            },function(){
                                MTools.toPredirect(basePath+"/common/toLogin");
                            });    
                    } else {
                        if(result.info){
                            layer.closeAll('loading');
                            layer.msg(result.info, {
                                icon : 2,time:5000
                            });    
                        }
                        return null;
                    }
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    layer.closeAll('loading');
                    layer.msg("请求遇到问题-错误编号:" + XMLHttpRequest.status, {
                        icon : 2
                    });
                    
                },
            });
        },
        getRowCount : function() {
            if(this.attr("result").rows==null){
                return 0;
            }
            return this.attr("result").rows.length;
        },
        // * @param key列名
        getValue : function(key) {
            var temp = "";
            try {
                temp = eval("this.attr('result')." + key);
            } catch (e) {
                console.error('getValueg执行失败');
                console.log(e);
            }
            return temp;
        },
        getResult : function() {
            return this.attr('result');
        },
        /**
         * @param mapName游标名称
         * @param index
         *            角标
         * @param key列名
         * @returns
         */
        getString : function(index, key) {
            var temp = "";
            try {
                temp = eval("this.attr('result').rows[" + index + "]." + key);
                if (!temp) {
                    temp = "";
                }
            } catch (e) {
                console.error('getString执行失败');
                console.log(e);
            }
            return temp;
        },
        /**
         * 获取一个Img 标签
         * 
         * @param index
         *            角标
         * @param key列名
         * @param w
         *            宽
         * @param h
         *            高
         * @returns
         */
        getImg : function(index, key, w, h) {
            if (!w) {
                w = 120;
            }
            if (!h) {
                h = 100;
            }
            var temp = "";
            try {
                temp = eval("this.attr('result').rows[" + index + "]."
                        + key);
                if (!temp) {
                    return "";
                }
            } catch (e) {
                console.error('getImg执行失败');
                console.log(e);
            }
            return "<img height='" + h + "' width='" + w + "' src=" + temp
                    + "  >";
        },
        /**
         * 
         * 根据传入的键值对 对象选取匹配结构的值返回
         * 
         * @param index
         *            角标
         * @param key
         *            列名
         * @param params
         *            需要被判断的键值对
         * 
         * @returns
         */
        getSwitch : function(index, key, paramsStr) {
            var params = eval("(" + paramsStr + ")");
            var temp = "";
            try {
                temp = eval("this.attr('result').rows[" + index + "]."+key);
                // 没有获取到值
                if (!temp) {
                    // 是否存在默认值
                    if (params.empty) {
                        return params.empty;
                    } else {
                        return "";
                    }
                } else {
                    return params[temp];
                }
            } catch (e) {
                console.error('getSwitch执行失败');
                console.log(e);
            }
            return temp;
        },
        getDate : function(index, key) {
            var temp = "";
            try {
                temp = eval("this.attr('result').rows[" + index + "]['" + key
                        + "']");
                var date = new Date(temp);
                if (!temp) {
                    return "";
                } else {
                    return date.getFullYear() + "-" + (date.getMonth() + 1)
                            + "-" + date.getDate() + " " + date.getHours()
                            + ":" + date.getMinutes();
                }
            } catch (e) {
                console.error('getDate执行失败');
                console.log(e);
            }
            return temp;
        },
        getDateDD : function(index, key) {
            var temp = "";
            try {
                temp = eval("this.attr('result').rows[" + index + "]['"
                    + key + "']");
                var date = new Date(temp);
                if(!temp){
                    return "";
                }else{
                    return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
                }
            } catch (e) {
                console.log('getDate执行失败');
            }
            return temp;
        },
        getDateDDHH : function(index, key) {
            var temp = "";
            try {
                temp = eval("this.attr('result').rows[" + index + "]['"
                    + key + "']");
                var date = new Date(temp);
                if(!temp){
                    return "";
                }else{
                    return (date.getMonth()+1)+"月"+(date.getDate())+"日";
                }
            } catch (e) {
                console.log('getDate执行失败');
            }
            return temp;
        }
    });
    $.extend({
        /** 初始化过程请求参数 */
        AjaxProxy : function(option) {
            // 初始化参数
            var initParam = {
                data : {},
                a : true,
                c : true,
                method:'post',
            };
            if (option == undefined) {
                var option = {};
            }
            if (option.p) {
                initParam.data = $.extend(initParam.data,
                        option.p);
            }
            initParam = $.extend(initParam, option);
            delete initParam.p;
            return $(initParam);
        }
    });
 
})(jQuery);