Files
JayuCloud/JC-Salon-Frontend/src/api/auth.ts
T

252 lines
9.8 KiB
TypeScript
Raw Normal View History

/**
* Front-end API wrapper for this module.
* Call guide: import the named API object, then call the matching method from a Vue page or composable.
*/
2026-02-24 09:59:22 +08:00
import api from './index'
2026-03-27 14:55:41 +08:00
import type { IdType } from '@/utils/id'
2026-02-24 09:59:22 +08:00
2026-05-23 18:44:57 +08:00
/**
* Purpose: SendVerificationCodeRequest supports auth.ts by holding or executing the send verification code request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-19 14:10:59 +08:00
export interface SendVerificationCodeRequest {
phone: string
sceneCode?: string
2026-03-19 14:10:59 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: LoginRequest supports auth.ts by holding or executing the login request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
export interface LoginRequest {
account: string
password: string
rememberMe?: boolean
shopId?: string | number
agreementAccepted?: boolean
agreementVersions?: Record<string, string>
clientType?: string
2026-02-24 09:59:22 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: PhoneLoginRequest supports auth.ts by holding or executing the phone login request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
export interface PhoneLoginRequest {
phone: string
verificationCode: string
shopId?: string | number
agreementAccepted?: boolean
agreementVersions?: Record<string, string>
clientType?: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: RegisterRequest supports auth.ts by holding or executing the register request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
export interface RegisterRequest {
account: string
password: string
nickname: string
shopId?: string | number
inviteCode?: string
2026-03-10 23:23:15 +08:00
phone?: string
verificationCode?: string
agreementAccepted?: boolean
agreementVersions?: Record<string, string>
clientType?: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: LegalAgreement supports auth.ts by holding or executing the legal agreement page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
export interface LegalAgreement {
id: IdType
agreementType: 'USER_TERMS' | 'PRIVACY_POLICY'
agreementTypeName: string
title: string
version: string
content: string
status: number
statusText?: string
effectiveTime?: string
2026-02-24 09:59:22 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: LoginResponse supports auth.ts by holding or executing the login response page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
export interface LoginResponse {
accessToken: string
refreshToken: string
userInfo: UserInfo
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: UserInfo supports auth.ts by holding or executing the user info page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
export interface UserInfo {
2026-03-27 14:55:41 +08:00
id: IdType
2026-02-24 09:59:22 +08:00
account: string
nickname: string
avatar?: string
2026-02-25 09:13:45 +08:00
signature?: string
type?: number
2026-03-27 14:55:41 +08:00
shopId?: IdType
2026-02-25 09:13:45 +08:00
shopName?: string
shopAuthorizationExpireTime?: string
shopAuthorizationExpired?: boolean
2026-03-27 14:55:41 +08:00
shopIds?: IdType[]
shopNames?: string[]
2026-02-24 09:59:22 +08:00
createTime: string
2026-02-25 09:13:45 +08:00
updateTime?: string
2026-02-24 09:59:22 +08:00
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: RefreshTokenRequest supports auth.ts by holding or executing the refresh token request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
export interface RefreshTokenRequest {
refreshToken: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: RefreshTokenResponse supports auth.ts by holding or executing the refresh token response page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-02-24 09:59:22 +08:00
export interface RefreshTokenResponse {
accessToken: string
refreshToken: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: ResetPasswordRequest supports auth.ts by holding or executing the reset password request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
2026-03-19 14:10:59 +08:00
export interface ResetPasswordRequest {
phone: string
verificationCode: string
newPassword: string
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: SwitchShopRequest supports auth.ts by holding or executing the switch shop request page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
export interface SwitchShopRequest {
shopId?: string | number
}
/**
* authApi groups all API calls for this page domain.
* Call guide: pass the typed payload or identifier into the method below, and use the returned Promise in the page script.
*/
2026-02-24 09:59:22 +08:00
export const authApi = {
/**
* `sendVerificationCode` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: SendVerificationCodeRequest caller-supplied value for `data: SendVerificationCodeRequest`
*/
2026-03-19 14:10:59 +08:00
sendVerificationCode: (data: SendVerificationCodeRequest) => {
return api.post('/user/send-verification-code', data)
},
/**
* `login` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: LoginRequest caller-supplied value for `data: LoginRequest`
*/
2026-02-24 09:59:22 +08:00
login: (data: LoginRequest) => {
return api.post<LoginResponse>('/user/login', data)
},
/**
* `phoneLogin` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: PhoneLoginRequest caller-supplied value for `data: PhoneLoginRequest`
*/
phoneLogin: (data: PhoneLoginRequest) => {
return api.post<LoginResponse>('/user/phone-login', data)
},
/**
* `adminLogin` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: LoginRequest caller-supplied value for `data: LoginRequest`
*/
adminLogin: (data: LoginRequest) => {
return api.post<LoginResponse>('/admin/auth/login', data)
},
/**
* `register` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: RegisterRequest caller-supplied value for `data: RegisterRequest`
*/
2026-02-24 09:59:22 +08:00
register: (data: RegisterRequest) => {
return api.post('/user/register', data)
},
/**
* `refreshToken` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: RefreshTokenRequest caller-supplied value for `data: RefreshTokenRequest`
*/
2026-02-24 09:59:22 +08:00
refreshToken: (data: RefreshTokenRequest) => {
return api.post<RefreshTokenResponse>('/user/refresh-token', data)
},
/**
* `logout` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
*/
2026-02-24 09:59:22 +08:00
logout: () => {
return api.post('/user/logout')
},
/**
* `switchShop` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: SwitchShopRequest caller-supplied value for `data: SwitchShopRequest`
*/
switchShop: (data: SwitchShopRequest) => {
return api.post<LoginResponse>('/user/switch-shop', data)
},
/**
* `getUserInfo` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
*/
2026-02-24 09:59:22 +08:00
getUserInfo: () => {
return api.get<UserInfo>('/user/info')
2026-03-19 14:10:59 +08:00
},
/**
* `resetPasswordByPhone` API call. Use this method from the page script to invoke the backend endpoint tied to this feature.
* Call guide: supply the parameters below, await the returned Promise, and handle loading / error UI in the caller.
* @param data: ResetPasswordRequest caller-supplied value for `data: ResetPasswordRequest`
*/
2026-03-19 14:10:59 +08:00
resetPasswordByPhone: (data: ResetPasswordRequest) => {
return api.post('/user/reset-password-by-phone', data)
2026-02-24 09:59:22 +08:00
}
}
2026-05-23 18:44:57 +08:00
/**
* Purpose: legalAgreementApi supports auth.ts by holding or executing the legal agreement api page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
export const legalAgreementApi = {
listCurrent: () => {
return api.get<LegalAgreement[]>('/legal-agreement/current')
},
getCurrent: (type: 'USER_TERMS' | 'PRIVACY_POLICY') => {
return api.get<LegalAgreement>(`/legal-agreement/current/${type}`)
},
getMyConsent: () => {
return api.get<{ consentVersions: Record<string, string> }>('/user/agreement-consent/me')
}
}