diff --git a/src/api/user.ts b/src/api/user.ts index 2314dfb..5a74f5a 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -2,6 +2,30 @@ import request from '@/utils/request' import type { ApiResponse, PageResult } from './types' // 定义接口的请求参数类型 + + +/** + * 关键点说明: + * 类型定义: + * 使用 interface 定义接口的请求参数和响应数据类型 + * 使用 Partial 表示部分可选的类型 + * 使用联合类型定义枚举值,如 0 | 1 + * 请求方法: + * request.get() - GET请求 + * request.post() - POST请求 + * request.put() - PUT请求 + * 泛型参数 T 用于定义响应数据的类型 + * 错误处理: + * 使用 try/catch 捕获请求错误 + * 统一的错误提示 + * 文件上传: + * 使用 FormData 处理文件上传 + * 设置正确的 Content-Type + * 类型推导: + * TypeScript 会自动推导 API 响应的类型 + * 编辑器会提供代码提示和类型检查 + */ + export interface LoginParams { phone: string password: string @@ -76,4 +100,4 @@ export const userApi = { changePassword(data: { oldPassword: string; newPassword: string }) { return request.post>('/user/change-password', data) } -} \ No newline at end of file +}