修复一些问题

This commit is contained in:
李琦
2026-07-08 08:18:02 +08:00
parent 41e56b3be6
commit 497d0a840f
43 changed files with 1078 additions and 554 deletions

View File

@@ -15,10 +15,39 @@ interface MenuButtonInfo {
}
// 全局单例状态(避免重复计算)
const systemBarHeight = ref(0)
const systemInfo = ref<UniApp.GetSystemInfoResult | null>(null)
const menuButtonInfo = ref<MenuButtonInfo | null>(null)
const isInitialized = ref(false)
/**
* 将状态栏高度注入全局 CSS 变量 --status-bar-height
* APP/H5 端页面依赖此变量计算导航栏 padding
*/
function injectStatusBarCSS(height: number) {
const px = `${height}px`
systemBarHeight.value = height
// #ifdef H5
if (typeof document !== 'undefined') {
document.documentElement.style.setProperty('--status-bar-height', px)
}
// #endif
// #ifdef APP-PLUS
if (typeof document !== 'undefined') {
document.documentElement.style.setProperty('--status-bar-height', px)
}
// #endif
// #ifdef MP-WEIXIN
// 微信小程序框架会注入,此处同步写入以便自定义导航栏一致
if (typeof document !== 'undefined') {
document.documentElement.style.setProperty('--status-bar-height', px)
}
// #endif
}
/**
* 初始化安全区域数据
*/
@@ -26,8 +55,11 @@ function initSafeArea() {
if (isInitialized.value) return
try {
// 获取系统信息
systemInfo.value = uni.getSystemInfoSync()
const barHeight = systemInfo.value.statusBarHeight || 0
// 非 MP 端若获取失败,使用 20px 兜底(iPhone 通常 44-47px)
const effectiveHeight = barHeight > 0 ? barHeight : 20
injectStatusBarCSS(effectiveHeight)
// #ifdef MP-WEIXIN
// 获取微信小程序胶囊按钮位置信息
@@ -56,9 +88,12 @@ function initSafeArea() {
export function useSafeArea() {
// 状态栏高度
const statusBarHeight = computed(() => {
return systemInfo.value?.statusBarHeight || 0
return systemInfo.value?.statusBarHeight || systemBarHeight.value || 20
})
/** 状态栏高度 CSS 值,供页面 :style 绑定 */
const statusBarHeightPx = computed(() => `${statusBarHeight.value}px`)
// 导航栏内容高度(不含状态栏)
const navBarContentHeight = computed(() => {
// #ifdef MP-WEIXIN
@@ -124,6 +159,7 @@ export function useSafeArea() {
systemInfo,
menuButtonInfo,
statusBarHeight,
statusBarHeightPx,
navBarContentHeight,
navBarTotalHeight,
menuButtonRight,