fix:修复bug
This commit is contained in:
+12
-12
@@ -59,7 +59,7 @@ import { ref, reactive, onMounted } from 'vue';
|
||||
import { getMyIndexInfo, uploadUserAvatar, updateUserInfo } from '../../config/api/user.js';
|
||||
import { useI18n } from '@/utils/i18n.js'
|
||||
|
||||
const { t: $t } = useI18n()
|
||||
const { t } = useI18n()
|
||||
|
||||
// 响应式状态
|
||||
const userInfo = ref({
|
||||
@@ -75,7 +75,7 @@ const isEditingNickname = ref(false);
|
||||
// 页面加载时初始化
|
||||
onMounted(() => {
|
||||
uni.setNavigationBarTitle({
|
||||
title: $t('userProfile.title')
|
||||
title: t('userProfile.title')
|
||||
})
|
||||
loadUserInfo();
|
||||
});
|
||||
@@ -102,7 +102,7 @@ const loadUserInfo = async () => {
|
||||
} catch (error) {
|
||||
console.error('获取用户信息失败:', error);
|
||||
uni.showToast({
|
||||
title: $t('user.getUserInfoFailed'),
|
||||
title: t('user.getUserInfoFailed'),
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
@@ -138,13 +138,13 @@ const onChooseAvatar = async (e) => {
|
||||
const avatarLocalPath = e?.detail?.avatarUrl;
|
||||
if (!avatarLocalPath) {
|
||||
uni.showToast({
|
||||
title: $t('user.noAvatar'),
|
||||
title: t('user.noAvatar'),
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showLoading({
|
||||
title: $t('userProfile.uploading'),
|
||||
title: t('userProfile.uploading'),
|
||||
mask: true
|
||||
});
|
||||
const uploadRes = await uploadUserAvatar(avatarLocalPath);
|
||||
@@ -157,14 +157,14 @@ const onChooseAvatar = async (e) => {
|
||||
uni.setStorageSync('userInfo', userInfo.value);
|
||||
}
|
||||
uni.showToast({
|
||||
title: $t('user.avatarUpdated'),
|
||||
title: t('user.avatarUpdated'),
|
||||
icon: 'success'
|
||||
});
|
||||
await loadUserInfo();
|
||||
} catch (err) {
|
||||
console.error('选择/上传头像失败:', err);
|
||||
uni.showToast({
|
||||
title: $t('user.avatarUploadFailed'),
|
||||
title: t('user.avatarUploadFailed'),
|
||||
icon: 'none'
|
||||
});
|
||||
} finally {
|
||||
@@ -188,7 +188,7 @@ const cancelEditNickname = () => {
|
||||
const saveNickname = async () => {
|
||||
if (!newNickname.value || !newNickname.value.trim()) {
|
||||
uni.showToast({
|
||||
title: $t('userProfile.nicknameRequired'),
|
||||
title: t('userProfile.nicknameRequired'),
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
@@ -196,7 +196,7 @@ const saveNickname = async () => {
|
||||
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: $t('userProfile.saving'),
|
||||
title: t('userProfile.saving'),
|
||||
mask: true
|
||||
});
|
||||
|
||||
@@ -228,19 +228,19 @@ const saveNickname = async () => {
|
||||
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: $t('userProfile.nicknameUpdated'),
|
||||
title: t('userProfile.nicknameUpdated'),
|
||||
icon: 'success'
|
||||
});
|
||||
isEditingNickname.value = false;
|
||||
} else {
|
||||
throw new Error(res.message || $t('userProfile.updateFailed'));
|
||||
throw new Error(res.message || t('userProfile.updateFailed'));
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('修改昵称失败:', error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: error.message || $t('userProfile.updateFailed'),
|
||||
title: error.message || t('userProfile.updateFailed'),
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user