62 lines
1.4 KiB
Plaintext
62 lines
1.4 KiB
Plaintext
<script setup lang="uts">
|
|
import userState, { initStore } from "@/stores/user.uts"
|
|
import appState, { initApp } from "@/stores/app.uts"
|
|
import messageService from "@/services/websocket/message-service.uts"
|
|
// #ifdef APP-ANDROID
|
|
UTSAndroid.setPrivacyAgree(true)
|
|
// #endif
|
|
// #ifdef APP-ANDROID || APP-HARMONY
|
|
let firstBackTime = 0
|
|
// #endif
|
|
const instance = getCurrentInstance()!.proxy!
|
|
|
|
onLaunch((options) => {
|
|
console.log('App onLaunch')
|
|
initStore();
|
|
// 注册 WebSocket 消息监听(即使未登录也先就绪)
|
|
messageService.init()
|
|
(async () => {
|
|
try {
|
|
await initApp()
|
|
// 其他异步初始化操作
|
|
} catch (e) {
|
|
console.error('初始化失败', e)
|
|
}
|
|
})()
|
|
|
|
})
|
|
onShow(() => {
|
|
console.log('App onShow')
|
|
const res = uni.getSystemInfoSync()
|
|
console.log(res)
|
|
})
|
|
onHide(() => {
|
|
console.log('App onHide')
|
|
})
|
|
// #ifdef APP-ANDROID || APP-HARMONY
|
|
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>
|
|
/*每个页面公共css */
|
|
@import url("@/static/common.scss");
|
|
</style> |