128 Star 1.1K Fork 472

进击的皇虫 / BookChatApp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
App.vue 2.72 KB
一键复制 编辑 Web IDE 原始数据 按行查看 历史
进击的皇虫 提交于 2021-01-11 23:39 . 小程序升级检测
<script>
import config from 'config.js'
import util from 'utils/util.js'
export default {
onLaunch: function() {
let info = uni.getSystemInfoSync()
info.versionCode = 0
info.version = config.info.version
info.appVersion = config.info.version
info.bookshelfChanged = false
if (info.model && info.model.indexOf('iPhone') !== -1) {
info.titleBarHeight = 44
} else {
info.titleBarHeight = 48
}
// 新版小程序升级检测
// #ifdef MP-WEIXIN
if (uni.canIUse('getUpdateManager')) {
const updateManager = uni.getUpdateManager()
updateManager.onCheckForUpdate(function(res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function() {
uni.showModal({
title: '升级提示',
content: '新版本已经为您准备就绪,是否升级应用?',
success: function(res) {
if (res.confirm) updateManager.applyUpdate()
}
})
})
}
})
}
// #endif
// #ifdef APP-PLUS
// 查询版本信息
plus.runtime.getProperty(plus.runtime.appid, function(wgtInfo) {
info.versionCode = wgtInfo.versionCode
info.version = wgtInfo.version
// 如果是Android平台,则检测是否有新版本
if (String(info.platform).toLowerCase() == "android") {
if (config.debug) console.log("request version api", config.api.lastestVersion)
util.request(config.api.lastestVersion).then(function(res) {
if (config.debug) console.log("latest version:", res)
if (res && res.data && res.data.version) {
if (config.debug) console.log("当前版本", info.versionCode, "最新版本", res.data.version)
if (info.versionCode < res.data.version) {
uni.showModal({
title: "温馨提示",
content: "发现新版本APP,您是否要升级体验?",
cancelText: "暂时忽略",
confirmText: "码上升级",
success: (action) => {
if (action.confirm) {
if (config.debug) console.log('用户点击确定');
plus.runtime.openURL(res.data.url)
} else if (res.cancel) {
if (config.debug) console.log('用户点击取消');
}
}
})
}
}
}).catch(function(e) {
console.log(e)
})
}
});
// #endif
if (config.debug) {
console.log(info)
console.log('platform', info.platform)
}
util.setSysInfo(info)
},
onShow: function() {
if (config.debug) console.log('App Show')
},
onHide: function() {
if (config.debug) console.log('App Hide')
},
}
</script>
<style>
/*每个页面公共css */
@import url("static/css/bookchat.css");
</style>
JavaScript
1
https://gitee.com/truthhun/BookChatApp.git
git@gitee.com:truthhun/BookChatApp.git
truthhun
BookChatApp
BookChatApp
master

搜索帮助

14c37bed 8189591 565d56ea 8189591