更改动态导航栏

This commit is contained in:
wwz
2025-02-08 09:16:43 +08:00
parent 20b5539a82
commit 5add1f1282
33 changed files with 21325 additions and 72 deletions

44
stores/navbarStore.js Normal file
View 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; // 失败时设置一个默认高度
}
});
}
}
});