吉安感知网项目-前端
shuishen
2026-01-19 16e9746e5da1ac0485fde18e71fb7bf8ee376d42
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(() => {