onLaunch
<script>
export default {
globalData: {
userCode: uni.getStorageSync('user').code
},
onLaunch: function() {
uni.request({
url: 'http://192.168.3.139:9301/' + 'version/check',
data: {},
method: 'GET',
header: {
'appVersion': plus.runtime.version,
'platform': '1',
'Content-type': 'application/json'
},
success: res => {
console.log(res)
if (res.data.code == 200 && res.data.data.fileUrl) {
uni.showModal({
title: '检测到新版本!',
content: res.data.data.versiondesc,
success: res1 => {
if (res1.confirm) {
var dtask = plus.downloader.createDownload(
res.data.data.fileUrl, {},
function(d, status) {
if (status == 200) {
var fileSaveUrl = plus.io.convertLocalFileSystemURL(d.filename);
plus.runtime.openFile(d.filename);
} else {
plus.downloader.clear();
}
});
dtask.start();
var prg = 0;
var showLoading = plus.nativeUI.showWaiting('正在下载');
dtask.addEventListener('statechanged', (task, status) => {
{
switch (task.state) {
case 1:
showLoading.setTitle("正在下载");
break;
case 2:
showLoading.setTitle("已连接到服务器");
break;
case 3:
prg = parseInt(
(parseFloat(task.downloadedSize) /
parseFloat(task.totalSize)) *
100
);
showLoading.setTitle('正在下载' + prg + '%');
break;
case 4:
plus.nativeUI.closeWaiting();
break;
}
}
})
} else if (res1.cancel) {
if (res.data.data.coerce == 1) {
plus.runtime.quit();
} else {
uni.showToast({
title: '取消更新',
mask: true,
icon: 'none'
})
}
}
}
})
}
}
})
},
onShow: function() {},
onHide: function() {
console.log('App Hide');
}
}
</script>