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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
mui.init({
    //下拉刷新、上拉加载
    //    pullRefresh: {
    //        container: "#login_body", //下拉刷新容器标识,querySelector能定位的css选择器均可,比如:id、.class等
    //        down: {
    //            style: 'circle', //必选,下拉刷新样式,目前支持原生5+ ‘circle’ 样式
    //            color: '#2BD009', //可选,默认“#2BD009” 下拉刷新控件颜色
    //            height: '50px', //可选,默认50px.下拉刷新控件的高度,
    //            range: '100px', //可选 默认100px,控件可下拉拖拽的范围
    //            offset: '0px', //可选 默认0px,下拉刷新控件的起始位置
    //            auto: true, //可选,默认false.首次加载自动上拉刷新一次
    //            callback: pullfresh //必选,刷新函数,根据具体业务来编写,比如通过ajax从服务器获取新数据;
    //        }
    //    }
});
 
function pullfresh() {
        app.init();
    //alert("刷新");loader
};
 
if (app.isPAD()) {
    mui(".mui-content")[0].classList.add("pad");
} else {
    mui(".mui-content")[0].classList.add("app");
};
 
//自定义变量
waitingDialog = null;
downloadProgress = 0;
//plus ready.
mui.plusReady(function() {
    //读取本地存储,检查是否为首次启动,进行展示指南
    // var showGuide = plus.storage.getItem("lauchFlag");
    // if(!showGuide) {
    //     mui.openWindow({
    //                 id: 'guide',
    //                 url: 'guide.html',
    //                 styles: {
    //                     popGesture: "none"
    //                 },
    //                 show: {
    //                     aniShow: 'none'
    //                 },
    //                 waiting: {
    //                     autoShow: false
    //                 }
    //             });
    // }
 
    // var firstRun=false;
    
    mui("#title")[0].innerHTML = app.APP_NAME_CN;
    mui("#emp_no")[0].focus();
    
    AppInit();
    //console.log("login");
    plus.runtime.getProperty(plus.runtime.appid, function(appinfo) {
        document.getElementById("appversion").innerText = appinfo.version;
    });
 
    var FactoryPicker = new mui.PopPicker(); //账套选择
    /**
     * 获取用户名字、账套
     */
    document.getElementById("emp_no").addEventListener("DOMFocusOut", function() {
        if (document.getElementById("emp_no").value == "") return;
        // console.log(app.API_URL_HEADER + app.API_METHOD_SYSAPI_ESP);        
        mui.ajax(app.API_URL_HEADER + app.API_METHOD_SYSAPI_ESP, {
            data: {
                spname: "APP_GetUserName",
                returnvalue: 1,
                _sp_UserNumber: document.getElementById("emp_no").value
            },
            dataType: "json",
            type: "post",
            timeout: 0,
            success: function(resp) {
                if (resp.status != 0) {
                    mui("#emp_no")[0].focus();
                    plus.nativeUI.alert(resp.message, null, app.APP_NAME_CN);
                } else {
                    if (resp.data.length > 0) {
                        document.getElementById("emp_name").value = resp.data[0].PAA002;
                        document.getElementById('txtFactory').value="标准MES";
                    }
                }
            },
            error: function(xhr, type, errorThrown) {
                plus.nativeUI.toast("无法连接到服务器。");
            }
        });
        //动态设置账套 2020-02-17 杨俊燃
        // $.ajax(
        // {
        //     url: app.API_URL_HEADER + app.API_METHOD_SYSAPI_ESP,
        //     data: {
        //         spname: "APP_GetFactory",
        //         returnvalue: 1,
        //         _sp_UserNumber: document.getElementById("emp_no").value
        //     },
        //     dataType: "json",
        //     type: "post",
        //     success: function(data) {                
        //         var Factory = document.getElementById('txtFactory');
        //         alert(data.data[0].text);
        //         FactoryPicker.setData(data.data);
        //         FactoryPicker.pickers[0].setSelectedValue(plus.storage.getItem("Factory"));
        //         Factory.value = FactoryPicker.pickers[0].getSelectedText() || "";
        //         plus.storage.setItem("FactoryName", FactoryPicker.pickers[0].getSelectedText() || "");
        //         plus.storage.setItem("Factory", FactoryPicker.pickers[0].getSelectedValue() || "");
        //         localStorage.setItem("Factory", FactoryPicker.pickers[0].getSelectedValue() || "");
        //         localStorage.setItem("FactoryName", FactoryPicker.pickers[0].getSelectedValue() || "");
        //         Factory.addEventListener('tap', function(e) {
        //             FactoryPicker.pickers[0].setSelectedValue(plus.storage.getItem("Factory"), 1000);
        //             FactoryPicker.show(function(items) {
        //                 var text = items[0].text;
        //                 alert(text);
        //                 if (Factory.value == text)
        //                     return;
        //                 Factory.value = text ? text : "";
        //                 plus.storage.setItem("Factory", items[0].value);
        //                 plus.storage.setItem("FactoryName", items[0].text);
        //                 localStorage.setItem("Factory", items[0].value);
        //                 localStorage.setItem("FactoryName", items[0].text);
        //                 document.getElementById('txtFactory').value=text;
        //             });
        //         });
 
        //     },
        //     error: function(xhr, type, errorThrown) {
        //         plus.nativeUI.toast("无法连接到服务器。");
        //     }
        // });
    });
 
    /**
     * 账号回车事件
     */
    document.getElementById("emp_no").addEventListener("keydown",
        function(e) {
            if (e.keyCode != 13) return;
            mui("#password")[0].focus();
        });
 
    /**
     * 登录
     */
    document.getElementById("button_login").addEventListener("click",
        function() {
            ExecuteLogin();
        });
 
    /**
     * 输入好密码后回车登陆操作
     */
    document.getElementById("password").addEventListener("keydown",
        function(e) {
            if (e.keyCode != 13) return;
            ExecuteLogin();
 
        });
 
    //关闭启动屏幕
    plus.navigator.closeSplashscreen();
});
 
/**
 * 登陆操作
 */
function ExecuteLogin() {
    var Factory = "标准MES";//plus.storage.getItem("Factory");
    if (typeof Factory == "undefined" || Factory == null || Factory == "") {
        plus.nativeUI.toast("请选择帐套!");
        return;
    }
    var currentSession = app.loadconfig(app.CONFIG_CURRENT_SESSION);
    //缓存用户账号  2018年11月7日17:14:10
    var emp_no = document.getElementById("emp_no").value;
    plus.storage.setItem("UserID", emp_no);
 
    //当前选择的语言  2019-07-09 12:46
    //    var multilingual = document.getElementById("txtMultilingual").value;
    //    plus.storage.setItem("Multilingual", multilingual);
 
    //console.log('登陆进行记住账号操作:' + emp_no);
 
    mui.ajax(app.API_URL_HEADER +app.API_METHOD_ESP , {//app.API_METHOD_SYSAPI_ESP
        data: {
            spname: "APP_Login",
            returnvalue: 1,
            _sp_UserNumber: emp_no,
            _sp_Password: document.getElementById("password").value
        },
        dataType: "json",
        type: "post",
        timeout: 0,
        success: function(resp) {
            //console.log(JSON.stringify(resp));
            if (resp.status != 0) {
                plus.nativeUI.alert(resp.message, null, app.APP_NAME_CN);
            } else {
                //记录登录信息
                currentSession = currentSession || {};
                currentSession.user_id = emp_no;
                currentSession.user_name = document.getElementById("emp_name").value;
                //console.log(app.formatJSON(currentSession));
                app.saveconfig(app.CONFIG_CURRENT_SESSION, currentSession);
 
                //跳转到主页
                var target_page = plus.webview.getWebviewById("index");
                if (!target_page) {
                    target_page = mui.preload({ //openWindow
                        url: "index.html",
                        id: "index",
                        styles: {
                            popGesture: "none"
                        },
                        show: {
                            autoShow: false
                        }
                    });
                }
                if (target_page) {
                    target_page.show("slide-in-right", 200);
                };
            }
        },
        error: function(xhr, type, errorThrown) {
            plus.nativeUI.toast("无法连接到服务器。");
        }
    });
}
 
/**
 * APP初始化,检查更新
 */
function AppInit() {
    app.init(
        function(networktype) {
            //console.log(networktype);
            document.getElementById("networktype").innerText = networktype;
            //查看是否有记住用户账号,如果有记住默认使用该账号 杨俊燃 2018年11月7日17:18:20
            var recordUserID = plus.storage.getItem("UserID");
            if (recordUserID) {
                document.getElementById("emp_no").value = recordUserID;
                mui("#emp_no")[0].select();
                //console.log('记住的账号' + recordUserID);
            }
 
            // //检查更新
            setTimeout(function() {
                var currentSession = app.loadconfig(app.CONFIG_CURRENT_SESSION);
                var user_id = 1;
                if (currentSession && currentSession.login && currentSession.login.usersysid) {
                    user_id = currentSession.login.usersysid;
                }
                plus.runtime.getProperty(plus.runtime.appid, function(appinfo) {
                    var data = {
                        PRA001: app.APP_Sys_Number
                    };
                    var responseData =
                        AjaxOperation(data, "获取APP版本信息", true, "/MESPDABase/CheckAPPUpdate");
                    
                    if (!responseData.state) {
                        //console.log("结果失败" + JSON.stringify(responseData));
                        return;
                    }    
                    //alert(appinfo.version);
                    //console.log("结果成功" + appinfo.version + "=" + responseData.data.data.appVersion + "=" + JSON.stringify(responseData));
                    if (appinfo.version != responseData.data.data.appVersion) {
                        //console.log("版本不同进行更新操作" + JSON.stringify(appinfo) + '1111' + JSON.stringify(responseData.data.data.appVersion));
                        if (confirm('检测到新版本,是否立即更新?')) {
                            downWgt();
                        }
                        //return;
                    }
 
                    // //检测语言库版本是否一致
                    // var M_Version = plus.storage.getItem("MultilingualVersion"); //当前语言版本
                    // if (M_Version) {
                    //     //console.log("存在语言库,检测版本是否一致" + M_Version + "=" + responseData.data.data.MultilingualVersion);
                    //     //存在语言库,检测版本不一致
                    //     if (M_Version != responseData.data.data.MultilingualVersion) {
                    //         //重新写入语言库
                    //         GetMultilingual();
                    //     }
                    // } else {
                    //     //console.log("没有记录过语言库重新写入语言库");
                    //     //没有记录过语言库重新写入语言库
                    //     GetMultilingual();
                    // }
                    // //记录语言库版本
                    // plus.storage.setItem("MultilingualVersion", responseData.data.data.MultilingualVersion);
 
                });
            }, 1000);
        }, true);
};
// 下载wgt文件
function downWgt() {    
    var wgtUrl = app.API_URL + "/_downloads/update.wgt";
    plus.nativeUI.showWaiting("下载wgt文件...");
    plus.downloader.createDownload(wgtUrl, {
        filename: "_doc/update/"
    }, function(d, status) {
        if (status == 200) {
            //console.log("下载wgt成功:" + d.filename);
            installWgt(d.filename); // 安装wgt包
        } else {
            //console.log("下载wgt失败!");
            plus.nativeUI.alert("下载wgt失败!");
        }
        plus.nativeUI.closeWaiting();
    }).start();
}
 
// 更新应用资源
function installWgt(path) {
    plus.nativeUI.showWaiting("安装wgt文件...");
    plus.runtime.install(path, {
        force: true
    }, function() {
        plus.nativeUI.closeWaiting();
        //console.log("安装wgt文件成功!");
        plus.nativeUI.alert("应用资源更新完成!", function() {
            plus.runtime.restart();
        });
    }, function(e) {
        plus.nativeUI.closeWaiting();
        //console.log("安装wgt文件失败[" + e.code + "]:" + e.message);
        plus.nativeUI.alert("安装wgt文件失败[" + e.code + "]:" + e.message);
    });
}
 
/**
 * 开始下载任务
 * @param {要下载文件资源地址} url
 * @param {下载任务的参数} fileName
 */
function startTask(url, fileName) {
    var task = plus.downloader.createDownload(url, {
        filename: fileName
    });
    task.addEventListener("statechanged", onstatechanged);
    waitingDialog = app.showWaiting("准备下载");
    task.start();
}
 
/**
 * 下载进度
 * @param {Object} d
 * @param {Object} s
 */
function onstatechanged(d, s) {
    if (d.state == 4) {
        if (s == 200) {
            if (mui.os.android && d.filename.substr(d.filename.length - 3, 3) == "apk") {
                plus.runtime.install(d.filename, {
                    force: true
                });
                if (waitingDialog) waitingDialog.close();
            } else {
                plus.runtime.install(d.filename, {
                    force: true
                }, function() {
                    //plus.nativeUI.closeWaiting();
                    if (waitingDialog) waitingDialog.close();
                    plus.runtime.restart();
                }, function(e) {
                    if (waitingDialog) waitingDialog.close();
                    plus.nativeUI.toast("资源更新失败:" + e.message);
                    alert("资源更新失败:" + e.message);
                });
            }
        } else {
            waitingDialog.close();
            plus.nativeUI.toast("下载更新失败");
        }
    } else {
        if (d.totalSize > 0) {
            if (parseInt(d.downloadedSize * 100 / d.totalSize) % 5 == 0 && downloadProgress != parseInt(d.downloadedSize * 100 /
                    d.totalSize)) {
                downloadProgress = parseInt(d.downloadedSize * 100 / d.totalSize);
                ////console.log(d.filename);
                if (downloadProgress > 100) {
                    downloadProgress = downloadProgress - 100;
                }
                if (waitingDialog) waitingDialog.setTitle("已下载:" + downloadProgress + "%");
            }
        }
    }
};
 
/**
 * 重新写入语言库
 */
function GetMultilingual() {
    var responseData =
        AjaxOperation({}, "获取APP语言库信息", true, "/MESPDABase/GetMultilingual");
 
    $(responseData.data.data.list).each(function(index, item) {
        //        alert(JSON.stringify(item));
        //        alert(app.MULTILINGUAL_PATH + item.name + '.properties');
        plus.io.requestFileSystem(plus.io.PRIVATE_DOC, function(fs) {
            fs.root.getFile(app.MULTILINGUAL_PATH + item.name + '.properties', {
                    create: true
                },
                function(fileEntry) {
                    fileEntry.file(function(file) {
                        var fileWrite = new plus.io.FileWriter;
                        fileEntry.createWriter(function(fileWrite) {
                            //console.log("开始写入");
                            fileWrite.seek(0);
                            fileWrite.write(item.strings);
                            //console.log("结束写入");
                            //读文件 
                            //fileWrite.onwrite = function(e) {
                            //    //console.log("Write data success!");
                            //    var fileReader = new plus.io.FileReader();
                            //    //console.log("getFile:" + JSON.stringify(file));
                            //    fileReader.readAsText(file, 'utf-8');
                            //    fileReader.onloadend = function(evt) {
                            //        //console.log("输出结果" + evt.target.result);
                            //    }
                            //}
                        })
                    });
                });
        });
    });
    loadProperties(plus.storage.getItem("Multilingual") || "CN");
}