From 07809e4d3db03a86d4a2f607af0b7e3ac3623618 Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Sat, 31 Jan 2026 21:17:37 +0800 Subject: [PATCH] fix: third api --- pages/mine/profile.vue | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/pages/mine/profile.vue b/pages/mine/profile.vue index f2dfc66..8a9adef 100644 --- a/pages/mine/profile.vue +++ b/pages/mine/profile.vue @@ -27,9 +27,9 @@ " mode="aspectFill" /> - + 更换头像 @@ -143,24 +143,33 @@ const handleAvatarClick = () => { }); }; -const handleEditName = () => { +const showEditNameModal = (content) => { uni.showModal({ title: "修改昵称", editable: true, placeholderText: "请输入昵称(最多5个字)", - content: form.value.nickName, + content: content, success: (res) => { if (res.confirm) { if (res.content.length > 5) { uni.showToast({ title: "昵称最多5个字", icon: "none" }); + // 重新打开弹窗以模拟“不消失”,并保留用户输入 + setTimeout(() => { + showEditNameModal(res.content); + }, 100); return; } form.value.nickName = res.content; + handleSave(); } }, }); }; +const handleEditName = () => { + showEditNameModal(form.value.nickName); +}; + const handleEditGender = () => { uni.showActionSheet({ itemList: ["男", "女"], @@ -194,12 +203,16 @@ const handleSave = async () => { } uni.showLoading({ title: "保存中...", mask: true }); + // 保存当前值,以便失败时恢复 + const originalForm = { + nickName: userInfo.value.nickName || "", + gender: userInfo.value.gender || 1, + bio: userInfo.value.bio || "万事如意,岁岁平安" + }; + try { const res = await updateUserInfo({ - nickname: form.value.nickName, // Prompt said "nickname" lowercase, I used "nickName" in ref but need to check param name. - // Prompt: "请求参数分别是nickname gender bio" - // Wait, prompt said "nickname", usually it is nickName in Uni-app userInfo. - // But I will follow prompt "nickname". + nickname: form.value.nickName, gender: form.value.gender, bio: form.value.bio, }); @@ -210,14 +223,14 @@ const handleSave = async () => { uni.hideLoading(); uni.showToast({ title: "保存成功", icon: "success" }); } else { + // 恢复之前的内容 + form.value = { ...originalForm }; + uni.showToast({ title: res.message || '修改失败', icon: "none" }); uni.hideLoading(); - // If res is not success but request didn't fail, maybe backend returns something else? - // Assuming request wrapper handles non-200 business codes by rejecting, - // so here we might just have data. - // If prompt says "returns { success: true }", then checking res.success is correct. - // If it fails, request throws error usually. } } catch (e) { + // 恢复之前的内容 + form.value = { ...originalForm }; uni.hideLoading(); // Error is handled by request usually if showError is true. // But we can show toast too.