From dfc3ee25d81398711bf5076ec5def7b38481a6f0 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Fri, 06 Feb 2026 15:05:49 +0800
Subject: [PATCH] feat: 保活

---
 uniapps/work-app/src/App.vue |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/uniapps/work-app/src/App.vue b/uniapps/work-app/src/App.vue
index e90687a..ccdcf8f 100644
--- a/uniapps/work-app/src/App.vue
+++ b/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) {
 		//不存在则跳转至登录页

--
Gitblit v1.9.3