فهرست منبع

feat: 多语言切换,动态数据适配h5更新

liangan 2 هفته پیش
والد
کامیت
f365a28a57

+ 25 - 15
src/pages/mine/mine.vue

@@ -17,6 +17,7 @@ import { getConfigByCode } from '@/api/common'
 import { pendingRedDots } from '@/api/order'
 import { getWalletAccountInfo } from '@/api/wallet'
 import { t } from '@/locale'
+import i18n from '@/locale/index'
 import { useUserStore } from '@/store/user'
 import { formatNumber } from '@/utils'
 import { toPage } from '@/utils/page'
@@ -43,21 +44,30 @@ const isLoggedIn = computed(() => !!userStore.token)
 // 获取用户信息
 const userInfo = computed(() => userStore.userInfo)
 
-const groupList = ref([
-  { name: t('mine.group.toPay'), url: `/pages/myOrders/myOrders`, dotName: 'toPayNum', type: 1, icon: '/static/icons/to-pay.png' },
-  { name: t('mine.group.success'), url: `/pages/myOrders/myOrders`, type: 2, dotName: 'successNum', icon: '/static/icons/success.png' },
-  { name: t('mine.group.failed'), url: `/pages/myOrders/myOrders`, type: 3, dotName: 'failedNum', icon: '/static/icons/failed.png' },
-  { name: t('mine.group.reward'), url: `/pages/myOrders/myOrders`, type: 4, dotName: 'rewardNum', icon: '/static/icons/reward.png' },
-])
+const groupList = computed(() => {
+  // 依赖 locale,确保切换语言后这里会重新计算
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { name: t('mine.group.toPay'), url: `/pages/myOrders/myOrders`, dotName: 'toPayNum', type: 1, icon: '/static/icons/to-pay.png' },
+    { name: t('mine.group.success'), url: `/pages/myOrders/myOrders`, type: 2, dotName: 'successNum', icon: '/static/icons/success.png' },
+    { name: t('mine.group.failed'), url: `/pages/myOrders/myOrders`, type: 3, dotName: 'failedNum', icon: '/static/icons/failed.png' },
+    { name: t('mine.group.reward'), url: `/pages/myOrders/myOrders`, type: 4, dotName: 'rewardNum', icon: '/static/icons/reward.png' },
+  ]
+})
 
-const menuList = ref([
-  { name: t('mine.menu.profile'), url: '/pages/mine/myProfile', icon: '/static/icons/my-profile.png' },
-  { name: t('mine.menu.address'), url: '/pages/mine/addressBook', icon: '/static/icons/address-book.png' },
-  { name: t('mine.menu.share'), url: '/pages/mine/share', icon: '/static/icons/share.png' },
-  { name: t('mine.menu.favorite'), url: '/pages/mine/myFavorite', icon: '/static/icons/my-favorite.png' },
-  { name: t('mine.menu.chat'), config: 'live_chat', icon: '/static/icons/live-chat.png' },
-  { name: t('mine.menu.activity'), config: 'activity_group', icon: '/static/icons/activity-group.png' },
-])
+const menuList = computed(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { name: t('mine.menu.profile'), url: '/pages/mine/myProfile', icon: '/static/icons/my-profile.png' },
+    { name: t('mine.menu.address'), url: '/pages/mine/addressBook', icon: '/static/icons/address-book.png' },
+    { name: t('mine.menu.share'), url: '/pages/mine/share', icon: '/static/icons/share.png' },
+    { name: t('mine.menu.favorite'), url: '/pages/mine/myFavorite', icon: '/static/icons/my-favorite.png' },
+    { name: t('mine.menu.chat'), config: 'live_chat', icon: '/static/icons/live-chat.png' },
+    { name: t('mine.menu.activity'), config: 'activity_group', icon: '/static/icons/activity-group.png' },
+  ]
+})
 
 function getPlusRuntime() {
   const p = (globalThis as any)?.plus
@@ -197,7 +207,7 @@ onShow(() => {
 </script>
 
 <template>
-  <z-paging ref="paging" refresher-only use-page-scroll @refresh="handleRefresh">
+  <z-paging ref="paging" use-page-scroll refresher-only @refresh="handleRefresh">
     <view
       class="flex items-center justify-between bg-[rgba(var(--wot-color-theme-rgb),0.3)] pb-72rpx pl-24rpx pr-54rpx"
       :style="{ paddingTop: `${safeAreaInsets?.top + 24}px` }"

+ 8 - 1
src/pages/mine/setting.vue

@@ -18,7 +18,14 @@ defineOptions({
   name: 'Setting', // 设置
 })
 const userStore = useUserStore()
-const columns = ref([{ label: t('setting.lang.en'), value: 'en' }, { label: t('setting.lang.bn'), value: 'bn' }])
+const columns = computed(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { label: t('setting.lang.en'), value: 'en' },
+    { label: t('setting.lang.bn'), value: 'bn' },
+  ]
+})
 const language = ref(uni.getLocale() === 'bn' ? 'bn' : 'en')
 function changeLanguage(data: any) {
   console.log(data)

+ 25 - 20
src/pages/missionCenter/missionCenter.vue

@@ -12,6 +12,7 @@
 <script lang="ts" setup>
 import { clockIn, todayDetail } from '@/api/mine'
 import { t } from '@/locale'
+import i18n from '@/locale/index'
 import { toPage } from '@/utils/page'
 import { toast } from '@/utils/toast'
 
@@ -19,26 +20,30 @@ defineOptions({
   name: 'MissionCenter', // 任务中心
 })
 
-const dailyMission = ref<any>([
-  {
-    name: t('missionCenter.dailyMission.inviteFriends.name'),
-    description: t('missionCenter.dailyMission.inviteFriends.description'),
-    icon: '/static/icons/invite-friends.png',
-    url: '/pages/referEarn/referEarn',
-  },
-  {
-    name: t('missionCenter.dailyMission.openGroupBuy.name'),
-    description: t('missionCenter.dailyMission.openGroupBuy.description'),
-    icon: '/static/icons/open-group-buy.png',
-    url: '/pages/bestSellers/bestSellers',
-  },
-  {
-    name: t('missionCenter.dailyMission.joinGroupBuy.name'),
-    description: t('missionCenter.dailyMission.joinGroupBuy.description'),
-    icon: '/static/icons/join-group-buy.png',
-    url: '/pages/bestSellers/bestSellers',
-  },
-])
+const dailyMission = computed(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    {
+      name: t('missionCenter.dailyMission.inviteFriends.name'),
+      description: t('missionCenter.dailyMission.inviteFriends.description'),
+      icon: '/static/icons/invite-friends.png',
+      url: '/pages/referEarn/referEarn',
+    },
+    {
+      name: t('missionCenter.dailyMission.openGroupBuy.name'),
+      description: t('missionCenter.dailyMission.openGroupBuy.description'),
+      icon: '/static/icons/open-group-buy.png',
+      url: '/pages/bestSellers/bestSellers',
+    },
+    {
+      name: t('missionCenter.dailyMission.joinGroupBuy.name'),
+      description: t('missionCenter.dailyMission.joinGroupBuy.description'),
+      icon: '/static/icons/join-group-buy.png',
+      url: '/pages/bestSellers/bestSellers',
+    },
+  ]
+})
 // 今日是否已签到
 const hasSignedToday = ref(true)
 

+ 12 - 7
src/pages/notifications/notifications.vue

@@ -16,6 +16,7 @@ import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
 
 import { noticeDel, noticeList, noticeRead, readAllNotice } from '@/api/common'
 import { t } from '@/locale'
+import i18n from '@/locale/index'
 import { goBack, toPage } from '@/utils/page'
 import { toast } from '@/utils/toast'
 
@@ -33,13 +34,17 @@ const paging = ref(null)
 useZPaging(paging)
 
 const tab = ref<string>('ALL')
-const tabs = [
-  { title: t('notifications.tabs.all'), value: 'ALL' },
-  { title: t('notifications.tabs.orders'), value: 'ORDER' },
-  { title: t('notifications.tabs.revenue'), value: 'REWARD' },
-  { title: t('notifications.tabs.account'), value: 'MONEY' },
-  { title: t('notifications.tabs.promos'), value: 'OTHER' },
-]
+const tabs = computed(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { title: t('notifications.tabs.all'), value: 'ALL' },
+    { title: t('notifications.tabs.orders'), value: 'ORDER' },
+    { title: t('notifications.tabs.revenue'), value: 'REWARD' },
+    { title: t('notifications.tabs.account'), value: 'MONEY' },
+    { title: t('notifications.tabs.promos'), value: 'OTHER' },
+  ]
+})
 
 const typeMap = {
   order: ['ORDER_GROUP_BUY_PAYMENT_SUCCESS', 'ORDER_GROUP_BUY_SUCCESS_WIN', 'ORDER_GROUP_BUY_SUCCESS_LOSE', 'ORDER_PROVIDE_SHIPPING_ADDRESS', 'ORDER_GROUP_BUY_FAIL', 'ORDER_SHIPPED_SUCCESS'],

+ 56 - 41
src/pages/search/search.vue

@@ -15,6 +15,7 @@ import { useQueue } from 'wot-design-uni'
 import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
 import { categoryList, getList } from '@/api/product'
 import { t } from '@/locale'
+import i18n from '@/locale/index'
 import { goBack, toPage } from '@/utils/page'
 
 defineOptions({
@@ -38,52 +39,66 @@ const formData = ref<any>({
 
 const { closeOutside } = useQueue()
 
-const option1 = ref<Record<string, any>[]>([
-  { label: t('home.priceTab.allPrice'), value: 0 },
-  {
-    label: t('home.priceTab.300spot'),
-    value: 300,
-    minPrice: 0,
-    maxPrice: 300,
-  },
-  {
-    label: t('home.priceTab.500spot'),
-    value: 500,
-    minPrice: 300,
-    maxPrice: 500,
-  },
-  {
-    label: t('home.priceTab.1000spot'),
-    value: 1000,
-    minPrice: 500,
-    maxPrice: 1000,
-  },
-  {
-    label: t('home.priceTab.2000spot'),
-    value: 2000,
-    minPrice: 1000,
-    maxPrice: 2000,
-  },
-  {
-    label: t('home.priceTab.3000spot'),
-    value: 3000,
-    minPrice: 2000,
-    maxPrice: 3000,
-  },
-])
+const option1 = computed<Record<string, any>[]>(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { label: t('home.priceTab.allPrice'), value: 0 },
+    {
+      label: t('home.priceTab.300spot'),
+      value: 300,
+      minPrice: 0,
+      maxPrice: 300,
+    },
+    {
+      label: t('home.priceTab.500spot'),
+      value: 500,
+      minPrice: 300,
+      maxPrice: 500,
+    },
+    {
+      label: t('home.priceTab.1000spot'),
+      value: 1000,
+      minPrice: 500,
+      maxPrice: 1000,
+    },
+    {
+      label: t('home.priceTab.2000spot'),
+      value: 2000,
+      minPrice: 1000,
+      maxPrice: 2000,
+    },
+    {
+      label: t('home.priceTab.3000spot'),
+      value: 3000,
+      minPrice: 2000,
+      maxPrice: 3000,
+    },
+  ]
+})
 
-const option2 = ref<Record<string, any>[]>([
-  { label: t('search.filterCategory'), value: 0 },
-])
+const categoryOptions = ref<Record<string, any>[]>([])
+const option2 = computed<Record<string, any>[]>(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { label: t('search.filterCategory'), value: 0 },
+    ...categoryOptions.value,
+  ]
+})
 
-const option3 = ref<Record<string, any>[]>([
-  { label: t('search.filterSellers'), value: 'SALES_DESC' },
-  { label: t('search.filterSellers1'), value: 'CREATE_DESC' },
-])
+const option3 = computed<Record<string, any>[]>(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { label: t('search.filterSellers'), value: 'SALES_DESC' },
+    { label: t('search.filterSellers1'), value: 'CREATE_DESC' },
+  ]
+})
 async function getCategoryList() {
   const res = await categoryList({ page: 1, size: 20 })
   console.log(res)
-  option2.value = [...option2.value, ...res.data.list.map((i: any) => ({ label: i.name, value: i.id }))]
+  categoryOptions.value = res.data.list.map((i: any) => ({ label: i.name, value: i.id }))
 }
 
 // 搜索结果

+ 12 - 7
src/pages/vipMembership/vipMembership.vue

@@ -12,6 +12,7 @@
 <script lang="ts" setup>
 import { memberConfigs } from '@/api/mine'
 import { t } from '@/locale'
+import i18n from '@/locale/index'
 import { useUserStore } from '@/store'
 import { formatNumber } from '@/utils'
 
@@ -42,13 +43,17 @@ interface TableColumn {
 }
 
 // 表格列配置
-const tableColumns = ref<TableColumn[]>([
-  { prop: 'level', label: t('vipMembership.table.vipLevel'), fixed: true, align: 'center', width: '100rpx' },
-  { prop: 'invitedNo', label: t('vipMembership.table.invitedNo'), align: 'center', width: '120rpx' },
-  { prop: 'directReferralReward', slot: true, label: t('vipMembership.table.directReferralReward'), align: 'center', width: '210rpx' },
-  { prop: 'indirectReferralReward', slot: true, label: t('vipMembership.table.indirectReferralReward'), align: 'center', width: '220rpx' },
-  { prop: 'joinedGroupsNo', label: t('vipMembership.table.joinedGroupsNo'), align: 'center', width: '220rpx' },
-])
+const tableColumns = computed<TableColumn[]>(() => {
+  const _locale = i18n.global.locale
+  void _locale
+  return [
+    { prop: 'level', label: t('vipMembership.table.vipLevel'), fixed: true, align: 'center', width: '100rpx' },
+    { prop: 'invitedNo', label: t('vipMembership.table.invitedNo'), align: 'center', width: '120rpx' },
+    { prop: 'directReferralReward', slot: true, label: t('vipMembership.table.directReferralReward'), align: 'center', width: '210rpx' },
+    { prop: 'indirectReferralReward', slot: true, label: t('vipMembership.table.indirectReferralReward'), align: 'center', width: '220rpx' },
+    { prop: 'joinedGroupsNo', label: t('vipMembership.table.joinedGroupsNo'), align: 'center', width: '220rpx' },
+  ]
+})
 
 const dataList = ref<TableData[]>([])