72 lines
1.6 KiB
TypeScript
72 lines
1.6 KiB
TypeScript
import { request } from '../request'
|
|
import { ApiResponse } from '../types'
|
|
|
|
// 认证相关类型
|
|
export interface LoginRequest {
|
|
username: string
|
|
password: string
|
|
}
|
|
|
|
export interface PhoneLoginRequest {
|
|
phone: string
|
|
code: string
|
|
}
|
|
|
|
export interface LoginResponse {
|
|
token: string
|
|
refreshToken: string
|
|
user: {
|
|
id: string
|
|
username: string
|
|
phone: string
|
|
role: string
|
|
tenantId: string
|
|
}
|
|
}
|
|
|
|
export interface User {
|
|
id: string
|
|
username: string
|
|
phone: string
|
|
role: string
|
|
tenantId: string
|
|
avatar?: string
|
|
email?: string
|
|
}
|
|
|
|
export const authApi = {
|
|
// 用户名密码登录
|
|
login: (data: LoginRequest): Promise<ApiResponse<LoginResponse>> => {
|
|
return request.post('/auth/login', data)
|
|
},
|
|
|
|
// 手机验证码登录
|
|
loginByPhone: (data: PhoneLoginRequest): Promise<ApiResponse<LoginResponse>> => {
|
|
return request.post('/auth/login/phone', data)
|
|
},
|
|
|
|
// 获取验证码
|
|
sendSmsCode: (phone: string): Promise<ApiResponse<void>> => {
|
|
return request.post('/auth/sms/send', { phone })
|
|
},
|
|
|
|
// 刷新token
|
|
refreshToken: (refreshToken: string): Promise<ApiResponse<{ token: string }>> => {
|
|
return request.post('/auth/refresh', { refreshToken })
|
|
},
|
|
|
|
// 登出
|
|
logout: (): Promise<ApiResponse<void>> => {
|
|
return request.post('/auth/logout')
|
|
},
|
|
|
|
// 获取用户信息
|
|
getUserInfo: (): Promise<ApiResponse<User>> => {
|
|
return request.get('/auth/user')
|
|
},
|
|
|
|
// 更新用户信息
|
|
updateUserInfo: (data: Partial<User>): Promise<ApiResponse<User>> => {
|
|
return request.put('/auth/user', data)
|
|
}
|
|
} |