提交1 bmad搭建与项目启动 - ok
This commit is contained in:
72
crop-x/src/apis/modules/auth.ts
Normal file
72
crop-x/src/apis/modules/auth.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user