1
yhj
2025-03-31 9003044073373185511f1e2c901285a3287e7fa4
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
var storage = window.localStorage;
var API = window.API = {
    //webPath: "http://192.168.1.245:4580/lyt_pda",
    //webPath: "http://192.168.37.26:7090/plee",///波达
    //webPath:"http://192.168.0.13:8099/jfmes",//巨发  发布时替换为服务器ip
    webPath:"http://192.168.2.159:8099/api_screen_master_war",//测试
    // webPath:"http://115.231.56.254:8399/lgmes",//朗格
    //version:"prod",//demo:静态,prod:正式,test:测试
    //webPath: "http://192.168.102.32:9991/heyi",
    projectType: 'lyt',//已经集成乐亿通lyt,微电wd,格林泰glt,波达boda
    Bluetooth:'false',//是否初始化蓝牙功能
    PlayYes:'false',//是否播放扫码成功
    PlayNo:'false',//是否播放操作失败
    env:'soap', //只支持web-service(soap)或者json
};
 
/** 
 * 时间对象的格式化 
 */
Date.prototype.format = function(format) {
 
    /* format="yyyy-MM-dd hh:mm:ss"; */
 
    var o = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S": this.getMilliseconds()
    }
 
    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;
};
//判断浏览器是手机还是电脑
function API_GetbrType() {
    var sUserAgent = navigator.userAgent.toLowerCase();
    var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
    var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
    var bIsMidp = sUserAgent.match(/midp/i) == "midp";
    var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
    var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
    var bIsAndroid = sUserAgent.match(/android/i) == "android";
    var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
    var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
    // if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){
    if (!(bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
        return 0; //PC
    } else {
        return 1; //手机
    }
}
 
//判断登录会话是否成功,成功返回1,失败返回0
function API_getLogin() {
    //判断会话
    var r = 0;
    var params = {
        "UID": localStorage.UID
    };
    var url = storage['_basePath'] + "anon/web/kmLogin!doLogin_check.action";
    //当session丢失但localStorage没有丢失时,模拟登录一次
    //var params={"kmUser.bsCode": usr, "kmUser.bsPassword":password};
    $.ajax({
        //cache: false,
        async: false,
        dataType: 'json',
        type: 'post',
        url: url,
        data: params,
        success: function(msg) {
            if (msg.status == "SUCCESS") {
                //登录成功  
                r = 1; //验证成功
            } else {
                r = 0; //账号密码验证失败
            }
        },
        error: function(msg) {
            r = -1; //"最痛苦的事情莫过于没有网络!"
        }
    });
 
    return r;
}
function playerNo() { //播放-失败请注意
if(API.PlayNo=='true'){
    NO_VOICE = plus.audio.createPlayer("wav/NO.WAV");
    
    NO_VOICE.play(function() {
        NO_VOICE.close()
    }, function(e) {
        //console.log("Audio play error: " + e.message);
    });
    }
                
            }
//播放声音-成功音效
function playerYes() { //播放-扫码成功
if(API.PlayYes=='true'){
    YES_VOICE = plus.audio.createPlayer("wav/YES.WAV");
    
    YES_VOICE.play(function() {
        YES_VOICE.close()
    }, function(e) {
        //console.log("Audio play error: " + e.message);
    })
}
    
}
//登录,成功返回1,失败返回0
function API_Login(user, pwd) {
    //判断会话
    var r = 0;
    var usr = user;
    var password = pwd;
    var url = storage['_basePath'] + "anon/web/kmLogin!doLogin.action";
 
 
    //如果存在本地会话则校验登录信息
    if (usr) {
        //当session丢失但localStorage没有丢失时,模拟登录一次
        var params = {
            "kmUser.bsCode": usr,
            "kmUser.bsPassword": password
        };
        $.ajax({
            //cache: false,
            async: false,
            dataType: 'json',
            type: 'post',
            url: url,
            data: params,
            success: function(msg) {
                if (msg.status == "SUCCESS") {
                    localStorage.setItem("bsCode", msg.data.bsCode);
                    localStorage.setItem("bsName", msg.data.bsName);
                    localStorage.setItem("bsPassword", pwd); //电话
                    sessionStorage.setItem("bsCode", msg.data.bsCode); //存一个session会话
                    if (msg.data.appDept) {
                        localStorage.setItem("appWork", msg.data.appWork.bsCode); // 工厂代码
                        localStorage.setItem("appWorkPk", msg.data.pkWork); //工厂描述
                        localStorage.setItem("appDept", msg.data.appDept.bsCode); //部门代码
                        localStorage.setItem("appDeptPk", msg.data.pkDept); //部门描述
                    }
 
                    r = 1; //与0和1区别  这个要单独重新推送消息
                } else {
 
                    //alert(msg.jsonMessage);
                    r = 0;
                }
            }
 
        });
 
    } else {
        r = -1;
    }
    return r;
}
 
 
//淡入淡出效果插件  add by YJY 2015-8-19 
function lighttips(id, tips, time) {
    if (tips) {
        $("#" + id).find("p").html(tips);
    }
    $("#" + id).fadeIn();
    $("#" + id).fadeOut(time);
}
 
//动态加载JS,css
function loadjscssfile(filename, filetype) {
 
    if (filetype == "js") {
        var fileref = document.createElement('script');
        fileref.setAttribute("type", "text/javascript");
        fileref.setAttribute("src", filename);
    } else if (filetype == "css") {
 
        var fileref = document.createElement('link');
        fileref.setAttribute("rel", "stylesheet");
        fileref.setAttribute("type", "text/css");
        fileref.setAttribute("href", filename);
    }
    if (typeof fileref != "undefined") {
        document.getElementsByTagName("head")[0].appendChild(fileref);
    }
 
}
 
//取URL参数
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg); //匹配目标参数
    if (r != null) return unescape(r[2]);
    return null; //返回参数值
}
 
//localStorage存储数据的方法
function api_localStorageSave(objname, obj) {
    var str = JSON.stringify(obj);
    //存入 
    localStorage.setItem(objname, str)
    sessionStorage.objname = str;
}
 
function api_localStorageGet(objname) {
    //读取 
    str = localStorage.getItem(objname);
    //重新转换为对象 
    obj = JSON.parse(str);
    console.log(str);
    return obj;
}
//获取IOS站点路径http://ip:端口/PMAPP/web/
function api_getWebPath() {
    var curWwwPath = "http://" + window.location.host + "/PMAPP/web/";
    return curWwwPath;
}
//获取IOS站点路径http://ip:端口/PMAPP/web/
function api_getiWebPath() {
    var curWwwPath = "http://" + window.location.host + "/PMAPP/iweb/";
    return curWwwPath;
}
//20190808-fyx-获取url的参数
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}
var _mask = mui.createMask(); //遮罩层 
//20190808-fyx-封装mui.ajax()
;
! function(window) {
    window.aj = {};
 
    aj.get = function(url, data, success) {
        ajax("get", storage['_basePath'] + url, data, success);
    };
 
    aj.post = function(url, data, success) {
 
        var urlA = storage['_basePath'] + url;
 
        console.log(urlA);
        console.log(JSON.stringify(data))
//console.log(data)
        ajax("post", urlA, data, success);
    };
 
 
    function ajax(type, url, data, success) {
        /* $.ajax({
            'type': type,
            'url': url,
            'data': data,
            'dataType': "json",
            'cache': false,
            'async': true,
            'success': success,
            'contentType': 'application/json;charset=utf-8',
            'beforeSend': function () {
                index = layer.msg('加载中', {
                    icon: 16,
                    shade: 0.01
                });
            },
            'complete': function () {
                layer.close(index);
            }
        }); */
        mui.ajax(url, {
            data: data,
            dataType: 'json',
            type: 'POST',
            timeout: 20000,
            headers: {},
            success: success,
            error: function(xhr, type, errorThrown) {
                console.log(JSON.stringify(errorThrown))
                console.log(JSON.stringify(type))
                console.log(JSON.stringify(xhr))
                mui.alert('服务器连接超时,请稍后再试');
            },
            beforeSend: function() {
                plus.nativeUI.showWaiting("处理中,请等待...");
                _mask.show(); //显示遮罩层
                //transWaiting()
            },
            complete: function() {
                plus.nativeUI.closeWaiting();
                _mask.close(); //关闭遮罩层
            }
        })
    }
}(window);
//20191129-fyx-封装ajax调用webservice的方法
function jQueryWeb(url, data, complete) {
    //console.log(JSON.stringify(data));
    $.ajax({
        type: "POST",
        url: "http://192.168.1.160:8888/Service.asmx/" + url,
        data: data,
        dataType: "xml",
        complete: complete,
        beforeSend: function(request) {
            _mask.show(); //显示遮罩层
            request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            request.setRequestHeader("SOAPAction", "http://ecifWebservice/service");
        },
        success: function(result) {
            //console.log(JSON.stringify(result))
            _mask.close(); //关闭遮罩层
        },
        error: function(request, errorInfo) {
            console.log(JSON.stringify(request))
            _mask.close(); //关闭遮罩层
            alert("errorInfo = " + errorInfo);
        }
    });
}
 
function doPost(url, data, complete1, complete2) {
    if (API.env == 'soap') {
        jQueryWeb(url, data, complete1)
    } else {
        aj.post(url, data, complete2)
    }
}
//20191129-fyx-封装打开新页面的方法
function OpenWindow(id, url, extras) {
    mui.openWindow({
        id: id,
        url: url,
        styles: {
            top: '0px', //新页面顶部位置 
            bottom: '0px', //新页面底部位置 
            //width: newpage - width, //新页面宽度,默认为100% 
            //height: newpage - height, //新页面高度,默认为100% ...... 
        },
        extras: extras,
        show: { //控制打开页面的类型
            autoShow: true,
            //页面loaded事件发生后自动显示,默认为true 
            aniShow: 'slide-in-right', //页面显示动画,默认为”slide-in-right“;  页面出现的方式 左右上下
            duration: '100' //页面动画持续时间,Android平台默认100毫秒,iOS平台默认200毫秒; 
        },
        waiting: { // 控制 弹出转圈框的信息
            autoShow: true, //自动显示等待框,默认为true 
            title: '加载中', //等待对话框上显示的提示内容 
            options: {
                width: '300px', //等待框背景区域宽度,默认根据内容自动计算合适宽度 
                height: '100px', //等待框背景区域高度,默认根据内容自动计算合适高度 ...... 
            }
        }
    });
}
 
//展示用户账号名称 2022/6/22 -lst
function setUsrCode() {
    return "" + api_localStorageGet("name");
}