plus-navigator.uts
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* plus.navigator 的 uni-app x 替代实现
* 用于导航栏相关操作
*/
/**
* 获取状态栏高度
*/
export function getStatusbarHeight(): number {
// #ifdef APP
const systemInfo = uni.getSystemInfoSync();
const height = systemInfo.statusBarHeight;
// UTS 要求条件语句必须使用布尔类型
if (height != null && height > 0) {
return height;
}
return 0;
// #endif
// #ifndef APP
return 0;
// #endif
}
/**
* 设置用户代理(User Agent)
* 注意:uni-app x 中 WebView 的 UA 设置需要在创建 WebView 时配置
*/
export function setUserAgent(userAgent: string): void {
// #ifdef APP
// uni-app x 中 WebView 的 UA 需要在创建时设置
// 使用 web-view 组件时,可以通过属性设置
console.warn("[plus-navigator] setUserAgent 需要在创建 WebView 时设置");
// #endif
// #ifndef APP
// H5 可以设置 navigator.userAgent
if (typeof navigator != "undefined") {
Object.defineProperty(navigator, "userAgent", {
get: () => userAgent,
configurable: true
});
}
// #endif
}