From bc87ef721a8b3642710006ec485f9413fb7e7940 Mon Sep 17 00:00:00 2001 From: JiaJun <2394389886@qq.com> Date: Wed, 15 Apr 2026 10:32:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(lang):=20=E4=BC=98=E5=8C=96=E8=AF=AD?= =?UTF-8?q?=E8=A8=80=E5=A4=84=E7=90=86=E5=92=8C=E6=95=B0=E6=8D=AE=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 7 ++- src/features/addressBook/useAddressBook.ts | 7 ++- src/features/authGuide.tsx | 3 +- src/features/goods/GoodsCategoryList.tsx | 50 +++++++++++++++++++--- src/lib/request.ts | 3 +- src/views/record/index.tsx | 25 ++++------- 6 files changed, 69 insertions(+), 26 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 47c853d..3689df9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -30,7 +30,10 @@ function App() { if (previousLanguage && previousLanguage !== normalizedLanguage) { await queryClient.cancelQueries() - await queryClient.invalidateQueries({refetchType: 'active'}) + await queryClient.invalidateQueries({ + refetchType: 'active', + predicate: (query) => query.queryKey[0] !== 'auth-bootstrap', + }) } previousLanguageRef.current = normalizedLanguage @@ -120,7 +123,7 @@ function App() { } > - + }/> }/> }/> diff --git a/src/features/addressBook/useAddressBook.ts b/src/features/addressBook/useAddressBook.ts index 5d12935..2b3b03d 100644 --- a/src/features/addressBook/useAddressBook.ts +++ b/src/features/addressBook/useAddressBook.ts @@ -48,6 +48,7 @@ export function useAddressBook(options?: UseAddressBookOptions) { const queryClient = useQueryClient() const sessionId = useUserStore((state) => state.authInfo?.session_id ?? '') const [addressForm, setAddressForm] = useState(emptyAddressForm) + const [loadAddressesLoading, setLoadAddressesLoading] = useState(false) const addressListQuery = useQuery({ queryKey: queryKeys.addressList(sessionId), @@ -100,6 +101,8 @@ export function useAddressBook(options?: UseAddressBookOptions) { return [] } + setLoadAddressesLoading(true) + try { const result = await queryClient.fetchQuery({ queryKey: queryKeys.addressList(sessionId), @@ -112,6 +115,8 @@ export function useAddressBook(options?: UseAddressBookOptions) { return result } catch { return [] + } finally { + setLoadAddressesLoading(false) } }, [queryClient, sessionId]) @@ -177,7 +182,7 @@ export function useAddressBook(options?: UseAddressBookOptions) { sessionId, addresses, addressOptions, - loading: addressListQuery.isPending, + loading: addressListQuery.isPending || loadAddressesLoading, addressForm, isAddressFormValid, submitLoading: saveAddressMutation.isPending, diff --git a/src/features/authGuide.tsx b/src/features/authGuide.tsx index c7f7550..4da46c4 100644 --- a/src/features/authGuide.tsx +++ b/src/features/authGuide.tsx @@ -4,6 +4,7 @@ import {type PropsWithChildren, useEffect, useRef, useState} from 'react' import {login, validateToken} from '@/api/auth.ts' import {userAssets} from '@/api/user.ts' import {useTranslation} from 'react-i18next' +import {normalizeLanguage} from '@/lib/i18n' import {queryKeys} from '@/lib/queryKeys.ts' import {useUserStore} from '@/store/user.ts' import type {HostContextMessage} from '@/types' @@ -70,7 +71,7 @@ export function AuthGuide({children}: PropsWithChildren) { } if (typeof language === 'string' && language.trim()) { - setLanguage(language.trim()) + setLanguage(normalizeLanguage(language)) } } diff --git a/src/features/goods/GoodsCategoryList.tsx b/src/features/goods/GoodsCategoryList.tsx index e26adad..d8f634e 100644 --- a/src/features/goods/GoodsCategoryList.tsx +++ b/src/features/goods/GoodsCategoryList.tsx @@ -4,7 +4,7 @@ import {useTranslation} from 'react-i18next' import {ChevronRight} from 'lucide-react' import Button from '@/components/button' -import {HOME_CATEGORY_META_MAP} from '@/constant' +import {HOME_CATEGORY_META_MAP, HOME_GOOD_TYPE_ORDER} from '@/constant' import type {ProductCategory, ProductItem} from '@/types' type GoodsCategoryListProps = { @@ -56,12 +56,52 @@ export function GoodsCategoryList({ }: GoodsCategoryListProps) { const {t} = useTranslation() const resolvedEmptyText = emptyText ?? t('goods.noGoodsAvailableYet') + if (loading) { return ( -
-
- {t('goods.loading')} -
+
+ {HOME_GOOD_TYPE_ORDER.map((categoryId) => { + const CategoryIcon = HOME_CATEGORY_META_MAP[categoryId].icon + + return ( +
+
+
+
+
+
+ {t(HOME_CATEGORY_META_MAP[categoryId].nameKey)} +
+
+ {showMore ? ( +
+ {t('common.more')} +
+ ) : null} +
+
+ {Array.from({length: 4}).map((_, index) => ( +
+
+
+
+
+
+
+
+
+
+
+ ))} +
+
+ ) + })}
) } diff --git a/src/lib/request.ts b/src/lib/request.ts index 06e9683..130ad7f 100644 --- a/src/lib/request.ts +++ b/src/lib/request.ts @@ -2,6 +2,7 @@ import ky, {HTTPError, type AfterResponseHook, type Input, type KyInstance, type import {notifyError, resolveToastMessage} from '@/features/notifications' import i18n from '@/lib/i18n' +import {normalizeLanguage} from '@/lib/i18n' import {useUserStore} from '@/store/user.ts' import type {ValidateTokenData} from '@/types/auth.type.ts' import {objectToFormData} from './tool' @@ -67,7 +68,7 @@ export const setAccessTokenFormatter = (formatter?: TokenFormatter) => { accessTokenFormatter = formatter ?? ((token) => `Bearer ${token}`) } -const getRequestLanguage = () => useUserStore.getState().language?.trim() || 'zh' +const getRequestLanguage = () => normalizeLanguage(useUserStore.getState().language) const authRefreshClient = ky.create({ baseUrl: API_BASE_URL, diff --git a/src/views/record/index.tsx b/src/views/record/index.tsx index c4ed917..9696910 100644 --- a/src/views/record/index.tsx +++ b/src/views/record/index.tsx @@ -103,20 +103,6 @@ function getOrderStatus(status?: string | number) { } function getOrderCategory(item: OrderItem) { - if (item.type?.trim()) { - const normalizedType = item.type.trim().toUpperCase() - switch (normalizedType) { - case 'BONUS': - return i18n.t('record.categories.bonus') - case 'PHYSICAL': - return i18n.t('record.categories.physical') - case 'WITHDRAW': - return i18n.t('record.categories.withdraw') - default: - return toTitleCase(normalizedType) - } - } - if (item.type_title) { return item.type_title } @@ -126,15 +112,22 @@ function getOrderCategory(item: OrderItem) { } if (item.type) { - switch (item.type) { + const normalizedType = item.type.trim().toUpperCase() + switch (normalizedType) { case 'BONUS': return i18n.t('record.categories.bonus') case 'PHYSICAL': return i18n.t('record.categories.physical') case 'WITHDRAW': return i18n.t('record.categories.withdraw') + case '1': + return i18n.t('record.categories.withdraw') + case '2': + return i18n.t('record.categories.physical') + case '3': + return i18n.t('record.categories.bonus') default: - return toTitleCase(item.type) + return toTitleCase(normalizedType) } }