diff --git a/bx-mobile/src/stores/auth.ts b/bx-mobile/src/stores/auth.ts index d75fc9671..7bd2d4bee 100644 --- a/bx-mobile/src/stores/auth.ts +++ b/bx-mobile/src/stores/auth.ts @@ -83,13 +83,22 @@ export const useAuthStore = defineStore('auth', () => { async function fetchUser() { try { const res: any = await portalAuthApi.currentUser() - user.value = res.data + const d = res.data || {} + user.value = { + id: String(d.id || d.userId || ''), + username: d.username || d.userName || '', + realName: d.realName || d.username || '', + phone: d.phone, + role: d.role, + roles: d.roles || [], + avatarUrl: d.avatarUrl, + } const perm: any = await portalAuthApi.menuCodes() isSuperAdmin.value = !!perm.data?.isSuperAdmin allMenus.value = !!perm.data?.all menuCodes.value = perm.data?.menuCodes || [] } catch { - logout() + await logout() } } diff --git a/bx-mobile/src/views/login/LoginPage.vue b/bx-mobile/src/views/login/LoginPage.vue index 487e2d3c4..0129aadb3 100644 --- a/bx-mobile/src/views/login/LoginPage.vue +++ b/bx-mobile/src/views/login/LoginPage.vue @@ -59,7 +59,7 @@ import { ref } from 'vue' import { useRouter } from 'vue-router' import { showToast } from 'vant' import { useAuthStore } from '@/stores/auth' -import { BizError } from '@/api/client' +import { PortalError } from '@/api/portalClient' const router = useRouter() const auth = useAuthStore() @@ -81,9 +81,14 @@ async function handleLogin() { showToast('登录成功') router.replace('/') } catch (e: any) { - const detail = e?.response?.data?.detail || e?.response?.data?.msg || '' + const detail = + e?.response?.data?.message || + e?.response?.data?.msg || + e?.response?.data?.detail || + '' errorText.value = detail || e.message || '账号或密码错误' - if (!(e instanceof BizError)) { + // PortalError:拦截器已 toast,避免双提示 + if (!(e instanceof PortalError)) { showToast(errorText.value) } } finally {