代码拉取完成,页面将自动刷新
<script>
import {
getToken
} from '@/utils/auth.js';
import {
Update
} from "@/api/user.js"
export default {
onLaunch: function() {
console.log('App Launch')
plus.navigator.closeSplashscreen();
// console.log('App Launch');
// app启动时打开启动广告页
var w = plus.webview.open('hybrid/html/advertise/advertise.html', '本地地址', {
top: 0,
bottom: 0,
zindex: 999
}, 'fade-in', 5);
//设置定时器,4s后关闭启动广告页
setTimeout(function() {
plus.webview.close(w);
}, 15000);
let haveToken = getToken()
// #ifdef APP-PLUS
// token标志来判断
if (haveToken) {
//存在则关闭启动页进入首页
plus.navigator.closeSplashscreen();
} else {
//不存在则跳转至登录页
uni.reLaunch({
url: "/pages/login/index",
success: () => {
plus.navigator.closeSplashscreen();
}
})
}
// #endif
// this.plusReady()
},
methods: {
// 获取当前版本号
plusReady() {
var that = this;
// 获取本地应用资源版本号
plus.runtime.getProperty(plus.runtime.appid, function(inf) {
// console.log(inf, 111111111)
that.AndroidCheckUpdate(inf.version)
uni.setStorageSync('version', inf.version)
});
},
// 自动更新
AndroidCheckUpdate(ver) {
var that = this;
Update(ver).then(res => {
// console.log(1232, res);
if (res.version > ver) {
uni.setStorageSync('isNew', true)
uni.showModal({
title: '',
content: '检测到有新版本可升级,是否更新',
confirmText: '更新',
confirmColor: '#EE8F57',
success: function(res2) {
if (res2.confirm) {
uni.setStorageSync('version', res.version)
if (uni.getSystemInfoSync().platform == 'android') {
that.doUpData(res.androidUrl)
} else if (uni.getSystemInfoSync().platform == 'ios') {
that.doUpData(res.iosUrl)
}
}
}
});
} else {
uni.setStorageSync('isNew', false)
// console.log("已是最新版本");
}
})
},
doUpData(urls) {
uni.showLoading({
title: '正在更新中……'
})
uni.downloadFile({ //执行下载
url: urls,
success: downloadResult => { //下载成功
if (downloadResult.statusCode === 200) {
uni.showModal({
title: '',
content: '更新成功,重启使用新版本',
confirmText: '重启',
confirmColor: '#EE8F57',
success: function(res) {
if (res.confirm) {
plus.runtime.install( //安装
downloadResult.tempFilePath, {
force: true
},
function() {
utils.showToast('更新成功,重启中');
plus.runtime.restart();
},
function(e) {
utils.showToast('更新失败');
}
);
}
}
});
} else {
uni.showLoading({
title: '更新失败,请联系管理员'
})
}
},
complete: () => {
uni.hideLoading();
}
});
},
},
onShow: function() {
console.log('App Show')
},
onHide: function() {
console.log('App Hide')
}
}
</script>
<style>
/*每个页面公共css */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。