WebApp 属性
window.Telegram.WebApp 对象提供以下只读属性,用于获取 Mini App 的运行环境和状态信息。
基本信息
| 属性 | 类型 | 描述 |
|---|---|---|
initData | String | 传递给 Mini App 的原始初始化数据字符串,用于服务端验证 |
initDataUnsafe | WebAppInitData | 解析后的初始化数据对象,包含用户、聊天等信息 |
version | String | Bot API 版本号,如 "8.0" |
platform | String | Mini App 运行平台,如 "android"、"ios"、"web"、"tdesktop" |
isActive | Boolean | Mini App 当前是否处于活跃状态。Bot API 8.0+ |
颜色与主题
| 属性 | 类型 | 描述 |
|---|---|---|
colorScheme | String | 当前主题色模式,值为 "light" 或 "dark" |
themeParams | ThemeParams | 当前主题的颜色参数对象 |
headerColor | String | 当前标题栏颜色,十六进制格式如 "#ffffff" |
backgroundColor | String | 当前背景颜色 |
bottomBarColor | String | 底部栏颜色。Bot API 7.10+ |
视口与布局
| 属性 | 类型 | 描述 |
|---|---|---|
viewportHeight | Float | Mini App 可见区域高度(像素) |
viewportStableHeight | Float | 视口稳定高度(不受键盘弹出等影响) |
isExpanded | Boolean | Mini App 是否已展开到最大高度 |
isFullscreen | Boolean | Mini App 是否处于全屏模式。Bot API 8.0+ |
isOrientationLocked | Boolean | 屏幕方向是否已锁定。Bot API 8.0+ |
safeAreaInset | SafeAreaInset | 安全区域内边距对象。Bot API 8.0+ |
contentSafeAreaInset | ContentSafeAreaInset | 内容安全区域内边距对象。Bot API 8.0+ |
交互状态
| 属性 | 类型 | 描述 |
|---|---|---|
isClosingConfirmationEnabled | Boolean | 是否启用关闭确认对话框 |
isVerticalSwipesEnabled | Boolean | 是否启用垂直滑动手势。Bot API 7.7+ |
UI 组件
| 属性 | 类型 | 描述 |
|---|---|---|
BackButton | BackButton | 返回按钮控制对象 |
MainButton | BottomButton | 主按钮控制对象(底部大按钮) |
SecondaryButton | BottomButton | 次要按钮控制对象。Bot API 7.10+ |
SettingsButton | SettingsButton | 设置按钮控制对象。Bot API 7.0+ |
HapticFeedback | HapticFeedback | 触觉反馈控制对象 |
管理器
| 属性 | 类型 | 描述 |
|---|---|---|
CloudStorage | CloudStorage | 云存储管理器 |
DeviceStorage | DeviceStorage | 设备存储管理器。Bot API 8.0+ |
SecureStorage | SecureStorage | 安全存储管理器。Bot API 8.0+ |
BiometricManager | BiometricManager | 生物识别管理器。Bot API 7.2+ |
Accelerometer | Accelerometer | 加速度计。Bot API 8.0+ |
DeviceOrientation | DeviceOrientation | 设备方向传感器。Bot API 8.0+ |
Gyroscope | Gyroscope | 陀螺仪。Bot API 8.0+ |
LocationManager | LocationManager | 位置管理器。Bot API 8.0+ |
