From 5ed7056c0574c82a84a9ee1ce039bad125a5d0ab Mon Sep 17 00:00:00 2001 From: KAI <1373639299@qq.com> Date: Tue, 11 Mar 2025 16:34:45 +0800 Subject: [PATCH] =?UTF-8?q?types:=20=E8=AE=A4=E8=AF=81=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/auth/type.ts | 22 +++++++++++++--------- src/stores/modules/user.ts | 10 +++++----- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/apis/auth/type.ts b/src/apis/auth/type.ts index 7b9b9ce..36b187d 100644 --- a/src/apis/auth/type.ts +++ b/src/apis/auth/type.ts @@ -42,15 +42,19 @@ export interface RouteItem { } /** 认证类型 */ -export enum AuthTypeEnum { - ACCOUNT = 'ACCOUNT', - PHONE = 'PHONE', - EMAIL = 'EMAIL', - SOCIAL = 'SOCIAL', -} +export type AuthType = 'ACCOUNT' | 'PHONE' | 'EMAIL' | 'SOCIAL' + +export const AuthTypeConstants = { + ACCOUNT: 'ACCOUNT', + PHONE: 'PHONE', + EMAIL: 'EMAIL', + SOCIAL: 'SOCIAL', +} as const + +/** 基础认证请求接口 */ export interface AuthReq { clientId?: string - authType?: string + authType?: AuthType } /** 账号登录请求参数 */ @@ -73,12 +77,12 @@ export interface EmailLoginReq extends AuthReq { captcha: string } -// 登录响应类型 +/** 登录响应类型 */ export interface LoginResp { token: string } -// 第三方登录授权类型 +/** 第三方登录授权类型 */ export interface SocialAuthAuthorizeResp { authorizeUrl: string } diff --git a/src/stores/modules/user.ts b/src/stores/modules/user.ts index 7599a26..a363b38 100644 --- a/src/stores/modules/user.ts +++ b/src/stores/modules/user.ts @@ -3,7 +3,7 @@ import { computed, reactive, ref } from 'vue' import { resetRouter } from '@/router' import { type AccountLoginReq, - AuthTypeEnum, + AuthTypeConstants, type EmailLoginReq, type PhoneLoginReq, type UserInfo, @@ -51,28 +51,28 @@ const storeSetup = () => { // 登录 const accountLogin = async (req: AccountLoginReq) => { - const res = await accountLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.ACCOUNT }) + const res = await accountLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.ACCOUNT }) setToken(res.data.token) token.value = res.data.token } // 邮箱登录 const emailLogin = async (req: EmailLoginReq) => { - const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.EMAIL }) + const res = await emailLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.EMAIL }) setToken(res.data.token) token.value = res.data.token } // 手机号登录 const phoneLogin = async (req: PhoneLoginReq) => { - const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.PHONE }) + const res = await phoneLoginApi({ ...req, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.PHONE }) setToken(res.data.token) token.value = res.data.token } // 三方账号登录 const socialLogin = async (source: string, req: any) => { - const res = await socialLoginApi({ ...req, source, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeEnum.SOCIAL }) + const res = await socialLoginApi({ ...req, source, clientId: import.meta.env.VITE_CLIENT_ID, authType: AuthTypeConstants.SOCIAL }) setToken(res.data.token) token.value = res.data.token }