wbc
2024-09-06 8177b79722037a348b08375c63723356c07690c5
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/**
 * APP全局配置
 */
app = {};
 
(function() {
    /**
     * MES系统中维护的APP系统编号
     */
    app.APP_Sys_Number = "APPSYS";
 
    /**
     * 多语言库路径
     */
    app.MULTILINGUAL_PATH = "YSMES.app/i18n/";
 
    /**
     * 应用名称
     */
    app.APP_NAME = "com.shintech.MES";
 
    /**
     * 应用中文名称
     */
    app.APP_NAME_CN = "YKD_MES";
 
    /**
     * 登陆配置(login)
     */
    app.CONFIG_LOGIN = "login";
 
    /**
     * 当前会话配置(current_session)
    //  */
    app.CONFIG_CURRENT_SESSION = "current_session";
 
    // // 内网 服务的地址
    //  app.API_URL = "http://55.55.55.202:8080";
    // //app.API_URL = "http://mes.nb-biyi.com:5637";
    // // 外网 接口服务的地址头
    // app.API_URL_BACK = "http://mes.nb-biyi.com:5637";
    // //内网 接口服务的地址头
    // app.API_URL_HEADER = "http://55.55.55.202:8080/api";
    // //app.API_URL_HEADER = "http://mes.nb-biyi.com:5637/api";
    // // 外网接口服务的地址头     
    // app.API_URL_HEADER_BACK = "http://mes.nb-biyi.com:5637/api";
 
    // app.API_URL = "http://localhost:27611/";
    // app.API_URL_BACK = "http://localhost:27611/"; 
    // app.API_URL_HEADER = "http://localhost:27611/api";
    // app.API_URL_HEADER_BACK = "http://localhost:27611/api";
    
    // app.API_URL = "http://192.168.0.103:27611";
    // app.API_URL_BACK = "http://192.168.0.103:27611";
    // app.API_URL_HEADER = "http://192.168.0.103:27611/api";
    // app.API_URL_HEADER_BACK = "http://192.168.0.103:27611/api";
 
    // app.API_URL = "http://192.168.1.198:8081/MESAPP";
    // app.API_URL_BACK = "http://192.168.1.198:8081/MESAPP";
    // app.API_URL_HEADER = "http://192.168.1.198:8081/MESAPP/api";
    // app.API_URL_HEADER_BACK = "http://192.168.1.198:8081/MESAPP/api";
    
    app.API_URL = "http://192.168.1.198:8081/MESAPP";
    app.API_URL_BACK = "http://211.140.38.18:8081/MESAPP";
    app.API_URL_HEADER = "http://192.168.1.198:8081/MESAPP/api";
    app.API_URL_HEADER_BACK = "http://211.140.38.18:8081/MESAPP/api";
 
    // app.API_URL = "http://211.140.38.18:8081/MESAPP";
    // app.API_URL_BACK = "http://211.140.38.18:8081/MESAPP";
    // app.API_URL_HEADER = "http://211.140.38.18:8081/MESAPP/api";
    // app.API_URL_HEADER_BACK = "http://211.140.38.18:8081/MESAPP/api";
 
 
 
    // app.API_URL = "http://192.168.1.250:8089/MESAPP/";
    // app.API_URL_BACK = "http://192.168.1.250:8089/MESAPP/";
    // app.API_URL_HEADER = "http://192.168.1.250:8089/MESAPP/api";
    // app.API_URL_HEADER_BACK = "http://192.168.1.250:8089/MESAPP/api";
    
    
    
    // app.API_URL = "http://182.105.131.80:8089/MESAPP/";
    // app.API_URL_BACK = "http://182.105.131.80:8089/MESAPP/";
    // app.API_URL_HEADER = "http://182.105.131.80:8089/MESAPP/api";
    // app.API_URL_HEADER_BACK = "http://182.105.131.80:8089/MESAPP/api";
    /** 
     * 接口方法:执行存储过程
     */
    app.API_METHOD_ESP = "/b/esp";
 
    /**
     * 执行系统数据库存储过程
     */
    app.API_METHOD_SYSAPI_ESP = "/SYSApi/esp";
 
    /**
     * 接口方法:获取PDF盘点票
     */
    app.API_METHOD_TEST = "/b/test";
 
    /**
     * 接口方法:检查APP更新
     */
    app.API_CHECK_APP_UPDATE = "http://localhost:27611/api/b/CheckAppUpdate";
 
    /**
     * 接口方法:检查APP更新
     */
    // app.API_CHECK_APP_UPDATE_BACK = "http://mes.nb-biyi.com:5637/api/b/CheckAppUpdate";
    //发送请求前触发 2020-02-17 杨俊燃
    $.ajaxSetup({
        beforeSend: function(request) //设置自定义标头
        {
            //var Factory = "MES_Test";
            var Factory = "MES";
            if (typeof plus != "undefined" && plus.storage.getItem("Factory") != null) {
                Factory = plus.storage.getItem("Factory");
            } else if (typeof localStorage != "undefined" && localStorage.getItem("Factory") != null) {
                Factory = localStorage.getItem("Factory");
            }
            // alert(Factory);
            request.setRequestHeader("Factory", Factory); //选择的账套
        }
    });
 
    /**
     * 应用默认配置
     */
    app.defaultconfig = {
        login: {
            account: "",
            password: "",
            autologin: false
        },
        message: {
 
        }
    };
 
    app.init = function(callback, firstRun) {
    
        //检查网络连接
        if (plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
            plus.nativeUI.alert("没有网络连接,请开启网络连接后再使用。", function() {
            
                plus.runtime.quit();
            }, app.APP_NAME_CN);
        }
 
        if (firstRun) {
            console.log("API服务器网络检查中...");
            //判断网络类型并修改服务器地址
            
            app.showWaiting("正在侦测网络...");
            console.log(app.API_URL_HEADER + app.API_METHOD_TEST);
 
            mui.ajax(app.API_URL_HEADER + app.API_METHOD_TEST, {
                data: {},
                async: true,
                dataType: "json",
                type: "post",
                timeout: 2000,
                success: function(resp) {
 
                    console.log(JSON.stringify(resp));
                    if (callback) callback("内网");
                    //保存网络检查结果
                    var currentSession = JSON.parse(plus.storage.getItem(app
                        .CONFIG_CURRENT_SESSION)) || {};
                    currentSession.networktype = "内网";
                    console.log(JSON.stringify(currentSession));
                    plus.storage.setItem(app.CONFIG_CURRENT_SESSION, JSON.stringify(
                    currentSession));
                    //把网络地址存下来
                    plus.storage.setItem(app.API_URL, app.API_URL);
                    app.closeWaiting();
                    console.log("内网success");
                },
                error: function(xhr, type, errorThrown) {
 
                    console.log(app.API_URL_HEADER_BACK + app.API_METHOD_TEST);
                    mui.ajax(app.API_URL_HEADER_BACK + app.API_METHOD_TEST, {
                        data: {},
                        async: true,
                        dataType: "json",
                        type: "post",
                        timeout: 2000,
                        success: function(resp) {
                            console.log("外网success");
                            console.log(JSON.stringify(resp));
                            app.API_URL = app.API_URL_BACK;
                            app.API_URL_HEADER = app.API_URL_HEADER_BACK;
                            app.API_CHECK_APP_UPDATE = app.API_CHECK_APP_UPDATE_BACK;
                            if (callback) callback("外网");
                            //保存网络检查结果
                            var currentSession = JSON.parse(plus.storage.getItem(app
                                .CONFIG_CURRENT_SESSION)) || {};
                            currentSession.networktype = "外网";
                            console.log(JSON.stringify(currentSession));
                            plus.storage.setItem(app.CONFIG_CURRENT_SESSION, JSON
                                .stringify(currentSession));
                            console.log(app.API_URL_HEADER + app.API_METHOD_TEST);
                            app.closeWaiting();
                        },
                        error: function(xhr, type, errorThrown) {
                            app.closeWaiting();
                            console.log("外网fail+内网fail");
                            plus.nativeUI.alert("网络不通,请检查网络。", null, app.APP_NAME_CN);
                        }
                    });
                }
            });
        } else {
            console.log("API服务器网络无需检测!!!!");
            var currentSession = JSON.parse(plus.storage.getItem(app.CONFIG_CURRENT_SESSION));
            console.log(JSON.stringify(currentSession));
            if (currentSession.networktype == "外网") {
                app.API_URL = app.API_URL_BACK;
                app.API_URL_HEADER = app.API_URL_HEADER_BACK;
                app.API_CHECK_APP_UPDATE = app.API_CHECK_APP_UPDATE_BACK;
                if (callback) callback("外网");
            } else {
                if (callback) callback("内网");
            }
        }
 
    }
 
    /**
     * 保存配置
     * @param {String} key 配置名称
     * @param {JSObject} configjsonobject 配置内容
     */
    app.saveconfig = function(key, configjsonobject) {
        if (configjsonobject == undefined || configjsonobject == null) {
            return;
        }
        plus.storage.setItem(key, JSON.stringify(configjsonobject));
    };
 
    /**
     * 加载应用程序配置
     * @param {String} key 配置名称
     * @example var config = app.loadconfig(app.CONFIG_LOGIN);
     * @return {JSObject}        
     */
    app.loadconfig = function(key) {
        if (typeof plus != "undefined")
            return JSON.parse(plus.storage.getItem(key));
        return "";
    };
    /* 
    登陆用户
    */
    app.userid = function() {
        var currentSession = app.loadconfig(app.CONFIG_CURRENT_SESSION);
        if (currentSession == "")
            return "admin"
        return currentSession.user_id;
    }
 
    /*
     * 当前选择的多语言
     */
    app.multilingual = function() {
        var m = app.loadconfig("multilingual");
        if (m == "")
            return "CN" //默认中文
        return m;
    }
 
    /**
     * 移除应用程序配置
     * @param {String} key 配置名称
     * @example app.removeconfig(app.CONFIG_LOGIN); 
     */
    app.removeconfig = function(key) {
        return plus.storage.removeItem(key);
    };
 
    app.showWaiting = function(title) {
        var waiting_title = title || "请稍候";
        if (plus) {
            return plus.nativeUI.showWaiting(waiting_title, {
                background: "rgba(100,100,100,0.8)",
                padding: "50px",
                size: "20px",
                loading: {
                    display: "inline"
                }
            });
        }
    }
 
    app.closeWaiting = function() {
        if (plus) {
            plus.nativeUI.closeWaiting();
        }
    }
 
    /**
     * 格式化JSON为便于显示输出的格式
     * @param {JSObject,String} json 可以是字符串也可以是对象
     * @return {String}
     */
    app.formatJSON = function(json) {
        var jsonStr = "";
        if (json.constructor == String) {
            jsonStr = json;
        } else if (json.constructor == Object) {
            jsonStr = JSON.stringify(json);
        }
        var res = "";
        for (var i = 0, j = 0, k = 0, ii, ele; i < jsonStr.length; i++) {
            //k:缩进,j:""个数
            ele = jsonStr.charAt(i);
            if (j % 2 == 0 && ele == "}") {
                k--;
                for (ii = 0; ii < k; ii++) ele = "    " + ele;
                ele = "\n" + ele;
            } else if (j % 2 == 0 && ele == "{") {
                ele += "\n";
                k++;
                for (ii = 0; ii < k; ii++) ele += "    ";
            } else if (j % 2 == 0 && ele == ",") {
                ele += "\n";
                for (ii = 0; ii < k; ii++) ele += "    ";
            } else if (ele == "\"") j++;
            res += ele;
        }
        return res;
    };
 
    //日期格式化函数
    Date.prototype.format = function(format) {
        var o = {
            "M+": this.getMonth() + 1, //month 
            "d+": this.getDate(), //day 
            "h+": this.getHours(), //hour 
            "m+": this.getMinutes(), //minute 
            "s+": this.getSeconds(), //second 
            "q+": Math.floor((this.getMonth() + 3) / 3), //quarter 
            "S": this.getMilliseconds() //millisecond 
        }
        if (/(y+)/.test(format)) {
            format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(format)) {
                format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[
                    k]).length));
            }
        }
        return format;
    };
 
    String.prototype.endWith = function(endStr) {
        var d = this.length - endStr.length;
        return (d >= 0 && this.lastIndexOf(endStr) == d)
    }
 
    /****
     * 比较版本,查看是否有更新
     * @param {String} oldVersion
     * @param {String} newVersion
     */
    app.HasUpdate = function(oldVersion, newVersion) {
        var oldVersion_filled, newVersion_filled;
        var a, b, c, tmp;
        if (oldVersion.indexOf(".") > 0) {
            a = oldVersion.substring(0, oldVersion.indexOf("."));
            b = oldVersion.substring(oldVersion.indexOf(".") + 1, oldVersion.length);
            if (b.indexOf(".") > 0) {
                tmp = b.substring(0, b.indexOf("."));
                c = b.substring(b.indexOf(".") + 1, b.length);
                b = tmp;
            } else {
                c = "0";
            }
        } else {
            a = oldVersion;
            b = "0";
            c = "0";
        }
        a = new Array(4 - a.length + 1).join("0") + a;
        b = new Array(4 - b.length + 1).join("0") + b;
        c = new Array(4 - c.length + 1).join("0") + c;
        oldVersion_filled = a + b + c;
        if (newVersion.indexOf(".") > 0) {
            a = newVersion.substring(0, newVersion.indexOf("."));
            b = newVersion.substring(newVersion.indexOf(".") + 1, newVersion.length);
            if (b.indexOf(".") > 0) {
                tmp = b.substring(0, b.indexOf("."));
                c = b.substring(b.indexOf(".") + 1, b.length);
                b = tmp;
            } else {
                c = "0";
            }
        } else {
            a = oldVersion;
            b = "0";
            c = "0";
        }
        a = new Array(4 - a.length + 1).join("0") + a;
        b = new Array(4 - b.length + 1).join("0") + b;
        c = new Array(4 - c.length + 1).join("0") + c;
        newVersion_filled = a + b + c;
        return newVersion_filled > oldVersion_filled;
    };
 
    app.isPAD = function() {
        if (navigator.userAgent.toUpperCase().indexOf("ANDROID") > -1) {
            return navigator.userAgent.toUpperCase().indexOf("MOBILE") == -1;
        } else {
            return navigator.userAgent.toUpperCase().indexOf("PAD") > -1;
        }
    };
}());