Browse Source

新增检查新版本功能

xuchunyang 8 years ago
parent
commit
45d06bad08
2 changed files with 69 additions and 1 deletions
  1. 8 0
      app/html/setup.html
  2. 61 1
      app/js/setup.js

+ 8 - 0
app/html/setup.html

63
				        </a>
63
				        </a>
64
				    </li>
64
				    </li>
65
				    
65
				    
66
				    <li class="mui-table-view-cell">
67
				        <a class="mui-navigate-right" id="checkNewVersion">
68
				        	<span class="mui-pull-left">检查新版本</span>
69
				        </a>
70
				    </li>
71
				    
66
				</ul>
72
				</ul>
73
				
67
		    </div>
74
		    </div>
75
		    
68
		    <div class="mui-input-group exitbox">
76
		    <div class="mui-input-group exitbox">
69
				<span class="exitbtn" id="removeid">退出登录</span>
77
				<span class="exitbtn" id="removeid">退出登录</span>
70
		    </div>
78
		    </div>

+ 61 - 1
app/js/setup.js

7
	var userAgreement = document.getElementById("userAgreement");
7
	var userAgreement = document.getElementById("userAgreement");
8
	var about = document.getElementById("about");
8
	var about = document.getElementById("about");
9
	var kefu = document.getElementById("kefu");
9
	var kefu = document.getElementById("kefu");
10
	
10
	var checkNewVersion = document.getElementById("checkNewVersion");
11
	
11
	
12
	/*账户与安全*/
12
	/*账户与安全*/
13
	security.addEventListener('tap',function(){
13
	security.addEventListener('tap',function(){
74
		
74
		
75
	});
75
	});
76
	
76
	
77
	/*检查新版本*/
78
	checkNewVersion.addEventListener('tap',function(){
79
		checkVersion();	
80
	});
81
	
82
	function checkVersion(){
83
		mui.plusReady(function(){
84
			// 获取本地应用资源版本号
85
		    plus.runtime.getProperty(plus.runtime.appid,function(inf){
86
			    wgtVer=inf.version;
87
			    console.log("当前应用版本:"+wgtVer);
88
			    mui.ajax(baseUrl + "/data/manager/version.json", {
89
					dataType: 'json', //数据格式类型
90
					type: 'GET', //http请求类型
91
					timeout: 10000, //超时设置
92
					async: false,
93
					success: function(data) {
94
						console.log(JSON.stringify(data));
95
						if (data.version > wgtVer) {
96
							var btn = ["确定更新", "取消更新"];
97
							mui.confirm("检测到新版本,是否更新?", "提示", btn, function(e) {
98
								if(e.index == 0) {
99
								try {
100
									     plus.nativeUI.showWaiting("检测更新...");
101
									     //var d="http://192.168.3.233/download/app1.0.6.apk";
102
										 plus.downloader.createDownload( data.wgt, {filename:"_doc/update/"}, function(d,status){
103
									        if ( status == 200 ) { 
104
									            plus.runtime.install(d.filename, {}, function() {
105
													console.log("安装新版本文件成功!");
106
													/*plus.nativeUI.alert("应用资源更新完成,程序需要立即重启", function() {
107
														plus.runtime.restart();
108
													});*/
109
												}, function(e) {
110
													console.log("安装新版文件失败[" + e.code + "]:" + e.message);
111
													plus.nativeUI.toast("安装新版文件失败[" + e.code + "]:" + e.message);
112
												});
113
									            
114
									        } else {
115
									            console.log("下载新版本失败!");
116
									            plus.nativeUI.toast("下载新版本失败!");
117
									        }
118
							       			plus.nativeUI.closeWaiting();
119
							    		}).start();
120
						    		} catch (e) {
121
										console.log(e.message);
122
									}	
123
								}
124
							});
125
						}else{
126
							plus.nativeUI.toast("您使用的是最新版本,请放心使用!", toastStyle);
127
						}
128
					},
129
					error: function() {
130
						plus.nativeUI.toast("服务器链接超时", toastStyle);
131
						return;
132
					}
133
				});
134
			});
135
		})
136
	}
77
	
137
	
78
	
138
	
79
});
139
});