更改动态导航栏
This commit is contained in:
44
stores/navbarStore.js
Normal file
44
stores/navbarStore.js
Normal file
@@ -0,0 +1,44 @@
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
export const useNavbarStore = defineStore('navbar', {
|
||||
state: () => ({
|
||||
showBack: true,
|
||||
rightText: '',
|
||||
showSearch: false,
|
||||
title: '',
|
||||
isTransparent: false,
|
||||
height: 0,
|
||||
hasPlaceholder: true
|
||||
}),
|
||||
actions: {
|
||||
updateNavbarConfig(config) {
|
||||
Object.assign(this, config);
|
||||
},
|
||||
initNavbarHeight() {
|
||||
uni.getSystemInfo({
|
||||
success: (res) => {
|
||||
const statusBarHeight = res.statusBarHeight;
|
||||
let navBarHeight;
|
||||
|
||||
// 微信小程序的特殊处理
|
||||
if (res.platform === 'weapp') {
|
||||
const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
|
||||
const topGap = menuButtonInfo.top - statusBarHeight;
|
||||
const bottomGap = statusBarHeight + menuButtonInfo.height + topGap * 2 - (menuButtonInfo.top + menuButtonInfo.height);
|
||||
navBarHeight = menuButtonInfo.height + topGap + bottomGap;
|
||||
} else if (uni.getSystemInfoSync().platform === 'ios') {
|
||||
navBarHeight = 44;
|
||||
} else {
|
||||
navBarHeight = 48;
|
||||
}
|
||||
|
||||
this.height = statusBarHeight + navBarHeight;
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('获取系统信息失败:', err);
|
||||
this.height = 64; // 失败时设置一个默认高度
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user