luyanan 7 years ago
parent
commit
9d517eef3f
2 changed files with 74 additions and 8 deletions
  1. 69 4
      app/js/index.js
  2. 5 4
      app/js/public/base.js

+ 69 - 4
app/js/index.js

@ -7,11 +7,76 @@ var search = document.getElementById("search");
7 7
mui.plusReady(function() {
8 8
	//plus.nativeUI.showWaiting();
9 9
	checkVersion();
10
})
11
document.addEventListener("resume", function() {
12
	checkVersion();
13
}, false)
14 10

11
document.addEventListener("resume", function(e) {
12
	//alert(JSON.stringify(e));
13
	if(mui.os.ios) {
14
	 window.check_version = window.check_version || 1;
15
	 window.check_version++;
16
	 if(window.check_version % 2) {
17
	 	return;
18
	 }
19
	 
20
	  if(window.check_version)
21
	  plus.runtime.getProperty(plus.runtime.appid,function(inf){
22
			    wgtVer=inf.version;
23
			    console.log("当前应用版本:"+wgtVer);
24
			    mui.ajax(baseUrl + "/data/manager/version.json", {
25
					dataType: 'json', //数据格式类型
26
					type: 'GET', //http请求类型
27
					timeout: 10000, //超时设置
28
					async: false,
29
					success: function(data) {
30
						// window.check_version=3;
31
						if (data.version > wgtVer) {
32
							var btn = ["立即更新", "稍后更新"];
33
							mui.confirm("新版本上线了,为了不影响您的正常使用,赶快更新吧", "提示", btn, function(e) {
34
								if(e.index == 0) {
35
									if(mui.os.ios) {
36
										plus.runtime.openURL('https://itunes.apple.com/cn/app/ke-xiu-da-jian-qi-ye-yu-zhuan/id1197110983?l=en&mt=8');
37
										return;
38
									}
39
								try {
40
									     plus.nativeUI.showWaiting("正在下载...");
41
									     //var d="http://192.168.3.233/download/app1.0.6.apk";
42
										 plus.downloader.createDownload( data.wgt, {filename:"_doc/update/"}, function(d,status){
43
									        if ( status == 200 ) { 
44
									            plus.runtime.install(d.filename, {}, function() {
45
													console.log("安装新版本文件成功!");
46
													/*plus.nativeUI.alert("应用资源更新完成,程序需要立即重启", function() {
47
														plus.runtime.restart();
48
													});*/
49
												}, function(e) {
50
													console.log("安装新版文件失败[" + e.code + "]:" + e.message);
51
													plus.nativeUI.toast("安装新版文件失败[" + e.code + "]:" + e.message);
52
												});
53
									            
54
									        } else {
55
									            console.log("下载新版本失败!");
56
									            plus.nativeUI.toast("下载新版本失败!");
57
									        }
58
							       			plus.nativeUI.closeWaiting();
59
							    		}).start();
60
						    		} catch (e) {
61
										console.log(e.message);
62
									}	
63
								}
64
							});
65
						}else{
66
							//plus.nativeUI.toast("您使用的是最新版本,请放心使用!", toastStyle);
67
						}
68
					},
69
					error: function() {
70
						plus.nativeUI.toast("服务器链接超时", toastStyle);
71
						return;
72
					}
73
				});
74
			});
75
			}else{
76
				checkVersion();
77
			}
78
}, false)
79
})
15 80
function orName() {
16 81
	mui.ajax(baseUrl + "/ajax/professor/baseInfo/" + plus.storage.getItem('userid'), {
17 82
		dataType: 'json', //数据格式类型

+ 5 - 4
app/js/public/base.js

@ -1,8 +1,8 @@
1 1
//公共文件
2 2
mui.init();
3 3
//var baseUrl = "http://www.ekexiu.com", 
4
//var baseUrl = "http://192.168.3.233",
5
var baseUrl = "http:192.168.3.233:81",    
4
var baseUrl = "http://192.168.3.233",
5
//var baseUrl = "http:192.168.3.233:81",    
6 6
	toastStyle = {
7 7
		'verticalAlign': 'top',
8 8
	}
@ -392,7 +392,7 @@ function cancelCollectionAbout(watchObject,sel, num,flag) {
392 392

393 393
}
394 394
function checkVersion(){
395
		mui.plusReady(function(){
395
		//mui.plusReady(function(){
396 396
			if(!plus.webview.currentWebview()) return;
397 397
			// 获取本地应用资源版本号
398 398
		    plus.runtime.getProperty(plus.runtime.appid,function(inf){
@ -448,7 +448,8 @@ function checkVersion(){
448 448
					}
449 449
				});
450 450
			});
451
		})
451
			
452
		//})
452 453
	}
453 454
function wlog(dt, id, src) {
454 455
	var src = src || "1";