<script setup>
|
import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
|
import { useAppStore, useUserStore, useLocationStore } from '@/store'
|
import { useGlobalWS } from '@/hooks/useGlobalWS.js'
|
// #ifdef APP-PLUS
|
import { keepAliveStart, requestIgnoreBatteryOptimization, isIgnoringBatteryOptimizations } from '@/uni_modules/keep-app'
|
import { openDialog, allowFloat, getBatteryCapacity, allowBackgroundPopup, allowLockScreen } from '@/uni_modules/lgh-dialog'
|
// #endif
|
|
const appStore = useAppStore()
|
const userStore = useUserStore()
|
const locationStore = useLocationStore()
|
|
// #ifdef APP-PLUS
|
// const currentKey = ref(1)
|
// function testKeep() {
|
// setInterval(() => {
|
// currentKey.value = currentKey.value + 1
|
// const val = '保活服务验证:' + currentKey.value
|
// console.log(val)
|
// uni.showToast({ title: val, icon: 'none' })
|
// }, 1000)
|
// }
|
// testKeep()
|
// #endif
|
|
useGlobalWS()
|
|
onShow(async () => {
|
console.log('App Show')
|
// 确保只有在用户已登录的情况下才初始化位置服务
|
if (userStore.userInfo && userStore.userInfo.username && locationStore) {
|
try {
|
await locationStore.initLocationService()
|
} catch (error) {
|
console.error('重新初始化位置服务失败:', error)
|
}
|
}
|
})
|
|
onHide(() => {
|
console.log('App Hide')
|
// 应用进入后台时,停止位置监听以节省资源
|
if (locationStore) {
|
locationStore.stopLocationWatch()
|
}
|
})
|
|
function setKeepFun() {
|
// #ifdef APP-PLUS
|
keepAliveStart()
|
|
//显示悬浮窗权限
|
setTimeout(allowFloat, 5000)
|
// 请求用户允许忽略电池优化(重要:用于保活)
|
setTimeout(requestIgnoreBatteryOptimization, 10000)
|
// 引导用户开启「后台弹出界面」权限
|
setTimeout(allowBackgroundPopup, 15000)
|
// 引导用户开启「锁屏显示」权限
|
setTimeout(allowLockScreen, 20000)
|
|
// #endif
|
}
|
|
onLaunch(() => {
|
// 初始化系统信息
|
appStore.initSystemInfo()
|
setKeepFun()
|
if (!userStore.userInfo) {
|
//不存在则跳转至登录页
|
uni.reLaunch({
|
url: '/pages/login/index',
|
})
|
}
|
})
|
</script>
|
|
<style lang="scss">
|
/* 每个页面公共css */
|
@import 'uview-plus/index.scss';
|
@import '@/static/styles/common.scss';
|
|
.TUICallKit-mobile {
|
position: fixed;
|
left: 0;
|
top: 0;
|
z-index: 9999;
|
}
|
|
page {
|
background-image: url('https://wrj.shuixiongit.com/aiskyminio/cloud-bucket/ztzf_app_assets/images/user/bg.png');
|
background-size: cover;
|
background-position: center;
|
background-repeat: no-repeat;
|
background-attachment: fixed;
|
// min-height: 10vh;
|
}
|
|
.uni-tabbar-border {
|
background-color: #f6f6f6 !important;
|
}
|
|
.uni-page-head__title {
|
font-family: Source Han Sans CN, Source Han Sans CN !important;
|
font-weight: 400 !important;
|
font-size: 17px !important;
|
color: #222324 !important;
|
}
|
|
.uni-page-head {
|
background: transparent !important;
|
}
|
</style>
|