From 89d9aa92065652753d7c54d3c4fc880744377c69 Mon Sep 17 00:00:00 2001
From: 罗广辉 <guanghui.luo@foxmail.com>
Date: Fri, 06 Feb 2026 14:52:11 +0800
Subject: [PATCH] feat: 保活

---
 uniapps/work-app/src/App.vue |  123 ++++++++++++++++++++++++----------------
 1 files changed, 73 insertions(+), 50 deletions(-)

diff --git a/uniapps/work-app/src/App.vue b/uniapps/work-app/src/App.vue
index 94cb54c..e90687a 100644
--- a/uniapps/work-app/src/App.vue
+++ b/uniapps/work-app/src/App.vue
@@ -1,79 +1,102 @@
 <script setup>
-import { onHide, onLaunch, onShow } from "@dcloudio/uni-app";
-import { useAppStore, useUserStore, useLocationStore } from "@/store";
-import { useGlobalWS } from "@/hooks/useGlobalWS.js";
+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 } from '@/uni_modules/keep-app'
+// #endif
 
-const appStore = useAppStore();
-const userStore = useUserStore();
-const locationStore = useLocationStore();
+const appStore = useAppStore()
+const userStore = useUserStore()
+const locationStore = useLocationStore()
 
-useGlobalWS();
+// #ifdef APP-PLUS
+import { getBatteryCapacity } from '@/uni_modules/lgh-getbatteryinfo'
+console.log('电池电量:', getBatteryCapacity())
+// #endif
+
+const valuetest = ref(1)
+function tests() {
+	setInterval(() => {
+		valuetest.value = valuetest.value + 1
+		console.log('valuetest.value:', valuetest.value)
+
+		uni.showToast({title: valuetest.value, icon: 'none'});
+	}, 1000)
+}
+
+useGlobalWS()
 
 onShow(async () => {
-  console.log("App Show");
-  // 确保只有在用户已登录的情况下才初始化位置服务
-  if (userStore.userInfo && userStore.userInfo.username && locationStore) {
-    try {
-      await locationStore.initLocationService();
-    } catch (error) {
-      console.error('重新初始化位置服务失败:', error);
-    }
-  }
-});
+	console.log('App Show')
+	// 确保只有在用户已登录的情况下才初始化位置服务
+	if (userStore.userInfo && userStore.userInfo.username && locationStore) {
+		try {
+			await locationStore.initLocationService()
+		} catch (error) {
+			console.error('重新初始化位置服务失败:', error)
+		}
+	}
+})
+tests()
 
 onHide(() => {
-  console.log("App Hide");
-  // 应用进入后台时,停止位置监听以节省资源
-  if (locationStore) {
-    locationStore.stopLocationWatch();
-  }
-});
+	console.log('App Hide')
+	// 应用进入后台时,停止位置监听以节省资源
+	if (locationStore) {
+		locationStore.stopLocationWatch()
+	}
+})
 
 onLaunch(() => {
-  // 初始化系统信息
-  appStore.initSystemInfo();
-  if (!userStore.userInfo) {
-    //不存在则跳转至登录页
-    uni.reLaunch({
-      url: "/pages/login/index",
-    });
-  }
-});
+	// 初始化系统信息
+	appStore.initSystemInfo()
+	// #ifdef APP-PLUS
+	keepAliveStart()
+	// #endif
+	if (!userStore.userInfo) {
+		//不存在则跳转至登录页
+		uni.reLaunch({
+			url: '/pages/login/index',
+		})
+	}
+})
 </script>
 
 <style lang="scss">
 /* 每个页面公共css */
-@import "uview-plus/index.scss";
-@import "@/static/styles/common.scss";
+@import 'uview-plus/index.scss';
+@import '@/static/styles/common.scss';
 
 .TUICallKit-mobile {
-  position: fixed;
-  left: 0;
-  top: 0;
-  z-index: 9999;
+	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;
+	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;
+	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;
+	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;
+	background: transparent !important;
 }
 </style>
+

--
Gitblit v1.9.3