From 1e49191b9acedb6670bd5bf7a719334fa78b9893 Mon Sep 17 00:00:00 2001 From: ovo Date: Fri, 6 Dec 2024 22:01:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=90=8E=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.ts | 66 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/src/api/user.ts b/src/api/user.ts index 2f4e0e4..2314dfb 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -1,37 +1,79 @@ import request from '@/utils/request' -import type { ApiResponse } from './types' +import type { ApiResponse, PageResult } from './types' +// 定义接口的请求参数类型 export interface LoginParams { - username: string + phone: string password: string + verifyCode?: string } +// 定义后端返回的用户信息类型 export interface UserInfo { id: number - username: string + phone: string nickname: string avatar: string - roles: string[] + gender: 0 | 1 // 0-女 1-男 + age: number + address: string + emergencyContact: { + name: string + phone: string + relation: string + } } +// 定义用户列表查询参数 +export interface UserQueryParams { + page: number + pageSize: number + nickname?: string + phone?: string + gender?: 0 | 1 + ageRange?: [number, number] +} + +// 用户API接口 export const userApi = { - // 登录 + // 手机号密码登录 login(data: LoginParams) { return request.post>('/auth/login', data) }, - // 获取用户信息 - getUserInfo() { - return request.get>('/user/info') + // 发送验证码 + sendVerifyCode(phone: string) { + return request.post>('/auth/send-code', { phone }) }, - // 修改密码 - changePassword(data: { oldPassword: string; newPassword: string }) { - return request.post('/user/change-password', data) + // 获取当前登录用户信息 + getCurrentUser() { + return request.get>('/user/current') }, // 更新用户信息 updateUserInfo(data: Partial) { - return request.put('/user/info', data) + return request.put>('/user/info', data) + }, + + // 更新用户头像 + updateAvatar(file: File) { + const formData = new FormData() + formData.append('avatar', file) + return request.post>('/user/avatar', formData, { + headers: { + 'Content-Type': 'multipart/form-data' + } + }) + }, + + // 分页获取用户列表(管理员接口) + getUserList(params: UserQueryParams) { + return request.get>>('/admin/users', { params }) + }, + + // 修改密码 + changePassword(data: { oldPassword: string; newPassword: string }) { + return request.post>('/user/change-password', data) } } \ No newline at end of file