From 5fd19822a2a74af0bf8bffe830ac7da8bfca6520 Mon Sep 17 00:00:00 2001 From: a273825743 Date: Sun, 17 May 2026 10:44:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DProfilePage=EF=BC=9Afetch?= =?UTF-8?q?=E6=94=B9=E4=B8=BAapiClient=EF=BC=8C=E4=BF=AE=E5=A4=8D=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81401=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/ProfilePage.tsx | 35 ++++++++++-------------------- 1 file changed, 11 insertions(+), 24 deletions(-) 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);