From 9392fe99389fc3941cc9a673b5a218458d11dd4a Mon Sep 17 00:00:00 2001 From: yangyao Date: Tue, 20 Jan 2026 18:10:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BF=AE=E6=94=B9=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=90=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/mine/index.vue | 71 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 4 deletions(-) diff --git a/pages/mine/index.vue b/pages/mine/index.vue index 7b3c7c2..1af8c53 100644 --- a/pages/mine/index.vue +++ b/pages/mine/index.vue @@ -16,7 +16,7 @@ import { - getUserInfo,updateNickname + getUserInfo,updateNickname,uploadAvatar } from './api.js'; import { useUserStore @@ -127,9 +127,50 @@ //弹窗控制 const show = ref(false) - const showPopup = () =>{ + const newNickname = ref('') + const showPopup = () => { + newNickname.value = userName.value || '' show.value = true } + + // 关闭弹窗方法 + const hidePopup = () => { + show.value = false + } + + // 确认修改用户名 + const confirmUpdateNickname = async () => { + if (!newNickname.value.trim()) { + uni.showToast({ + title: 'Username cannot be empty', + icon: 'none' + }) + return + } + + try { + const res = await updateNickname({ nickname: newNickname.value }) + if (res.data) { + userName.value = newNickname.value + userStore.updateUserInfo('nickname', newNickname.value) + hidePopup() + uni.showToast({ + title: 'Update success', + icon: 'success' + }) + } else { + uni.showToast({ + title: 'Update failed', + icon: 'none' + }) + } + } catch (error) { + uni.showToast({ + title: 'Update failed', + icon: 'none' + }) + } + }