吉安感知网项目-前端
罗广辉
2026-02-06 dfc3ee25d81398711bf5076ec5def7b38481a6f0
uniapps/work-app/src/App.vue
@@ -3,7 +3,7 @@
import { useAppStore, useUserStore, useLocationStore } from '@/store'
import { useGlobalWS } from '@/hooks/useGlobalWS.js'
// #ifdef APP-PLUS
import { keepAliveStart } from '@/uni_modules/keep-app'
import { keepAliveStart, requestIgnoreBatteryOptimization } from '@/uni_modules/keep-app'
// #endif
const appStore = useAppStore()
@@ -11,8 +11,8 @@
const locationStore = useLocationStore()
// #ifdef APP-PLUS
import { getBatteryCapacity } from '@/uni_modules/lgh-getbatteryinfo'
console.log('电池电量:', getBatteryCapacity())
// import { getBatteryCapacity } from '@/uni_modules/lgh-getbatteryinfo'
// console.log('电池电量:', getBatteryCapacity())
// #endif
const valuetest = ref(1)
@@ -20,11 +20,10 @@
   setInterval(() => {
      valuetest.value = valuetest.value + 1
      console.log('valuetest.value:', valuetest.value)
      uni.showToast({title: valuetest.value, icon: 'none'});
      uni.showToast({ title: valuetest.value, icon: 'none' })
   }, 1000)
}
tests()
useGlobalWS()
onShow(async () => {
@@ -38,7 +37,6 @@
      }
   }
})
tests()
onHide(() => {
   console.log('App Hide')
@@ -53,6 +51,10 @@
   appStore.initSystemInfo()
   // #ifdef APP-PLUS
   keepAliveStart()
   // 请求用户允许忽略电池优化(重要:用于保活)
   setTimeout(() => {
      requestIgnoreBatteryOptimization()
   }, 2000)
   // #endif
   if (!userStore.userInfo) {
      //不存在则跳转至登录页