Skip to content

Commit e0c08e6

Browse files
committed
fix(profile): 修复个人中心数据加载失败问题
修复个人中心数据加载失败问题
1 parent 221a0ae commit e0c08e6

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

frontend/src/components/dashboard/ProfileView.jsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,24 @@ export default function ProfileView() {
8181
const uuidResponse = await apiClient.get(`/user/uuid?username=${statusResponse.data.username}`);
8282
if (uuidResponse && uuidResponse.data?.uuid) {
8383
const profileResponse = await apiClient.get(`/user/${uuidResponse.data.uuid}`);
84-
if (profileResponse) {
85-
const birthdayFormatted = profileResponse.birthday
86-
? profileResponse.birthday.substring(0, 10)
84+
if (profileResponse && profileResponse.data) {
85+
const data = profileResponse.data;
86+
const birthdayFormatted = data.birthday
87+
? data.birthday.substring(0, 10)
8788
: '';
8889

89-
const processedAvatar = profileResponse.avatar
90-
? getFullImageUrl(profileResponse.avatar)
90+
const processedAvatar = data.avatar
91+
? getFullImageUrl(data.avatar)
9192
: '/image_error.svg';
9293

9394
// 用户信息转义避免潜在的xss
9495
const userData = {
95-
uuid: profileResponse.uuid || '',
96-
username: escapeHtml(profileResponse.username) || '',
97-
avatar: profileResponse.avatar || '',
98-
phone: escapeHtml(profileResponse.phone) || '',
99-
email: escapeHtml(profileResponse.email) || '',
100-
gender: escapeHtml(profileResponse.gender) || '',
96+
uuid: data.uuid || '',
97+
username: escapeHtml(data.username) || '',
98+
avatar: data.avatar || '',
99+
phone: escapeHtml(data.phone) || '',
100+
email: escapeHtml(data.email) || '',
101+
gender: escapeHtml(data.gender) || '',
101102
birthday: birthdayFormatted,
102103
};
103104

@@ -207,13 +208,13 @@ export default function ProfileView() {
207208
}
208209
});
209210

210-
if (response && response.data?.fileUrl) {
211+
if (response && response.fileUrl) {
211212
setUser(prev => ({
212213
...prev,
213-
avatar: response.data.fileUrl
214+
avatar: response.fileUrl
214215
}));
215216

216-
const processedAvatar = getFullImageUrl(response.data.fileUrl);
217+
const processedAvatar = getFullImageUrl(response.fileUrl);
217218
setPreviewAvatar(processedAvatar || '/image_error.svg');
218219
showMessage('头像上传成功', 'success');
219220
} else {

0 commit comments

Comments
 (0)