Просмотр исходного кода

feat(bx-mobile): finish portal login page and normalize current-user fields

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu 2 месяцев назад
Родитель
Сommit
a4f04ff297
2 измененных файлов с 19 добавлено и 5 удалено
  1. 11 2
      bx-mobile/src/stores/auth.ts
  2. 8 3
      bx-mobile/src/views/login/LoginPage.vue

+ 11 - 2
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()
     }
   }
 

+ 8 - 3
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 {