更新记录
1.0.1(2026-05-13) 下载此版本
新增工具函数
1.0.0(2026-05-11) 下载此版本
- 初始版本
- 系统信息工具函数:getStatusBarHeight、getWindowWidth
平台兼容性
uni-app(5.0)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | √ | - | - | √ | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 3.15.0 | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(5.0)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | - | - | - | 3.15.0 |
carson-tools
系统信息工具函数库,提供获取系统信息的通用方法。
安装
直接在 uni-app 项目中使用,无需额外安装。
使用方法
方式一:从主入口导入
import { getStatusBarHeight, getWindowWidth, getContentHeight, getNavbarHeight } from '@/uni_modules/carson-tools/index.js';
// 获取状态栏高度
const statusBarHeight = getStatusBarHeight();
// 获取窗口宽度
const windowWidth = getWindowWidth();
// 获取导航栏内容高度(不含状态栏)
const contentHeight = getContentHeight();
// 获取导航栏总高度(含状态栏)
const navbarHeight = getNavbarHeight();
方式二:单独导入
import getStatusBarHeight from '@/uni_modules/carson-tools/libs/getStatusBarHeight.js';
import getWindowWidth from '@/uni_modules/carson-tools/libs/getWindowWidth.js';
import getContentHeight from '@/uni_modules/carson-tools/libs/getContentHeight.js';
import getNavbarHeight from '@/uni_modules/carson-tools/libs/getNavbarHeight.js';
API
getStatusBarHeight()
获取状态栏高度。
返回值:
| 类型 | 说明 |
|---|---|
| number | 状态栏高度(px) |
getWindowWidth()
获取窗口宽度。
返回值:
| 类型 | 说明 |
|---|---|
| number | 窗口宽度(px) |
getContentHeight(customHeight = 88)
计算导航栏内容区域高度(不含状态栏)。
参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| customHeight | number | string | 88 | 导航栏内容高度(rpx),支持数字或字符串格式如 '88rpx' |
返回值:
| 类型 | 说明 |
|---|---|
| number | 导航栏内容高度(px) |
示例:
// 使用默认高度 88rpx
const height = getContentHeight();
// 使用自定义高度
const customHeight = getContentHeight(100);
const customHeight2 = getContentHeight('100rpx');
getNavbarHeight(customHeight = 88)
计算导航栏总高度(含状态栏)。
参数:
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| customHeight | number | string | 88 | 导航栏内容高度(rpx),支持数字或字符串格式如 '88rpx' |
返回值:
| 类型 | 说明 |
|---|---|
| number | 导航栏总高度(px),等于状态栏高度 + 导航栏内容高度 |
示例:
// 使用默认高度
const height = getNavbarHeight();
// 使用自定义高度
const customHeight = getNavbarHeight(100);
平台支持
- Vue2 / Vue3
- App(app-vue / app-nvue)
- H5(移动端 / PC端)
- 微信小程序、支付宝小程序、百度小程序等
- 快应用
更新日志
1.1.0
- 新增
getContentHeight函数 - 计算导航栏内容区域高度 - 新增
getNavbarHeight函数 - 计算导航栏总高度(含状态栏) - 新增
parseHeight工具函数 - 解析高度参数
1.0.0
- 初始版本
- 新增
getStatusBarHeight函数 - 新增
getWindowWidth函数

收藏人数:
下载插件并导入HBuilderX
下载插件ZIP
赞赏(0)
下载 12
赞赏 0
下载 12341699
赞赏 1924
赞赏
京公网安备:11010802035340号