diff --git a/src/api/login/index.ts b/src/api/login/index.ts index ab552ec..1acfc8a 100644 --- a/src/api/login/index.ts +++ b/src/api/login/index.ts @@ -1,5 +1,12 @@ import { post } from '@/utils/request'; +import type { LoginResult } from './types'; + +export type { LoginResult } from './types'; export const login = (params: { phone: string; password: string }) => { - return post(`/op/login`, params); + return post(`/op/login`, params) as Promise<{ + code: number; + msg: string; + data: LoginResult; + }>; }; diff --git a/src/api/login/types.ts b/src/api/login/types.ts new file mode 100644 index 0000000..d152867 --- /dev/null +++ b/src/api/login/types.ts @@ -0,0 +1,8 @@ +export interface LoginResult { + token: string; + phone?: string; + nickName?: string; + realName?: string; + userName?: string; + name?: string; +} diff --git a/src/api/menu.ts b/src/api/menu.ts index 7c5d73c..f9be5b1 100644 --- a/src/api/menu.ts +++ b/src/api/menu.ts @@ -3,6 +3,7 @@ import type { MenuNode, PermissionCode } from '@/types'; import { FALLBACK_MENU_NODES } from '@/config/fallbackRoutes'; import { getAuthDataPromise, setAuthDataPromise, clearAuthDataCache } from '@/api/authCache'; import { forceReLogin } from '@/hooks/useAuth'; +import { useUserStore } from '@/stores/userStore'; export { clearAuthDataCache } from '@/api/authCache'; @@ -12,6 +13,8 @@ export { clearAuthDataCache } from '@/api/authCache'; export interface AuthData { roleList: string[]; permsList: string[]; + nickname: string; + phone: string; } const AUTH_FETCH_FAIL_MSG = '账户权限获取失败,请重新登录'; @@ -21,14 +24,26 @@ function normalizeAuthData(res: any): AuthData { throw new Error(res.msg || AUTH_FETCH_FAIL_MSG); } - const roleList = res?.data?.roleList || []; - const permsList = res?.data?.permsList || []; + const data = res?.data || {}; + const roleList = data.roleList || []; + const permsList = data.permsList || []; if (permsList.length === 0) { throw new Error(AUTH_FETCH_FAIL_MSG); } - return { roleList, permsList }; + const nickname = data.nickName || ''; + const phone = typeof data.phone === 'string' ? data.phone : ''; + + if (nickname || phone) { + const { setUser } = useUserStore(); + setUser({ + ...(nickname ? { nickname } : {}), + ...(phone ? { phone } : {}), + }); + } + + return { roleList, permsList, nickname, phone }; } function handleAuthFetchFailure() { diff --git a/src/layouts/BasicLayout.module.less b/src/layouts/BasicLayout.module.less index 2a25135..bf59f0e 100644 --- a/src/layouts/BasicLayout.module.less +++ b/src/layouts/BasicLayout.module.less @@ -62,7 +62,7 @@ align-items: center; } - .userPhone { + .displayName { font-size: 14px; color: rgba(0, 0, 0, 0.65); } diff --git a/src/layouts/BasicLayout.tsx b/src/layouts/BasicLayout.tsx index cd73a31..bcbd633 100644 --- a/src/layouts/BasicLayout.tsx +++ b/src/layouts/BasicLayout.tsx @@ -79,6 +79,7 @@ export default defineComponent({ const { menuItems } = useMenuStore(); const { phone, nickname } = useUserStore(); + const displayName = computed(() => nickname.value || phone.value); const { tabs, cachedViews, @@ -232,7 +233,7 @@ export default defineComponent({ {/* 右侧: 账号信息 + 退出 */}