App.vue
<script>
import interfaces from "utils/api.js"
export default {
onLaunch: function() {
console.log('App Launch')
this.getNewVersion();
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
},
globalData: {
requestUrl: "http://xxxxxxx",
userInfo: null,
timer: null
},
methods: {
getNewVersion() {
let self = this;
this.http({
url: interfaces.getNewVersion,
showLoading: false,
callback: (res) => {
console.log(res.data)
let newVersion = res.data.Data;
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
console.log(inf)
if (Number(inf.versionCode) < newVersion.VersionCode) {
uni.showModal({
content: '检测到新版本,是否更新?',
success: showResult => {
if (showResult.confirm) {
let url=newVersion.Domain+newVersion.Url;
var dtask = plus.downloader.createDownload(url, {},
function(d, status) {
// 下载完成
if (status == 200) {
plus.runtime.install(plus.io.convertLocalFileSystemURL(
d.filename
), {}, {},
function(error) {
uni.showToast({
title: '安装失败',
mask: false,
duration: 1500
});
})
} else {
uni.showToast({
title: '更新失败',
mask: false,
duration: 1500
});
}
});
dtask.start();
}
}
});
}
});
}
})
}
}
}
</script>
<style>
/*每个页面公共css */
</style>