App.uvue
3.16 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<script lang="uts">
// import { updateResolutionConfig } from "@/services/adapter/index.uts";
// #ifdef APP
import { applyScreenOrientationLock } from "@/utils/apply-orientation-lock.uts";
import ws from "@/ws";
// #endif
let firstBackTime = 0;
export default {
onLaunch () {
// #ifdef APP
const sys = uni.getSystemInfoSync();
console.log(`[App] 当前分辨率:${ sys.screenWidth } x ${ sys.screenHeight}`);
// globalStyle.pageOrientation=auto 允许旋转;手机在下方仍 lock 竖屏,Pad unlock FULL_SENSOR
applyScreenOrientationLock();
// #endif
console.log("App Launch");
// 启动时仅做分辨率配置,避免后台定时器/录音模拟导致对象被长时间持有
// updateResolutionConfig();
// 连接(自动登录)
// #ifdef APP
ws.connect();
// #endif
},
onShow () {
console.log("App Show");
// #ifdef APP
// 与 onLaunch 一致:手机每次回到前台再锁竖屏(auto 下易被系统/框架改回可旋转)
applyScreenOrientationLock();
// #endif
},
onHide () {
console.log("App Hide");
},
// #ifdef APP-ANDROID
onLastPageBackPress () {
console.log("App LastPageBackPress");
if (firstBackTime == 0) {
uni.showToast({
title: "再按一次退出应用",
position: "bottom"
});
firstBackTime = Date.now();
setTimeout(() => {
firstBackTime = 0;
}, 2000);
} else if (Date.now() - firstBackTime < 2000) {
firstBackTime = Date.now();
uni.exit();
}
},
// #endif
onExit () {
console.log("App Exit");
}
};
</script>
<style lang="scss">
/* 引入自定义 CSS 工具类 */
@import url("./common.css");
/* I18n 布局适配:横竖屏 + 分辨率 */
// @import "./services/adapter/styles/layout-adapt.scss";
/* 全局默认样式:App 端 view 不支持 font-size,基准字号用 var(--l-font-*) 落在 <text> 上 */
.layout-root {
height: 100%;
min-height: 0;
}
/* #ifdef H5 */
.layout-root {
font-size: 14px;
}
/* #endif */
/* #ifdef H5 */
svg {
display: initial;
}
/* H5 端统一 flex 默认行为,与 App 端保持一致 */
uni-app uni-page-body, uni-app uni-left-window .uni-left-window, uni-app uni-right-window .uni-right-window, uni-app uni-top-window .uni-top-window, uni-app uni-view, uni-app uni-match-media, uni-app uni-swiper, uni-app uni-swiper-item, uni-app uni-movable-area, uni-app uni-movable-view, uni-app uni-cover-view, uni-app uni-list-item, uni-app uni-navigator, uni-app uni-radio-group, uni-app uni-checkbox-group, uni-app uni-scroll-view, uni-app uni-list-view, uni-app uni-unicloud-db, uni-app uni-sticky-section, uni-app uni-sticky-header {
display: flex ;
flex-direction: row ;
}
/* #endif */
.safe-area-top {
margin-top: env(safe-area-inset-top);
}
.uni-tabbar {
// #ifdef H5
display: none;
// #endif
.uni-tabbar__icon {
margin-top: 0;
}
}
.uni-toast {
border-radius: 32rpx;
background-color: rgba(0, 0, 0, 0.8) !important;
}
/* 修复 uview-unix un-segmented 组件在 uni-app X 的样式问题 */
/* color 属性只能在 text、button、input、textarea 上使用 */
.un-segmented__item {
.un-segmented__item__text {
color: #1f2937;
}
}
.un-segmented__item--active {
.un-segmented__item__text {
color: #ffffff;
}
}
</style>