diff --git a/frontend/src/pages/ProfilePage.tsx b/frontend/src/pages/ProfilePage.tsx index 1f2cb31..600f554 100644 --- a/frontend/src/pages/ProfilePage.tsx +++ b/frontend/src/pages/ProfilePage.tsx @@ -3,6 +3,7 @@ import { Card, Typography, Form, Input, Button, Avatar, Space, Upload, message, import { UserOutlined, LockOutlined, PhoneOutlined, MailOutlined, UploadOutlined } from '@ant-design/icons'; import { useAuthStore } from '../store/authStore'; import useFormDraft from '../hooks/useFormDraft'; +import apiClient from '../utils/request'; const { Title, Paragraph } = Typography; @@ -78,21 +79,14 @@ const ProfilePage: React.FC = () => { const values = await form.validateFields(); setLoading(true); - // 调用API更新用户信息 - const response = await fetch(`/api/users/${user?.id}`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - ...values, - avatar: avatarUrl, - passport: passportUrl, - driverLicense: driverLicenseUrl - }) + const response = await apiClient.put(`/users/${user?.id}`, { + ...values, + avatar: avatarUrl, + passport: passportUrl, + driverLicense: driverLicenseUrl }); - const data = await response.json(); + const data = response.data; if (data.success) { message.success('个人信息已更新'); // 更新authStore中的用户信息 @@ -121,19 +115,12 @@ const ProfilePage: React.FC = () => { try { const values = await passwordForm.validateFields(); - // 调用API更新密码 - const response = await fetch(`/api/users/${user?.id}/password`, { - method: 'PUT', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - currentPassword: values.currentPassword, - newPassword: values.newPassword - }) + const response = await apiClient.put(`/users/${user?.id}/password`, { + currentPassword: values.currentPassword, + newPassword: values.newPassword }); - const data = await response.json(); + const data = response.data; if (data.success) { message.success('密码已更新'); setPasswordModalVisible(false);