<script>
var api = require("utils/api.js");
export default {
data() {
return {
user:'',
version: '4400',
iosversion: '4400',
};
},
methods: {
AndroidCheckUpdate(){
var _this=this;
var server = api.host + "/index.php/index/index/getversions" //更新
uni.request({
url: server,
method: 'GET',
data: {},
success: res => {
console.log("版本号res: " + JSON.stringify(res));
if(res.data.data.version != this.version){
// if(plus.networkinfo.getCurrentType()!=3){
// uni.showToast({
// title: '有新的版本发布,检测到您目前非Wifi连接,为节约您的流量,程序已停止自动更新,将在您连接WIFI之后重新检测更新。',
// mask: false,
// duration: 5000,
// icon:"none"
// });
// return;
// }
uni.showToast({
title: '有新的版本发布,程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
mask: false,
duration: 5000,
icon:"none"
});
setTimeout(function(){
var dtask = plus.downloader.createDownload( res.data.data.url,
{ filename: '_doc/update/' + new Date().getTime() + '/' }
, function ( d, status ) {
// 下载完成
if ( status == 200 ) {
plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename),{force:true},function(e){
uni.showModal({
title: '',
content: '更新成功,是否重启?(部分功能重启后生效)',
confirmText: '重启',
confirmColor: '#be141c',
success: function(res) {
if (res.confirm) {
plus.runtime.restart();
}
}
});
},function(error){
console.error("安装失败:", JSON.stringify(error));
uni.showToast({
title: '安装失败',
icon:'none',
duration: 1500
});
// uni.showToast({
// title: error.message,
// mask: false,
// duration: 5000,
// icon:"none"
// });
})
} else {
uni.showToast({
title: '更新失败',
mask: false,
duration: 1500
});
}
});
dtask.start();
},2000)
}
},
fail: () => {},
complete: () => {}
});
},
},
onLaunch: function() {
uni.getSystemInfo({
success:(res) => {
console.log("检测版本",res.platform);
//检测当前平台,如果是安卓则启动安卓更新
if(res.platform=="android"){
this.AndroidCheckUpdate();
} else{
// 检测版本更新
//#ifdef APP-PLUS
var server = api.host + "/index.php/index/index/getversionsios"; //检查更新地址
// var req = { //升级检测数据
// "appid": plus.runtime.appid,
// "version": plus.runtime.version
// };
// console.log("这习惯",server)
uni.request({
url: server,
data: {},
success: (res) => {
console.log('ios更新',res)
if(res.data.data.version != this.iosversion){
// if(plus.networkinfo.getCurrentType()!=3){
// uni.showToast({
// title: '有新的版本发布,检测到您目前非Wifi连接,为节约您的流量,程序已停止自动更新,将在您连接WIFI之后重新检测更新。',
// mask: false,
// duration: 5000,
// icon:"none"
// });
// return;
// }
uni.showToast({
title: '有新的版本发布,程序已启动自动更新。新版本下载完成后将自动弹出安装程序。',
mask: false,
duration: 5000,
icon:"none"
});
uni.downloadFile({
url: res.data.data.url,
success: (downloadResult) => {
if (downloadResult.statusCode === 200) {
uni.showToast({
title: '下载成功安装中',
mask: false,
duration: 2000
});
plus.runtime.install(downloadResult.tempFilePath, {
force: true
}, function() {
console.log('install success...');
// uni.showToast({
// title: '安装成功',
// mask: false,
// duration: 2000
// });
uni.showModal({
title: '',
content: '更新成功,是否重启?(部分功能重启后生效)',
confirmText: '重启',
confirmColor: '#be141c',
success: function(res) {
if (res.confirm) {
plus.runtime.restart();
}
}
});
}, function(e) {
console.error('install fail...');
uni.showToast({
title: '安装失败',
mask: false,
duration: 1500
});
});
}
}
});
}
}
})
//#endif
}
}
})
plus.runtime.getProperty(plus.runtime.appid, function (info) {
console.log('当前版本', info.version); // 如 1.0.44
console.log('当前版本code', info.versionCode); // 如 4400
console.log("当前 AppID:", info.appid);
});
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>