mirror of
https://gitee.com/TSpecific/tuniao-ui.git
synced 2026-03-12 18:44:01 +08:00
减少App.vue的代码依赖,优化获取顶部自定义导航栏的高度信息
This commit is contained in:
@@ -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