//判断版本大小
checkPlugin(a,b) {
var that =this
var a= that.toNum(a);
var b= that.toNum(b);
console.log(a,b)
if(a==b){
console.log("版本号相同!版本号为:"+a);
}else if(a>b){
plus.nativeUI.confirm( "当前有新版本是否更新?", e=>{
if(e.index===0){
console.log("没有执行")
that.downWgt()
}
console.log(e, (e.index==0)?"Yes!":"No!" );
}, "版本更新", ["确定","取消"] );
console.log("版本号a"+a+"是新版本!");
}else{
console.log("版本号b"+b+"是新版本!");
}
},
toNum(a){
var a=a.toString();
var c=a.split('.');
var num_place=["","0","00","000","0000"],r=num_place.reverse();
for (var i=0;i<c.length;i++){
var len=c[i].length;
c[i]=r[len]+c[i];
}
var res= c.join('');
return res;
} ,
//得到要安装的版本号
getVersion() {
var that =this;
var loginMark= localStorage.getItem("loginMark")
var token= localStorage.getItem("token")
this.$http.get("xxxxxxx",{
params: {
'loginMark':loginMark,
'token':token
}
}).then((res) => {
that.MYversion=res.data.data.F_EditionNumber;
that.wgtUrl=res.data.data.F_DownloadSiteWGT;
console.log( that.MYversion, 'ASDSADAS' , that.wgtUrl,"版本")
if(window.plus){
plus.runtime.getProperty(plus.runtime.appid,function(inf){
var wgtVer=inf.version;
console.log("当前应用版本:"+wgtVer);
that.checkPlugin(that.MYversion,wgtVer)
});
}
}).catch((error) => {
console.warn(error)
})
},
//安装
downWgt(){
var that=this;
plus.nativeUI.showWaiting("自动更新中,请勿退出");
plus.downloader.createDownload(this.wgtUrl, {filename:"_doc/update/"}, function(d,status){
console.log(d,status)
if ( status == 200 ) {
console.log("下载wgt成功:"+d.filename);
that.installWgt(d.filename); // 安装wgt包
} else {
console.log("下载wgt失败!");
plus.nativeUI.alert("自动更新失败,请联系管理员");
}
plus.nativeUI.closeWaiting();
}).start();
},
installWgt(path){
plus.nativeUI.showWaiting("安装中...");
plus.runtime.install(path,{},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("自动更新失败,请联系管理员["+e.code+"]:"+e.message);
})
},