user.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // src/api/user.ts
  2. import { request } from '@/utils/request';
  3. // 获取用户信息的响应数据接口
  4. interface UserProfileData {
  5. birthday: string | null;
  6. contactEmail: string | null;
  7. createTime: string;
  8. englishName: string | null;
  9. gender: number | null; // 【修正】后端返回的是 number
  10. id: number;
  11. lastLoginTime: string | null;
  12. name: string;
  13. officialEmail: string;
  14. officialNumber: string;
  15. password: string;
  16. phone: string;
  17. pid: string | null; // 【修正】pid 是 string
  18. role: number; // 【修正】后端返回的是 number
  19. userAvatar: string;
  20. }
  21. export interface UserProfileResponse {
  22. code: number;
  23. data: UserProfileData;
  24. msg: string;
  25. }
  26. // 更新用户信息的请求体接口
  27. interface UpdateUserInfoRequest {
  28. name?: string;
  29. officialEmail?: string | null;
  30. officialNumber?: string | null;
  31. role?: 'STUDENT' | 'TEACHER' | null;
  32. userAvatar?: string | null;
  33. englishName?: string | null;
  34. gender?: number | string | null;
  35. birthday?: string | null;
  36. contentEmail?: string | null;
  37. }
  38. /**
  39. * 获取当前用户个人信息
  40. * GET /api/auth
  41. * @param officialNumber 学生的学号/工号,用于查询
  42. */
  43. export const getUserProfileApi = (officialNumber: string | number): Promise<UserProfileData> => {
  44. return request<UserProfileData>({
  45. url: '/auth',
  46. method: 'GET',
  47. params: { officialNumber }
  48. });
  49. };
  50. /**
  51. * 修改用户信息
  52. * PUT /api/auth
  53. * @param data 需要修改的用户信息
  54. */
  55. export const updateUserProfileApi = (data: UpdateUserInfoRequest): Promise<void> => {
  56. return request<void>({
  57. url: '/auth',
  58. method: 'PUT',
  59. data
  60. });
  61. };