- 统一定制顶部导航组件,支持沉浸式渐变主题与返回逻辑 - 适配 H5 环境的页面跳转逻辑,避免 reLaunch 导致的闪屏问题 - 重构会员、充值、发布等页面布局,改用 Grid 提升移动端适配 - 优化搜索、收藏、消息等页面交互细节,增加点击反馈 - 统一配置页面导航样式,替换原生导航为自定义组件
74 行
2.0 KiB
JavaScript
74 行
2.0 KiB
JavaScript
/**
|
|
* 顶部导航栏与胶囊避让度量工具
|
|
* 规范化统一各页面的 Topbar 状态栏高度、导航栏高度及微信小程序右上角胶囊避让
|
|
*/
|
|
|
|
/**
|
|
* 获取当前设备与平台环境下的导航栏尺寸度量
|
|
* @returns {Object} 包含 statusBarHeight, navBarHeight, capsulePadding, capsuleWidth, capsuleHeight, capsuleTop, totalHeight
|
|
*/
|
|
export function getNavMetrics() {
|
|
let statusBarHeight = 0
|
|
let navBarHeight = 44
|
|
let capsulePadding = 0
|
|
let capsuleWidth = 0
|
|
let capsuleHeight = 32
|
|
let capsuleTop = 6
|
|
let capsuleRight = 0
|
|
|
|
try {
|
|
// #ifdef H5
|
|
// 浏览器环境下通常无需模拟系统状态栏,状态栏高度置 0,导航栏高度固定 44px
|
|
statusBarHeight = 0
|
|
navBarHeight = 44
|
|
capsulePadding = 0
|
|
// #endif
|
|
|
|
// #ifndef H5
|
|
const sys = uni.getSystemInfoSync ? uni.getSystemInfoSync() : null
|
|
if (sys && sys.statusBarHeight) {
|
|
statusBarHeight = sys.statusBarHeight
|
|
}
|
|
|
|
// #ifdef MP-WEIXIN || MP
|
|
if (typeof uni.getMenuButtonBoundingClientRect === 'function') {
|
|
const menu = uni.getMenuButtonBoundingClientRect()
|
|
if (menu && menu.width && menu.top) {
|
|
capsuleWidth = menu.width
|
|
capsuleHeight = menu.height
|
|
capsuleTop = menu.top
|
|
const winWidth = (sys && sys.windowWidth) ? sys.windowWidth : 375
|
|
capsuleRight = winWidth - menu.right
|
|
// 右侧避让距离 = 胶囊宽度 + 胶囊右边距 + 左右视觉留白间隙(8px)
|
|
capsulePadding = (winWidth - menu.left) + 8
|
|
|
|
// 胶囊垂直居中时的标准导航条高度:上下边距对称 (menu.top - statusBarHeight) * 2 + menu.height
|
|
const barH = (menu.top - statusBarHeight) * 2 + menu.height
|
|
if (barH >= 38 && barH <= 64) {
|
|
navBarHeight = barH
|
|
}
|
|
} else {
|
|
capsulePadding = 96
|
|
}
|
|
}
|
|
// #endif
|
|
// #endif
|
|
} catch (e) {
|
|
capsulePadding = 0
|
|
}
|
|
|
|
return {
|
|
statusBarHeight,
|
|
navBarHeight,
|
|
capsulePadding,
|
|
capsuleWidth,
|
|
capsuleHeight,
|
|
capsuleTop,
|
|
totalHeight: statusBarHeight + navBarHeight,
|
|
}
|
|
}
|
|
|
|
export default {
|
|
getNavMetrics,
|
|
}
|