types: 认证类型定义调整

This commit is contained in:
KAI
2025-03-11 16:34:45 +08:00
parent 0f8c9aec25
commit 5ed7056c05
2 changed files with 18 additions and 14 deletions

View File

@@ -42,15 +42,19 @@ export interface RouteItem {
} }
/** 认证类型 */ /** 认证类型 */
export enum AuthTypeEnum { export type AuthType = 'ACCOUNT' | 'PHONE' | 'EMAIL' | 'SOCIAL'
ACCOUNT = 'ACCOUNT',
PHONE = 'PHONE', export const AuthTypeConstants = {
EMAIL = 'EMAIL', ACCOUNT: 'ACCOUNT',
SOCIAL = 'SOCIAL', PHONE: 'PHONE',
} EMAIL: 'EMAIL',
SOCIAL: 'SOCIAL',
} as const
/** 基础认证请求接口 */
export interface AuthReq { export interface AuthReq {
clientId?: string clientId?: string
authType?: string authType?: AuthType
} }
/** 账号登录请求参数 */ /** 账号登录请求参数 */
@@ -73,12 +77,12 @@ export interface EmailLoginReq extends AuthReq {
captcha: string captcha: string
} }
// 登录响应类型 /** 登录响应类型 */
export interface LoginResp { export interface LoginResp {
token: string token: string
} }
// 第三方登录授权类型 /** 第三方登录授权类型 */
export interface SocialAuthAuthorizeResp { export interface SocialAuthAuthorizeResp {
authorizeUrl: string authorizeUrl: string
} }

View File

@@ -3,7 +3,7 @@ import { computed, reactive, ref } from 'vue'
import { resetRouter } from '@/router' import { resetRouter } from '@/router'
import { import {
type AccountLoginReq, type AccountLoginReq,
AuthTypeEnum, AuthTypeConstants,
type EmailLoginReq, type EmailLoginReq,
type PhoneLoginReq, type PhoneLoginReq,
type UserInfo, type UserInfo,
@@ -51,28 +51,28 @@ const storeSetup = () => {
// 登录 // 登录
const accountLogin = async (req: AccountLoginReq) => { 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) setToken(res.data.token)
token.value = res.data.token token.value = res.data.token
} }
// 邮箱登录 // 邮箱登录
const emailLogin = async (req: EmailLoginReq) => { 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) setToken(res.data.token)
token.value = res.data.token token.value = res.data.token
} }
// 手机号登录 // 手机号登录
const phoneLogin = async (req: PhoneLoginReq) => { 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) setToken(res.data.token)
token.value = res.data.token token.value = res.data.token
} }
// 三方账号登录 // 三方账号登录
const socialLogin = async (source: string, req: any) => { 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) setToken(res.data.token)
token.value = res.data.token token.value = res.data.token
} }