Sfoglia il codice sorgente

feat: 个人资料多语言

liangan 1 settimana fa
parent
commit
afbab377e0
5 ha cambiato i file con 52 aggiunte e 24 eliminazioni
  1. 12 0
      src/locale/bn.json
  2. 12 0
      src/locale/en.json
  3. 12 0
      src/locale/zh-Hans.json
  4. 1 1
      src/pages.json
  5. 15 23
      src/pages/mine/myProfile.vue

+ 12 - 0
src/locale/bn.json

@@ -1,4 +1,16 @@
 {
+  "myProfile.title": "আমার প্রোফাইল",
+  "myProfile.avatar": "অবতার",
+  "myProfile.userId": "ইউজার আইডি",
+  "myProfile.userName": "ব্যবহারকারীর নাম",
+  "myProfile.mobileNumber": "মোবাইল নম্বর",
+  "myProfile.bankName": "ব্যাংকের নাম",
+  "myProfile.bankAccountName": "ব্যাংক অ্যাকাউন্ট নাম",
+  "myProfile.bankAccountNo": "ব্যাংক অ্যাকাউন্ট নং",
+  "myProfile.upload.sizeLimit": "ছবির আকার 5MB এর বেশি হতে পারবে না",
+  "myProfile.upload.uploading": "আপলোড হচ্ছে...",
+  "myProfile.upload.success": "অবতার সফলভাবে আপডেট করা হয়েছে",
+  "myProfile.upload.error": "অবতার আপডেট করতে ব্যর্থ হয়েছে",
   "setting.title": "সেটিং",
   "setting.changePassword": "পাসওয়ার্ড পরিবর্তন",
   "setting.language": "ভাষা",

+ 12 - 0
src/locale/en.json

@@ -1,4 +1,16 @@
 {
+  "myProfile.title": "My Profile",
+  "myProfile.avatar": "Avatar",
+  "myProfile.userId": "User ID",
+  "myProfile.userName": "User Name",
+  "myProfile.mobileNumber": "Mobile Number",
+  "myProfile.bankName": "Bank Name",
+  "myProfile.bankAccountName": "Bank Account Name",
+  "myProfile.bankAccountNo": "Bank Account No.",
+  "myProfile.upload.sizeLimit": "Image size cannot exceed 5MB",
+  "myProfile.upload.uploading": "Uploading...",
+  "myProfile.upload.success": "Avatar updated successfully",
+  "myProfile.upload.error": "Failed to update avatar",
   "setting.title": "Setting",
   "setting.changePassword": "Change Password",
   "setting.language": "Language",

+ 12 - 0
src/locale/zh-Hans.json

@@ -1,4 +1,16 @@
 {
+  "myProfile.title": "个人资料",
+  "myProfile.avatar": "头像",
+  "myProfile.userId": "用户ID",
+  "myProfile.userName": "用户名",
+  "myProfile.mobileNumber": "手机号",
+  "myProfile.bankName": "银行名称",
+  "myProfile.bankAccountName": "开户名",
+  "myProfile.bankAccountNo": "银行账号",
+  "myProfile.upload.sizeLimit": "图片大小不能超过5MB",
+  "myProfile.upload.uploading": "上传中...",
+  "myProfile.upload.success": "头像更新成功",
+  "myProfile.upload.error": "更新头像失败",
   "setting.title": "设置",
   "setting.changePassword": "修改密码",
   "setting.language": "语言",

+ 1 - 1
src/pages.json

@@ -129,7 +129,7 @@
       "type": "page",
       "layout": "default",
       "style": {
-        "navigationBarTitleText": "My Profile",
+        "navigationBarTitleText": "%myProfile.title%",
         "navigationBarBackgroundColor": "#fff"
       }
     },

+ 15 - 23
src/pages/mine/myProfile.vue

@@ -2,18 +2,15 @@
 {
   layout: 'default',
   style: {
-    navigationBarTitleText: 'My Profile',
+    navigationBarTitleText: '%myProfile.title%',
     navigationBarBackgroundColor: '#fff',
   },
 }
 </route>
 
 <script lang="ts" setup>
-// 必须导入需要用到的页面生命周期(即使在当前页面上没有直接使用到)
-// eslint-disable-next-line unused-imports/no-unused-imports
-import { onPageScroll, onReachBottom } from '@dcloudio/uni-app'
-import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
 import { updateInfo } from '@/api/login'
+import { t } from '@/locale'
 import { useUserStore } from '@/store'
 import { getEnvBaseUploadUrl } from '@/utils'
 import { toast } from '@/utils/toast'
@@ -27,11 +24,6 @@ const userInfo = computed(() => {
   return getUserInfoHook()
 })
 
-// z-paging
-const paging = ref(null)
-// 类似mixins,如果是页面滚动务必要写这一行,并传入当前ref绑定的paging,注意此处是paging,而非paging.value
-useZPaging(paging)
-
 const uploading = ref(false)
 
 // 更新头像
@@ -58,13 +50,13 @@ async function updateAvatar() {
     // 检查文件大小(限制为5MB)
     const maxSize = 5 * 1024 * 1024
     if (tempFile.size > maxSize) {
-      toast.error('Image size cannot exceed 5MB')
+      toast.error(t('myProfile.upload.sizeLimit'))
       return
     }
 
     uploading.value = true
     await uni.showLoading({
-      title: 'Uploading...',
+      title: t('myProfile.upload.uploading'),
       mask: true,
     })
 
@@ -82,7 +74,7 @@ async function updateAvatar() {
     // 解析上传结果
     const uploadData = JSON.parse(uploadRes.data)
     if (uploadData.code !== 200) {
-      throw new Error(uploadData.message || 'Upload failed')
+      throw new Error(uploadData.message)
     }
 
     const avatarUrl = uploadData.data.url
@@ -95,12 +87,12 @@ async function updateAvatar() {
     userStore.setUserInfo(newUserInfo)
 
     uni.hideLoading()
-    toast.success('Avatar updated successfully')
+    toast.success(t('myProfile.upload.success'))
   }
   catch (error: any) {
     uni.hideLoading()
     console.error('Update avatar failed:', error)
-    toast.error(error.message || 'Failed to update avatar')
+    toast.error(error.message || t('myProfile.upload.error'))
   }
   finally {
     uploading.value = false
@@ -109,10 +101,10 @@ async function updateAvatar() {
 </script>
 
 <template>
-  <z-paging ref="paging" refresher-only use-page-scroll>
+  <z-paging>
     <view class="py-20rpx">
       <wd-cell-group custom-class="mb-20rpx" border>
-        <wd-cell title="Avatar" center>
+        <wd-cell :title="t('myProfile.avatar')" center>
           <view class="flex items-center justify-end" @click="updateAvatar">
             <view class="relative flex items-center justify-center">
               <wd-img width="64rpx" height="64rpx" round :src="userInfo.headPic" />
@@ -123,14 +115,14 @@ async function updateAvatar() {
             <wd-icon name="arrow-right" custom-class="ml-10rpx" size="36rpx" />
           </view>
         </wd-cell>
-        <wd-cell title="User ID" :value="userInfo.userId" />
-        <wd-cell title="User Name" :value="userInfo.name" />
-        <wd-cell title="Mobile Number" :value="userInfo.phoneNo" />
+        <wd-cell :title="t('myProfile.userId')" :value="userInfo.userId" />
+        <wd-cell :title="t('myProfile.userName')" :value="userInfo.name" />
+        <wd-cell :title="t('myProfile.mobileNumber')" :value="userInfo.phoneNo" />
       </wd-cell-group>
       <wd-cell-group custom-class="mb-20rpx" border>
-        <wd-cell title="Bank Name" :value="userInfo.bank" />
-        <wd-cell title="Bank Account Name" :value="userInfo.bankAccountName" />
-        <wd-cell title="Bank Account No." :value="userInfo.bankAccount" />
+        <wd-cell :title="t('myProfile.bankName')" :value="userInfo.bank" />
+        <wd-cell :title="t('myProfile.bankAccountName')" :value="userInfo.bankAccountName" />
+        <wd-cell :title="t('myProfile.bankAccountNo')" :value="userInfo.bankAccount" />
       </wd-cell-group>
     </view>
   </z-paging>