From 57e876522ec2830eddbd7b559550291ccc07ecac Mon Sep 17 00:00:00 2001 From: ray <1490493387@qq.com> Date: Tue, 20 Aug 2024 00:12:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=AD=E5=BF=83=E6=89=8B=E6=9C=BA=E5=8F=B7=E5=92=8C=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.ts | 30 ++++++++++++++++++++++++------ src/views/profile/index.vue | 20 ++++++++++++++------ 2 files changed, 38 insertions(+), 12 deletions(-) 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) {