37 lines
821 B
TypeScript
37 lines
821 B
TypeScript
|
import request from '@/utils/request'
|
||
|
import type { ApiResponse } from './types'
|
||
|
|
||
|
export interface LoginParams {
|
||
|
username: string
|
||
|
password: string
|
||
|
}
|
||
|
|
||
|
export interface UserInfo {
|
||
|
id: number
|
||
|
username: string
|
||
|
nickname: string
|
||
|
avatar: string
|
||
|
roles: string[]
|
||
|
}
|
||
|
|
||
|
export const userApi = {
|
||
|
// 登录
|
||
|
login(data: LoginParams) {
|
||
|
return request.post<ApiResponse<{ token: string }>>('/auth/login', data)
|
||
|
},
|
||
|
|
||
|
// 获取用户信息
|
||
|
getUserInfo() {
|
||
|
return request.get<ApiResponse<UserInfo>>('/user/info')
|
||
|
},
|
||
|
|
||
|
// 修改密码
|
||
|
changePassword(data: { oldPassword: string; newPassword: string }) {
|
||
|
return request.post<ApiResponse>('/user/change-password', data)
|
||
|
},
|
||
|
|
||
|
// 更新用户信息
|
||
|
updateUserInfo(data: Partial<UserInfo>) {
|
||
|
return request.put<ApiResponse>('/user/info', data)
|
||
|
}
|
||
|
}
|