From 1e9df13f397f1a86eb3b94ad39576caf8f438be4 Mon Sep 17 00:00:00 2001
From: 张含笑 <zhx18749296735@163.com>
Date: Sat, 17 Jan 2026 11:25:04 +0800
Subject: [PATCH] feat:获取位置
---
uniapps/work-app/src/App.vue | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/uniapps/work-app/src/App.vue b/uniapps/work-app/src/App.vue
index 020fe6c..3240b20 100644
--- a/uniapps/work-app/src/App.vue
+++ b/uniapps/work-app/src/App.vue
@@ -1,19 +1,32 @@
<script setup>
import { onHide, onLaunch, onShow } from "@dcloudio/uni-app";
-import { useAppStore, useUserStore } from "@/store";
+import { useAppStore, useUserStore, useLocationStore } from "@/store";
import { useGlobalWS } from "@/hooks/useGlobalWS.js";
const appStore = useAppStore();
const userStore = useUserStore();
+const locationStore = useLocationStore();
useGlobalWS();
-onShow(() => {
+onShow(async () => {
console.log("App Show");
+ // 应用从后台返回前台时,重新初始化位置服务
+ if (userStore.userInfo && locationStore) {
+ try {
+ await locationStore.initLocationService();
+ } catch (error) {
+ console.error('重新初始化位置服务失败:', error);
+ }
+ }
});
onHide(() => {
console.log("App Hide");
+ // 应用进入后台时,停止位置监听以节省资源
+ if (locationStore) {
+ locationStore.stopLocationWatch();
+ }
});
onLaunch(() => {
--
Gitblit v1.9.3