plus-screen.uts
1.67 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
46
47
48
49
50
51
52
53
/**
* plus.screen 的 uni-app x 替代实现
* 用于屏幕方向控制
*/
/**
* 锁定屏幕方向
* @param orientation 方向:'portrait-primary' | 'landscape-primary' | 'portrait' | 'landscape'
*/
export function lockOrientation(orientation: string): void {
// #ifdef APP
// uni-app x 中屏幕方向通过 manifest.json 或页面配置控制
// 动态控制需要通过 UTS 插件实现
console.log(`[plus-screen] 锁定屏幕方向: ${orientation}`);
console.warn("[plus-screen] uni-app x 中屏幕方向建议在 manifest.json 或页面配置中设置");
// #endif
// #ifndef APP
console.log(`[plus-screen] 非APP平台不支持锁定屏幕方向`);
// #endif
}
/**
* 解锁屏幕方向
*/
export function unlockOrientation(): void {
// #ifdef APP
console.log("[plus-screen] 解锁屏幕方向");
console.warn("[plus-screen] uni-app x 中屏幕方向建议在 manifest.json 或页面配置中设置");
// #endif
// #ifndef APP
console.log("[plus-screen] 非APP平台不支持解锁屏幕方向");
// #endif
}
/**
* 保持屏幕常亮
* @param keepOn 是否保持常亮
*/
export function setKeepScreenOn(keepOn: boolean): void {
// #ifdef APP
// uni-app x 中设置屏幕常亮需要使用 plus.device.setWakelock 或 UTS 插件
// 注意:uni.setKeepScreenOn 在 uni-app x 中可能不存在,需要使用其他方式
// 暂时使用 console 提示,实际使用时需要通过 UTS 插件实现
console.warn(`[plus-screen] 设置屏幕常亮功能需要通过 UTS 插件实现: ${keepOn}`);
// TODO: 实现 UTS 插件调用原生 API 设置屏幕常亮
// #endif
// #ifndef APP
console.log(`[plus-screen] 非APP平台不支持设置屏幕常亮`);
// #endif
}