// 小程序自定义导航头部避让工具 // env(safe-area-inset-top) 在开发者工具模拟器/部分安卓机返回 0,不可靠; // 改用胶囊按钮实测位置(getMenuButtonBoundingClientRect)计算顶部内边距。 // 用法:const headPad = mpHeadPad(),绑定到头部元素 :style="headPad" export function mpHeadPad(extra = 8) { // #ifdef MP-WEIXIN try { const mb = uni.getMenuButtonBoundingClientRect() if (mb && mb.bottom > 0) { return { paddingTop: mb.bottom + extra + 'px' } } } catch (e) { // 取不到胶囊时回退 CSS 值 } // #endif return {} }