当前位置: 首页 > news >正文

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;},

相关文章:

  • Grafana之Dashboard(仪表盘)
  • OpenCV CUDA 模块中的矩阵算术运算-----在频域中执行两个复数频谱的逐元素乘法的函数mulSpectrums()
  • 多商户1.8.1版本前端问题优化集合指南
  • 可视化图解算法41:搜索二维矩阵(二维数组中的查找)
  • OpenCV CUDA模块中的矩阵算术运算------创建卷积操作对象的工厂方法 cv::cuda::createConvolution
  • 批量剪辑 + 矩阵分发 + 数字人分身源码搭建全技术解析,支持OEM
  • Linux 判断是否有未挂载的盘 分区挂载 (挂载所有大小的盘,包括挂载超过2T的盘)
  • Qt框架核心组件完全指南:从按钮交互到定时器实现
  • Regmap子系统之六轴传感器驱动-编写icm20607.c驱动
  • 基于STM32的光照测量报警Proteus仿真设计+程序设计+设计报告+讲解视频
  • 供应链风险管理中,企业如何识别关键风险因素?
  • 【C++】模版(1)
  • 机器学习--特征工程具体案例
  • 2022年下半年信息系统项目管理师——综合知识真题及答案(4)
  • WPF Data Binding 及经典应用示例
  • 《黑马前端ajax+node.js+webpack+git教程》(笔记)——node.js教程+webpack教程(nodejs教程)
  • 【占融数科-注册/登录安全分析报告】
  • Kotlin Compose Button 实现长按监听并实现动画效果
  • Text2SQL在Spark NLP中的实现与应用:将自然语言问题转换为SQL查询的技术解析
  • 深度学习---模型预热(Model Warm-Up)
  • 去年中企海外新增风电装机量5.4GW,亚太区域占比过半
  • 新片|《碟中谍8:最终清算》定档5月30日
  • 缅甸内观冥想的历史漂流:从“人民鸦片”到东方灵修
  • 从能源装备向应急装备蓝海拓展,川润股份发布智能综合防灾应急仓
  • 中国恒大:清盘人向香港高等法院申请撤回股份转让
  • 水豚出逃40天至今未归,江苏扬州一动物园发悬赏公告