diff --git a/src/api/user.ts b/src/api/user.ts index 1e96d5e8..be660af9 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -146,9 +146,9 @@ class UserAPI { } /** 修改个人中心用户信息 */ - static updateProfile(id: number, data: UserProfileForm) { + static updateProfile(data: UserProfileForm) { return request({ - url: `${USER_BASE_URL}/${id}/profile`, + url: `${USER_BASE_URL}/profile`, method: "put", data: data, }); @@ -176,6 +176,24 @@ class UserAPI { params: { contact: contact, contactType: contactType }, }); } + + /** 绑定个人中心用户手机 */ + static bindMobile(data: MobileBindingForm) { + return request({ + url: `${USER_BASE_URL}/mobile`, + method: "put", + data: data, + }); + } + + /** 丙丁个人中心用户邮箱 */ + static bindEmail(data: EmailBindingForm) { + return request({ + url: `${USER_BASE_URL}/email`, + method: "put", + data: data, + }); + } } export default UserAPI; @@ -335,17 +353,17 @@ export interface PasswordChangeForm { confirmPassword?: string; } -/** 手机绑定表单 */ +/** 修改手机表单 */ export interface MobileBindingForm { - /** 新手机号 */ + /** 手机号 */ mobile?: string; /** 验证码 */ code?: string; } -/** 邮箱绑定表单 */ +/** 修改邮箱表单 */ export interface EmailBindingForm { - /** 新邮箱 */ + /** 邮箱 */ email?: string; /** 验证码 */ code?: string; diff --git a/src/views/profile/index.vue b/src/views/profile/index.vue index ccf03c2b..aa98d27d 100644 --- a/src/views/profile/index.vue +++ b/src/views/profile/index.vue @@ -451,7 +451,7 @@ const handleSendVerificationCode = async (contactType: string) => { */ const handleSubmit = async () => { if (dialog.type === DialogType.ACCOUNT) { - UserAPI.updateProfile(userProfileForm.id, userProfileForm).then(() => { + UserAPI.updateProfile(userProfileForm).then(() => { ElMessage.success("账号资料修改成功"); dialog.visible = false; loadUserProfile(); @@ -465,10 +465,18 @@ const handleSubmit = async () => { ElMessage.success("密码修改成功"); dialog.visible = false; }); - } else if (dialog.type === "mobile") { - //await UserAPI.bindMobile(mobileBindingForm.value); - } else if (dialog.type === "email") { - //await UserAPI.bindEmail(emailBindingForm.value); + } else if (dialog.type === DialogType.MOBILE) { + UserAPI.bindMobile(mobileBindingForm).then(() => { + ElMessage.success("手机号绑定成功"); + dialog.visible = false; + loadUserProfile(); + }); + } else if (dialog.type === DialogType.EMAIL) { + UserAPI.bindEmail(emailBindingForm).then(() => { + ElMessage.success("邮箱绑定成功"); + dialog.visible = false; + loadUserProfile(); + }); } }; @@ -488,7 +496,7 @@ const handleFileChange = async (event: Event) => { // 更新用户头像 userProfile.value.avatar = data.url; // 更新用户信息 - await UserAPI.updateProfile(userProfile.value.id, { + await UserAPI.updateProfile(userProfile.value.id as number, { avatar: data.url, }); } catch (error) {