uniapp小程序获取手机设备安全距离

utils.js

复制代码
let systemInfo = null;

export const getSystemInfo = () => {
  if (!systemInfo) {
    systemInfo = uni.getSystemInfoSync();
    // 补充安全区域默认值
    systemInfo.safeAreaInsets = systemInfo.safeAreaInsets || {
      top: 0,
      bottom: 0,
      left: 0,
      right: 0
    };
    // 确保statusBarHeight存在(兼容旧版本)
    systemInfo.statusBarHeight = systemInfo.statusBarHeight || 
      (systemInfo.platform === 'android' ? 25 : 20);
  }
  return systemInfo;
};

// 获取状态栏高度(px)
export const getStatusBarHeight = () => getSystemInfo().statusBarHeight;

// 获取iPhone底部下巴高度(px)
export const getIphoneBottomHeight = () => {
  const { platform, safeAreaInsets } = getSystemInfo();
  return platform === 'ios' ? safeAreaInsets.bottom : 0;
};

// 是否全面屏设备
export const isNotchScreen = () => {
  const { model, statusBarHeight } = getSystemInfo();
  return statusBarHeight > 20 || /iphone x|iphone 1[1-5]/i.test(model);
};

import { getSystemInfo, getStatusBarHeight, getIphoneBottomHeight } from '@/utils/device';

复制代码
  computed: {
    // 底部安全区域高度(单位:px)
    bottomSafeArea() {
      return getIphoneBottomHeight();
    },
    // 转换为rpx单位
    bottomSafeAreaRpx() {
      return this.bottomSafeArea * (750 / this.deviceInfo.windowWidth);
    }
  },
  created() {
    // 获取设备状态栏高度
    const { statusBarHeight } = uni.getSystemInfoSync();
    this.navBarHeight = statusBarHeight;
  },
相关推荐
游戏开发爱好者831 分钟前
iOS 混淆工具链实战 多工具组合完成 IPA 混淆与加固 无源码混淆
android·ios·小程序·https·uni-app·iphone·webview
2501_916008897 小时前
用多工具组合把 iOS 混淆做成可复用的工程能力(iOS混淆|IPA加固|无源码混淆|Ipa Guard|Swift Shield)
android·开发语言·ios·小程序·uni-app·iphone·swift
阿金要当大魔王~~7 小时前
uniapp 页面标签 传值 ————— uniapp 定义 接口
前端·javascript·uni-app·1024程序员节
全栈软件开发7 小时前
uniapp三端影视源码苹果cms自动采集电影视频网站源码前端源码带VIP
前端·uni-app·影视源码
liweiweili12610 小时前
驾校陪练下单小程序
小程序
TiAmo zhang10 小时前
微信小程序开发案例 | 简易登录小程序
微信小程序·小程序·1024程序员节
黑马源码库miui5208612 小时前
场馆预定系统小程序
微信·微信小程序·小程序·1024程序员节
开发者小天13 小时前
uniapp中对接开发激励广告视频
uni-app
奎歪歪13 小时前
UniApp缓存系统详解
缓存·uni-app·1024程序员节