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

89 lines
2.3 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-02-11 15:50:55 +08:00
// #ifdef MP-ALIPAY
return 44;
// #endif
2026-01-15 08:43:10 +08:00
if (uni.getMenuButtonBoundingClientRect) {
2026-02-11 15:50:55 +08:00
try {
const rect = uni.getMenuButtonBoundingClientRect();
if (rect && rect.top && rect.height) {
return rect.height + (rect.top - getStatusBarHeight()) * 2;
}
} catch (e) {
console.error(e);
}
2026-01-15 08:43:10 +08:00
}
2026-02-11 15:50:55 +08:00
return 44;
2026-01-15 08:43:10 +08:00
};
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
2026-02-11 23:59:51 +08:00
export function getPlatform() {
return getPlatformProvider().replace("mp-", "");
}
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
};
}
2026-02-09 20:30:15 +08:00
/**
* 判断是否处于朋友圈单页模式
*/
export function isSinglePageMode() {
// #ifdef MP-WEIXIN
const launchOptions = uni.getLaunchOptionsSync();
return launchOptions.scene === 1154;
// #endif
return false;
}