2026-02-24 09:59:22 +08:00
|
|
|
import api from './index'
|
|
|
|
|
|
2026-03-19 14:10:59 +08:00
|
|
|
export interface SendVerificationCodeRequest {
|
|
|
|
|
phone: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
export interface LoginRequest {
|
|
|
|
|
account: string
|
|
|
|
|
password: string
|
|
|
|
|
rememberMe?: boolean
|
2026-03-26 10:28:28 +08:00
|
|
|
shopId?: string | number
|
2026-02-24 09:59:22 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-03 14:39:02 +08:00
|
|
|
export interface PhoneLoginRequest {
|
|
|
|
|
phone: string
|
|
|
|
|
verificationCode: string
|
2026-03-26 10:28:28 +08:00
|
|
|
shopId?: string | number
|
2026-03-03 14:39:02 +08:00
|
|
|
}
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
export interface RegisterRequest {
|
|
|
|
|
account: string
|
|
|
|
|
password: string
|
|
|
|
|
nickname: string
|
2026-03-26 10:28:28 +08:00
|
|
|
shopId?: string | number
|
2026-03-10 23:23:15 +08:00
|
|
|
phone?: string
|
|
|
|
|
verificationCode?: string
|
2026-02-24 09:59:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface LoginResponse {
|
|
|
|
|
accessToken: string
|
|
|
|
|
refreshToken: string
|
|
|
|
|
userInfo: UserInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface UserInfo {
|
|
|
|
|
id: number
|
|
|
|
|
account: string
|
|
|
|
|
nickname: string
|
|
|
|
|
avatar?: string
|
2026-02-25 09:13:45 +08:00
|
|
|
signature?: string
|
2026-03-26 10:28:28 +08:00
|
|
|
type?: number
|
|
|
|
|
shopId?: number | string
|
2026-02-25 09:13:45 +08:00
|
|
|
shopName?: string
|
2026-03-26 10:28:28 +08:00
|
|
|
shopIds?: Array<number | string>
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RefreshTokenRequest {
|
|
|
|
|
refreshToken: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface RefreshTokenResponse {
|
|
|
|
|
accessToken: string
|
|
|
|
|
refreshToken: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-19 14:10:59 +08:00
|
|
|
export interface ResetPasswordRequest {
|
|
|
|
|
phone: string
|
|
|
|
|
verificationCode: string
|
|
|
|
|
newPassword: string
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-26 10:28:28 +08:00
|
|
|
export interface SwitchShopRequest {
|
|
|
|
|
shopId?: string | number
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
export const authApi = {
|
2026-03-19 14:10:59 +08:00
|
|
|
sendVerificationCode: (data: SendVerificationCodeRequest) => {
|
|
|
|
|
return api.post('/user/send-verification-code', data)
|
|
|
|
|
},
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
login: (data: LoginRequest) => {
|
|
|
|
|
return api.post<LoginResponse>('/user/login', data)
|
|
|
|
|
},
|
|
|
|
|
|
2026-03-03 14:39:02 +08:00
|
|
|
phoneLogin: (data: PhoneLoginRequest) => {
|
|
|
|
|
return api.post<LoginResponse>('/user/phone-login', data)
|
|
|
|
|
},
|
|
|
|
|
|
2026-02-27 16:44:41 +08:00
|
|
|
adminLogin: (data: LoginRequest) => {
|
2026-02-27 22:20:25 +08:00
|
|
|
return api.post<LoginResponse>('/admin/auth/login', data)
|
2026-02-27 16:44:41 +08:00
|
|
|
},
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
register: (data: RegisterRequest) => {
|
|
|
|
|
return api.post('/user/register', data)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
refreshToken: (data: RefreshTokenRequest) => {
|
|
|
|
|
return api.post<RefreshTokenResponse>('/user/refresh-token', data)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
logout: () => {
|
|
|
|
|
return api.post('/user/logout')
|
|
|
|
|
},
|
|
|
|
|
|
2026-03-26 10:28:28 +08:00
|
|
|
switchShop: (data: SwitchShopRequest) => {
|
|
|
|
|
return api.post<LoginResponse>('/user/switch-shop', data)
|
|
|
|
|
},
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
getUserInfo: () => {
|
|
|
|
|
return api.get<UserInfo>('/user/info')
|
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-03-26 10:28:28 +08:00
|
|
|
}
|