2 Star 0 Fork 0

半夏 / xingqi

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
App.vue 3.32 KB
一键复制 编辑 原始数据 按行查看 历史
肖扬豪 提交于 2022-08-02 11:59 . ..
<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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/cailan/xingqi.git
git@gitee.com:cailan/xingqi.git
cailan
xingqi
xingqi
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891