| | |
| | | <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(() => { |