fix: third api

This commit is contained in:
zzc
2026-01-31 21:17:37 +08:00
parent a6ee0f8be6
commit 07809e4d3d

View File

@@ -27,9 +27,9 @@
" "
mode="aspectFill" mode="aspectFill"
/> />
<!-- <view class="camera-badge"> <view class="camera-badge">
<uni-icons type="camera-filled" size="16" color="#ff3b30" /> <uni-icons type="camera-filled" size="16" color="#ff3b30" />
</view> --> </view>
</view> </view>
<text class="change-avatar-text">更换头像</text> <text class="change-avatar-text">更换头像</text>
</view> </view>
@@ -143,24 +143,33 @@ const handleAvatarClick = () => {
}); });
}; };
const handleEditName = () => { const showEditNameModal = (content) => {
uni.showModal({ uni.showModal({
title: "修改昵称", title: "修改昵称",
editable: true, editable: true,
placeholderText: "请输入昵称(最多5个字)", placeholderText: "请输入昵称(最多5个字)",
content: form.value.nickName, content: content,
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
if (res.content.length > 5) { if (res.content.length > 5) {
uni.showToast({ title: "昵称最多5个字", icon: "none" }); uni.showToast({ title: "昵称最多5个字", icon: "none" });
// 重新打开弹窗以模拟“不消失”,并保留用户输入
setTimeout(() => {
showEditNameModal(res.content);
}, 100);
return; return;
} }
form.value.nickName = res.content; form.value.nickName = res.content;
handleSave();
} }
}, },
}); });
}; };
const handleEditName = () => {
showEditNameModal(form.value.nickName);
};
const handleEditGender = () => { const handleEditGender = () => {
uni.showActionSheet({ uni.showActionSheet({
itemList: ["男", "女"], itemList: ["男", "女"],
@@ -194,12 +203,16 @@ const handleSave = async () => {
} }
uni.showLoading({ title: "保存中...", mask: true }); uni.showLoading({ title: "保存中...", mask: true });
// 保存当前值,以便失败时恢复
const originalForm = {
nickName: userInfo.value.nickName || "",
gender: userInfo.value.gender || 1,
bio: userInfo.value.bio || "万事如意,岁岁平安"
};
try { try {
const res = await updateUserInfo({ const res = await updateUserInfo({
nickname: form.value.nickName, // Prompt said "nickname" lowercase, I used "nickName" in ref but need to check param name. nickname: form.value.nickName,
// Prompt: "请求参数分别是nickname gender bio"
// Wait, prompt said "nickname", usually it is nickName in Uni-app userInfo.
// But I will follow prompt "nickname".
gender: form.value.gender, gender: form.value.gender,
bio: form.value.bio, bio: form.value.bio,
}); });
@@ -210,14 +223,14 @@ const handleSave = async () => {
uni.hideLoading(); uni.hideLoading();
uni.showToast({ title: "保存成功", icon: "success" }); uni.showToast({ title: "保存成功", icon: "success" });
} else { } else {
// 恢复之前的内容
form.value = { ...originalForm };
uni.showToast({ title: res.message || '修改失败', icon: "none" });
uni.hideLoading(); 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) { } catch (e) {
// 恢复之前的内容
form.value = { ...originalForm };
uni.hideLoading(); uni.hideLoading();
// Error is handled by request usually if showError is true. // Error is handled by request usually if showError is true.
// But we can show toast too. // But we can show toast too.