版本控制客户端代码
/**
* 检查服务器的程序版本
* @param that vue对象
*/
function checkVersion(that){
var version = VERSION;
var baseVersion = plus.runtime.version;
wt.request(API_HOST+'index.php/Index/checkVersion',{
version:version,
baseVersion:baseVersion
},function(response){
if(response.status == "0"){
that.$messagebox.alert(response.msg).then(function(){
if(response.url && response.url != "") {
plus.runtime.openURL( response.url );
}
});
return;
}else if(response.url && response.url != ""){
that.$messagebox.confirm('', {
message: '系统检测到有新版本,是否更新',
title: '提示',
confirmButtonText: '确认',
cancelButtonText: '取消'
}).then(function(action){
that.$data.showload=true;
var timestamp = (new Date()).valueOf();
var downLoader = plus.downloader.createDownload(response.url, {
method: 'GET',
filename: '_downloads/' + timestamp + '.wgt'
}, function(download, status) {
var fileName = download.filename;
that.$indicator.close();
installWgt(fileName);
});
downLoader.addEventListener("statechanged",function(task,status) {
switch(task.state) {
case 3: // 已接收到数据
that.$data.loadmsg=changeSize(task.downloadedSize) + '/' + changeSize(task.totalSize);
break;
case 4: // 下载完成
stop();
break;
}
});
try{
downLoader.start();
}catch(e){
//TODO handle the exception
that.$toast("稍后下载");
}
}).catch(function(err) {
if (err == 'cancel') { //取消的回调
}
}) ;
}
},function(error){
});
}
服务端PHP代码
//APP当前版本
define("APP_VERSION","1.3.0");
define("APP_BASIC_VERSION","1.3.0"); //基础版本号 升级包时此处不变
//比对客户端的APP版本和服务器的当前APP版本
public function checkVersion(){
$postData = $this->request->post();
if(!isset($postData['baseVersion']) || $postData['baseVersion'] != APP_BASIC_VERSION){
return error("请前往官网下载最新的APP","http://xxxx/web/pages/index/download.html");
}
$version = isset($postData['version'])?$postData['version']:"-1";
Session::set("version",$version);
Cookie::set("cookie", '1');
if(version_compare($version,APP_VERSION) < 0){
return success("需要更新版本","http://xxxx/wgt/".APP_VERSION.".wgt");
}else{
return success("当前是最新版本了");
}
}