import { getToken } from '@/utils/auth' import { useUserStore } from '@/store/user' import { PARTNER_ROLE_DENIED_MSG } from '@/utils/partnerRole' /** * 应用启动:若有 Token 则拉取用户信息;非供应商/承销商则清登录态 */ export function syncUserOnLaunch() { if (!getToken()) { return Promise.resolve() } const userStore = useUserStore() if (userStore.isLoggedIn()) { return Promise.resolve() } return userStore.fetchUserInfo().catch((err) => { userStore.fedLogOut() if (err && err.message === PARTNER_ROLE_DENIED_MSG) { uni.showToast({ title: PARTNER_ROLE_DENIED_MSG, icon: 'none', duration: 2500 }) } }) } /** @deprecated 仅保留兼容 */ export function initRouteGuard() {} /** @deprecated 请使用 syncUserOnLaunch */ export function bootstrapAuth() { return syncUserOnLaunch() }