feat:国际化多语言适配

This commit is contained in:
2025-10-29 15:48:40 +08:00
parent 985d739324
commit 3d67dc928d
41 changed files with 2636 additions and 2801 deletions
+26 -20
View File
@@ -9,15 +9,15 @@
<button class="avatar-choose-btn" open-type="chooseAvatar" @chooseavatar="onChooseAvatar"></button>
<!-- #endif -->
</view>
<view class="avatar-tip">点击头像更换</view>
</view>
<view class="avatar-tip">{{ $t('userProfile.clickToChange') }}</view>
</view>
<view class="form-section">
<!-- 昵称编辑区域 -->
<view class="form-item nickname-item" :class="{ editing: isEditingNickname }">
<view class="label">昵称</view>
<view class="label">{{ $t('userProfile.nickname') }}</view>
<view class="value" v-if="!isEditingNickname" @click="startEditNickname">
<text class="value-text">{{ userInfo.nickName || '未设置' }}</text>
<text class="value-text">{{ userInfo.nickName || $t('userProfile.notSet') }}</text>
<uv-icon name="edit-pen" size="16" color="#999999"></uv-icon>
</view>
</view>
@@ -27,25 +27,25 @@
<input
class="nickname-input"
v-model="newNickname"
placeholder="请输入新昵称"
:placeholder="$t('userProfile.enterNickname')"
maxlength="20"
:focus="true"
/>
<view class="edit-buttons">
<button class="cancel-btn" @click="cancelEditNickname">取消</button>
<button class="save-btn" @click="saveNickname">保存</button>
<button class="cancel-btn" @click="cancelEditNickname">{{ $t('common.cancel') }}</button>
<button class="save-btn" @click="saveNickname">{{ $t('common.save') }}</button>
</view>
</view>
<view class="form-item">
<view class="label">手机号</view>
<view class="label">{{ $t('userProfile.phone') }}</view>
<view class="value">
<text class="value-text">{{ userInfo.phone ? maskPhone(userInfo.phone) : '未绑定' }}</text>
<text class="value-text">{{ userInfo.phone ? maskPhone(userInfo.phone) : $t('userProfile.notBound') }}</text>
</view>
</view>
<view class="form-item" v-if="userInfo.balanceAmount !== undefined">
<view class="label">余额</view>
<view class="label">{{ $t('userProfile.balance') }}</view>
<view class="value">
<text class="value-text amount">¥{{ userInfo.balanceAmount || '0.00' }}</text>
</view>
@@ -57,6 +57,9 @@
<script setup>
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 userInfo = ref({
@@ -71,6 +74,9 @@ const isEditingNickname = ref(false);
// 页面加载时初始化
onMounted(() => {
uni.setNavigationBarTitle({
title: $t('userProfile.title')
})
loadUserInfo();
});
@@ -96,7 +102,7 @@ const loadUserInfo = async () => {
} catch (error) {
console.error('获取用户信息失败:', error);
uni.showToast({
title: '获取用户信息失败',
title: $t('user.getUserInfoFailed'),
icon: 'none'
});
}
@@ -132,13 +138,13 @@ const onChooseAvatar = async (e) => {
const avatarLocalPath = e?.detail?.avatarUrl;
if (!avatarLocalPath) {
uni.showToast({
title: '未选择头像',
title: $t('user.noAvatar'),
icon: 'none'
});
return;
}
uni.showLoading({
title: '上传中...',
title: $t('userProfile.uploading'),
mask: true
});
const uploadRes = await uploadUserAvatar(avatarLocalPath);
@@ -151,14 +157,14 @@ const onChooseAvatar = async (e) => {
uni.setStorageSync('userInfo', userInfo.value);
}
uni.showToast({
title: '头像更新成功',
title: $t('user.avatarUpdated'),
icon: 'success'
});
await loadUserInfo();
} catch (err) {
console.error('选择/上传头像失败:', err);
uni.showToast({
title: '头像更新失败',
title: $t('user.avatarUploadFailed'),
icon: 'none'
});
} finally {
@@ -182,7 +188,7 @@ const cancelEditNickname = () => {
const saveNickname = async () => {
if (!newNickname.value || !newNickname.value.trim()) {
uni.showToast({
title: '昵称不能为空',
title: $t('userProfile.nicknameRequired'),
icon: 'none'
});
return;
@@ -190,7 +196,7 @@ const saveNickname = async () => {
try {
uni.showLoading({
title: '保存中...',
title: $t('userProfile.saving'),
mask: true
});
@@ -222,19 +228,19 @@ const saveNickname = async () => {
uni.hideLoading();
uni.showToast({
title: '昵称修改成功',
title: $t('userProfile.nicknameUpdated'),
icon: 'success'
});
isEditingNickname.value = false;
} else {
throw new Error(res.message || '修改失败');
throw new Error(res.message || $t('userProfile.updateFailed'));
}
} catch (error) {
console.error('修改昵称失败:', error);
uni.hideLoading();
uni.showToast({
title: error.message || '修改失败',
title: error.message || $t('userProfile.updateFailed'),
icon: 'none'
});
}