62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
interface SystemInfo {
|
|
statusBarHeight?: number;
|
|
[key: string]: any;
|
|
}
|
|
|
|
interface MenuButtonRect {
|
|
top: number;
|
|
height: number;
|
|
[key: string]: any;
|
|
}
|
|
|
|
interface LeftIcon {
|
|
left: string;
|
|
width: string;
|
|
}
|
|
|
|
const SYSTEM_INFO: SystemInfo = uni.getSystemInfoSync();
|
|
|
|
export const getStatusBarHeight = (): number => SYSTEM_INFO.statusBarHeight || 0;
|
|
|
|
export const getTitleBarHeight = (): number => {
|
|
if (uni.getMenuButtonBoundingClientRect) {
|
|
const { top, height }: MenuButtonRect = uni.getMenuButtonBoundingClientRect();
|
|
return height + (top - getStatusBarHeight()) * 2;
|
|
} else {
|
|
return 44;
|
|
}
|
|
}
|
|
|
|
export const getNavBarHeight = (): number => getStatusBarHeight() + getTitleBarHeight();
|
|
|
|
export const getLeftIconLeft = (): number => {
|
|
// #ifdef MP-TOUTIAO
|
|
const { leftIcon: { left, width } }: { leftIcon: LeftIcon } = tt.getCustomButtonBoundingClientRect();
|
|
return left + parseInt(width);
|
|
// #endif
|
|
|
|
// #ifndef MP-TOUTIAO
|
|
return 0;
|
|
// #endif
|
|
}
|
|
|
|
export const getNavbarHeight2 = () => {
|
|
const systemInfo = uni.getSystemInfoSync()
|
|
statusBarHeight.value = systemInfo.statusBarHeight || 0
|
|
|
|
let navBarHeight = 44
|
|
if (systemInfo.model.indexOf('iPhone') !== -1 && parseInt(systemInfo.model.slice(-2)) >= 11) {
|
|
navBarHeight = 48
|
|
}
|
|
|
|
const totalHeight = statusBarHeight.value + navBarHeight
|
|
navbarHeight.value = totalHeight + 'px'
|
|
}
|
|
|
|
/**
|
|
* 获取屏幕刘海高度
|
|
*/
|
|
export const getNotchHeight = () => {
|
|
const systemInfo = uni.getSystemInfoSync()
|
|
return systemInfo.safeArea?.top || 0
|
|
} |