mui.plusReady(function() {
if(window.plus) {
plus.screen.lockOrientation('portrait-primary');
}
if(typeof plus != "undefined" && typeof plus.MinePlugin != 'undefined') {
if(plus.os.name == "iOS") {
go2Index();
} else {
go2Index();
/*plus.MinePlugin.getPermission([CAMERA, STORAGE, LOCATION],
function(msg) {
go2Index();
},
function(msg) {
plus.runtime.quit();
}
);*/
}
} else {
go2Index();
}
});
function go2Index() {
localStorage.setItem("serviceAddress", serviceAddress);
localStorage.setItem("indexPage", indexPage);
localStorage.setItem("loginPage", loginPage);
localStorage.setItem("updateClientPositionKey", updateClientPositionKey);
var loginInfo = localStorage.getItem("loginInfo");
console.log(loginInfo);
if(loginInfo) {
try {
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
console.log('=====================检测版本更新======================');
version = inf.version;
var url = localStorage.getItem("serviceAddress") + '/client/interface/1.0/checkappversion'
console.log(url);
var filetype = "appwgt";
loginInfo = loginInfo?$.parseJSON(loginInfo):{};
console.log(JSON.stringify(loginInfo));
var data = $.extend({version: version,filetype: filetype,appname:'bjhbapp',appid:'bjhbapp'}, loginInfo);
console.log(JSON.stringify(data));
mui.ajax(url, {
data: data,
dataType: 'json',
type: 'POST',
timeout: 10000,
success: function(result) {
if(result.SUCCESS) {
if(result.DATA && result.DATA.length == 1){
var data = result.DATA[0];
var url = localStorage.getItem("serviceAddress") + "/client/interface/1.0/speciafiledownload";
var params = loginInfo;
params.id = data.ID;
console.log("==================-----------------" + $.param(loginInfo));
url += "?id="+data.ID +"&"+ $.param(loginInfo);
console.log(url);
var fileName = "_doc/update/" + data.NAME;
var dtask = plus.downloader.createDownload(url, {method:"GET",filename:fileName}, function(d, status) {
console.log("status============================" + status);
if(status == 200) {
clearInterval(i);
console.log("正在准备环境,请稍后!");
var path = d.filename; //_downloads yijietong.apk
console.log(d.filename);
plus.runtime.install(path, {
force: true
}, function() {
//完成更新向服务器进行通知
console.log("更新完毕,将重启应用!");
plus.runtime.restart();
//window.location.href = indexPage;
}, function(err) {
//alert(JSON.stringify(err));
console.log("安装升级失败:" + JSON.stringify(err));
window.location.href = indexPage;
}); // 安装下载的apk文件
} else {
console.log('下载失败:' + status);
window.location.href = indexPage;
}
});
dtask.start();
var i = setInterval(function() {
var totalSize = dtask.totalSize;
var downloadedSize = dtask.downloadedSize;
console.log(downloadedSize);
console.log(totalSize);
}, 500); //1000为1秒钟
}else{
console.log("当前已是最新版本");
window.location.href = indexPage;
}
} else {
console.log(result.MSG);
window.location.href = indexPage;
}
},
error: function(xhr, type, errerThrown) {
console.log('网络异常,请稍候再试');
window.location.href = indexPage;
}
});
});
} catch(e){}
}else{
window.location.href = loginPage;
}
}
一键复制
编辑
Web IDE
原始数据
按行查看
历史