Files
test/utils/system.js

45 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//获取状态栏高度
const SYSTEM_INFO = uni.getSystemInfoSync();
// 获取高度失败的话就返回默认值 0
// 获取状态栏高度
export const getStatusBarHeight = ()=> SYSTEM_INFO.statusBarHeight || 0
//获取预览页面的状态栏
export const getPreviewBarHeight = ()=>{
// 下面是获取胶囊按钮全部信息
// let MENU_BUTTON = uni.getMenuButtonBoundingClientRect();
//如果有胶囊按钮,我们才进行操作,否则返回一个固定的值
if(uni.getMenuButtonBoundingClientRect){
//我们使用解构的方法来选取所需的特定内容就可以了
let {top} = uni.getMenuButtonBoundingClientRect();
// 标题栏的高度
let PreviewBarHeight = top
return PreviewBarHeight
}
else{
return 40;
}
}
//获取标题栏高度
export const getTitleBarHeight = ()=>{
// 下面是获取胶囊按钮全部信息
// let MENU_BUTTON = uni.getMenuButtonBoundingClientRect();
//如果有胶囊按钮,我们才进行操作,否则返回一个固定的值
if(uni.getMenuButtonBoundingClientRect){
//我们使用解构的方法来选取所需的特定内容就可以了
let {top,height} = uni.getMenuButtonBoundingClientRect();
// 标题栏的高度
let titleBarHeight = (top - getStatusBarHeight())*2 + height
return titleBarHeight
}
else{
return 40;
}
}
//获取整个导航栏高度用于fill栏
export const getNavBarHeight = ()=> getTitleBarHeight() + getStatusBarHeight();