mirror of
https://gitee.com/TSpecific/tuniao-ui.git
synced 2026-03-07 08:14:01 +08:00
减少App.vue的代码依赖,优化获取顶部自定义导航栏的高度信息
This commit is contained in:
71
App.vue
71
App.vue
@@ -1,79 +1,8 @@
|
||||
<script>
|
||||
import Vue from 'vue'
|
||||
import store from './store/index.js'
|
||||
import updateCustomBarInfo from './tuniao-ui/libs/function/updateCustomBarInfo.js'
|
||||
|
||||
export default {
|
||||
onLaunch: function() {
|
||||
uni.getSystemInfo({
|
||||
success: function(e) {
|
||||
// #ifndef H5
|
||||
// 获取手机系统版本
|
||||
const system = e.system.toLowerCase()
|
||||
const platform = e.platform.toLowerCase()
|
||||
// 判断是否为ios设备
|
||||
if (platform.indexOf('ios') != -1 && (system.indexOf('ios') != -1 || system.indexOf('macos') != -1)) {
|
||||
Vue.prototype.SystemPlatform = 'apple'
|
||||
} else if (platform.indexOf('android') != -1 && (system.indexOf('android') != -1)) {
|
||||
Vue.prototype.SystemPlatform = 'android'
|
||||
} else {
|
||||
Vue.prototype.SystemPlatform = 'devtools'
|
||||
}
|
||||
// #endif
|
||||
}
|
||||
})
|
||||
|
||||
// 获取设备的状态栏信息和自定义顶栏信息
|
||||
// store.dispatch('updateCustomBarInfo')
|
||||
updateCustomBarInfo().then((res) => {
|
||||
store.commit('$tStore', {
|
||||
name: 'vuex_status_bar_height',
|
||||
value: res.statusBarHeight
|
||||
})
|
||||
store.commit('$tStore', {
|
||||
name: 'vuex_custom_bar_height',
|
||||
value: res.customBarHeight
|
||||
})
|
||||
})
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
//更新检测
|
||||
if (wx.canIUse('getUpdateManager')) {
|
||||
const updateManager = wx.getUpdateManager();
|
||||
updateManager && updateManager.onCheckForUpdate((res) => {
|
||||
if (res.hasUpdate) {
|
||||
updateManager.onUpdateReady(() => {
|
||||
uni.showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备就绪,是否需要重新启动应用?',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
uni.clearStorageSync() // 更新完成后刷新storage的数据
|
||||
updateManager.applyUpdate()
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
updateManager.onUpdateFailed(() => {
|
||||
uni.showModal({
|
||||
title: '已有新版本上线',
|
||||
content: '小程序自动更新失败,请删除该小程序后重新搜索打开哟~~~',
|
||||
showCancel: false
|
||||
})
|
||||
})
|
||||
} else {
|
||||
//没有更新
|
||||
}
|
||||
})
|
||||
} else {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '当前微信版本过低,无法使用该功能,请更新到最新的微信后再重试。',
|
||||
showCancel: false
|
||||
})
|
||||
}
|
||||
// #endif
|
||||
},
|
||||
onShow: function() {
|
||||
// console.log('App Show')
|
||||
|
||||
@@ -175,16 +175,7 @@
|
||||
},
|
||||
mounted() {
|
||||
// 获取vuex中的自定义顶栏的高度
|
||||
let customBarHeight = this.vuex_custom_bar_height
|
||||
let statusBarHeight = this.vuex_status_bar_height
|
||||
// 如果获取失败则重新获取
|
||||
if (!customBarHeight) {
|
||||
this.$t.updateCustomBar()
|
||||
customBarHeight = this.vuex_custom_bar_height
|
||||
statusBarHeight = this.vuex_status_bar_height
|
||||
}
|
||||
this.customBarHeight = customBarHeight
|
||||
this.statusBarHeight = statusBarHeight
|
||||
this.updateNavBarInfo()
|
||||
},
|
||||
created() {
|
||||
// 获取胶囊信息
|
||||
@@ -196,6 +187,32 @@
|
||||
// #endif
|
||||
},
|
||||
methods: {
|
||||
// 更新导航栏的高度
|
||||
async updateNavBarInfo() {
|
||||
// 获取vuex中的自定义顶栏的高度
|
||||
let customBarHeight = this.vuex_custom_bar_height
|
||||
let statusBarHeight = this.vuex_status_bar_height
|
||||
// 如果获取失败则重新获取
|
||||
if (!customBarHeight) {
|
||||
try {
|
||||
const navBarInfo = await this.$t.updateCustomBar()
|
||||
customBarHeight = navBarInfo.customBarHeight
|
||||
statusBarHeight = navBarInfo.statusBarHeight
|
||||
} catch(e) {
|
||||
setTimeout(() => {
|
||||
this.updateNavBarInfo()
|
||||
}, 10)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 更新vuex中的导航栏信息
|
||||
this && this.$t.vuex('vuex_status_bar_height', statusBarHeight)
|
||||
this && this.$t.vuex('vuex_custom_bar_height', customBarHeight)
|
||||
|
||||
this.customBarHeight = customBarHeight
|
||||
this.statusBarHeight = statusBarHeight
|
||||
},
|
||||
// 处理返回事件
|
||||
async handlerBack() {
|
||||
if (this.beforeBack && typeof(this.beforeBack) === 'function') {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/**
|
||||
* 更新自定义顶部导航栏的高度
|
||||
*/
|
||||
async function updateCustomBarInfo () {
|
||||
return await new Promise((resolve, reject) => {
|
||||
function updateCustomBarInfo () {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.getSystemInfo({
|
||||
success: (e) => {
|
||||
let statusBarHeight = 0
|
||||
@@ -27,8 +27,6 @@ async function updateCustomBarInfo () {
|
||||
statusBarHeight = e.statusBarHeight
|
||||
customBarHeight = e.statusBarHeight + e.titleBarHeight
|
||||
// #endif
|
||||
this && this.$t.vuex('vuex_status_bar_height', statusBarHeight)
|
||||
this && this.$t.vuex('vuex_custom_bar_height', customBarHeight)
|
||||
resolve({
|
||||
statusBarHeight,
|
||||
customBarHeight
|
||||
@@ -36,8 +34,6 @@ async function updateCustomBarInfo () {
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("获取设备信息失败", err);
|
||||
this && this.$t.vuex('vuex_status_bar_height', 0)
|
||||
this && this.$t.vuex('vuex_custom_bar_height', 0)
|
||||
reject()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user