Files
spring-festival-greetings/utils/system.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2026-01-15 08:43:10 +08:00
const SYSTEM = uni.getSystemInfoSync();
2026-01-09 11:24:40 +08:00
2026-01-15 08:43:10 +08:00
export const getStatusBarHeight = () => SYSTEM.statusBarHeight || 15;
2026-01-09 11:24:40 +08:00
export const getTitleBarHeight = () => {
2026-01-15 08:43:10 +08:00
if (uni.getMenuButtonBoundingClientRect) {
const { top, height } = uni.getMenuButtonBoundingClientRect();
return height + (top - getStatusBarHeight()) * 2;
} else {
return 40;
}
};
2026-01-09 11:24:40 +08:00
2026-01-15 08:43:10 +08:00
export const getBavBarHeight = () => getStatusBarHeight() + getTitleBarHeight();
2026-01-09 11:24:40 +08:00
export const getLeftIconLeft = () => {
2026-01-15 08:43:10 +08:00
// 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
};
2026-01-09 11:24:40 +08:00
export function getPlatformProvider() {
2026-01-15 08:43:10 +08:00
const platform = process.env.UNI_PLATFORM;
2026-01-16 15:09:19 +08:00
return platform || "mp-weixin";
2026-01-09 11:24:40 +08:00
// 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';
}
2026-01-15 08:43:10 +08:00
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,
2026-01-26 17:16:52 +08:00
appId: "69665538a49b8ae3be50fe5d",
2026-01-15 08:43:10 +08:00
};
}