64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
const SYSTEM = uni.getSystemInfoSync();
|
|
|
|
export const getStatusBarHeight = () => SYSTEM.statusBarHeight || 15;
|
|
export const getTitleBarHeight = () => {
|
|
if (uni.getMenuButtonBoundingClientRect) {
|
|
const { top, height } = uni.getMenuButtonBoundingClientRect();
|
|
return height + (top - getStatusBarHeight()) * 2;
|
|
} else {
|
|
return 40;
|
|
}
|
|
};
|
|
|
|
export const getBavBarHeight = () => getStatusBarHeight() + getTitleBarHeight();
|
|
|
|
export const getLeftIconLeft = () => {
|
|
// if(tt?.getMenuButtonBoundingClientRect) {
|
|
// const { leftIcon: {left, width}} = tt.getMenuButtonBoundingClientRect
|
|
// return left + parseInt(width) + 5
|
|
// } else {
|
|
// return 0
|
|
// }
|
|
// #ifdef MP-TOUTIAO
|
|
const {
|
|
leftIcon: { left, width },
|
|
} = tt.getCustomButtonBoundingClientRect();
|
|
return left + parseInt(width);
|
|
// #endif
|
|
// #ifndef MP-TOUTIAO
|
|
return 0;
|
|
// #endif
|
|
};
|
|
|
|
export function getPlatformProvider() {
|
|
const platform = process.env.UNI_PLATFORM;
|
|
return platform ?? "mp-weixin";
|
|
// const platform = uni.getSystemInfoSync().platform;
|
|
// console.log(1111111, platform)
|
|
// // H5 模拟器调试时使用 __wxConfig 环境变量判断
|
|
// if (typeof __wxConfig !== 'undefined') return 'weixin';
|
|
// if (platform === 'devtools') {
|
|
// // 可以根据小程序环境变量判断
|
|
// // 抖音开发工具会定义 tt 对象
|
|
// return typeof tt !== 'undefined' ? 'toutiao' : 'weixin';
|
|
// }
|
|
|
|
// return typeof tt !== 'undefined' ? 'toutiao' : 'weixin';
|
|
}
|
|
|
|
export function getDeviceInfo() {
|
|
const info = uni.getSystemInfoSync();
|
|
return {
|
|
platform: info.platform,
|
|
brand: info.brand,
|
|
model: info.model,
|
|
system: info.system,
|
|
screenWidth: info.screenWidth,
|
|
screenHeight: info.screenHeight,
|
|
pixelRatio: info.pixelRatio,
|
|
language: info.language,
|
|
version: info.version,
|
|
SDKVersion: info.SDKVersion,
|
|
};
|
|
}
|