| | |
| | | <script setup lang="ts"> |
| | | import { useStore } from "/@/cool"; |
| | | import { useStore, storage } from "/@/cool"; |
| | | import { miniAutoLogin, phoneAuthState } from "/@/cool/mini-login"; |
| | | import { i18n } from "/@/locale"; |
| | | import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"; |
| | | |
| | | let booted = false; |
| | | |
| | | function boot() { |
| | | if (booted) { |
| | | return; |
| | | } |
| | | booted = true; |
| | | |
| | | const { dict, user } = useStore(); |
| | | const authState = phoneAuthState(); |
| | | |
| | | try { |
| | | const locale = uni.getLocale(); |
| | | if (locale) { |
| | | i18n.global.locale = locale; |
| | | } |
| | | } catch (err) { |
| | | console.error(err); |
| | | } |
| | | |
| | | dict.refresh()?.catch(() => undefined); |
| | | |
| | | // #ifdef MP-WEIXIN |
| | | miniAutoLogin() |
| | | .catch(() => false) |
| | | .finally(() => { |
| | | authState.ready = true; |
| | | if (user.token && !storage.isExpired("token")) { |
| | | user.get()?.catch(() => undefined); |
| | | } |
| | | }); |
| | | // #endif |
| | | |
| | | // #ifndef MP-WEIXIN |
| | | authState.ready = true; |
| | | if (user.token) { |
| | | user.get()?.catch(() => undefined); |
| | | } |
| | | // #endif |
| | | } |
| | | |
| | | onLaunch(() => { |
| | | console.log("App Launch"); |
| | | |
| | | const { dict, user } = useStore(); |
| | | |
| | | // 获取字典 |
| | | dict.refresh(); |
| | | |
| | | if (user.token) { |
| | | // 获取登录用户信息 |
| | | user.get(); |
| | | } |
| | | }); |
| | | |
| | | onShow(() => { |
| | | console.log("App Show"); |
| | | setTimeout(boot, 0); |
| | | }); |
| | | |
| | | onHide(() => { |