From bcb04aedd744fa51732896f7389256012e9b08f4 Mon Sep 17 00:00:00 2001 From: zhangyahui Date: Wed, 3 Jun 2026 13:14:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.ts | 4 +- src/lang/en.ts | 79 ++++++++++++++++------------ src/lang/zh-cn.ts | 25 +++++---- src/views/main-header.vue | 11 ++-- src/views/setting/index.vue | 6 +-- src/views/setting/types.ts | 2 +- src/views/setting/useSettingsForm.ts | 59 +++++++-------------- 7 files changed, 90 insertions(+), 96 deletions(-) diff --git a/src/api/user.ts b/src/api/user.ts index 60123ca..8445caa 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -146,7 +146,9 @@ export const getUserLanguage = (): Promise => { } // 设置语言 -export const setUserLanguage = (language: string): Promise => { +export const setUserLanguage = ( + language: 'ENGLISH' | 'CHINESE_SIMPLIFIED' +): Promise => { return request({ url: '/buyer/profile/setLanguage', method: 'post', diff --git a/src/lang/en.ts b/src/lang/en.ts index 343c6cf..8fb2e49 100644 --- a/src/lang/en.ts +++ b/src/lang/en.ts @@ -83,7 +83,7 @@ export default { avatarCrop: { title: 'Crop Avatar', confirm: 'Confirm', - processing: 'Processing...', + processing: 'Processing...' }, security: { title: 'Security', @@ -159,8 +159,8 @@ export default { other: 'Other' }, languages: { - english: 'English', - chinese: 'Chinese' + ENGLISH: 'English', + CHINESE_SIMPLIFIED: 'Chinese Simplified' }, regions: { hongKongSar: 'Hong Kong SAR', @@ -338,34 +338,41 @@ export default { AddToCart: 'Add to Cart' }, Home: { - IndexTitle: 'We’re Seeking
Fashion Voice
Worth Featuring.', - IndexTip: 'Discover collections through the stories behind their creation. A curated space connecting designers, narratives, and fashion commerce.', + IndexTitle: + 'We’re Seeking
Fashion Voice
Worth Featuring.', + IndexTip: + 'Discover collections through the stories behind their creation. A curated space connecting designers, narratives, and fashion commerce.', DesignerTitle: 'Designer Community', - DesignerTip: 'Discover the designers shaping AiDA’s creative landscape.
Each month, we will showcase a curated selection of their most distinguished works.', + DesignerTip: + 'Discover the designers shaping AiDA’s creative landscape.
Each month, we will showcase a curated selection of their most distinguished works.', SearchBrands: 'Search Brands', AidaTitle: 'Design with AiDA', - AidaTip: 'Each garment on this platform is where designer vision blooms through AiDA. A tool that nurtures your creativity, never overshadows it. Let your ideas flourish.', + AidaTip: + 'Each garment on this platform is where designer vision blooms through AiDA. A tool that nurtures your creativity, never overshadows it. Let your ideas flourish.', TryNow: 'Try Now', DigitalItems: 'Digital Items', - DigitalItemsTip1: 'AiDA captures your boldest thoughts and transforms them into vivid
digital visions—a virtual realm where creativity collides and evolves.', - DigitalItemsTip2: 'AiDA accelerates style innovation, shaping daily pieces that keep
your wardrobe in sync with modern fashion’s rhythm.', - FooterTip: "Stylish Parade is a commerce platform for designers, serving as AiDA's commercial extension.", - FooterAidaTip: "Bloom your Creativity with AiDA!", - Help: "Help", - FAQ: "FAQ", - MyAccount: "My Account", - MyOrders: "My Orders", - PaymentInvoices: "Payment and Invoices", - CopyrightLicense: "Copyright Licence", - Polices: "Policies", - Legal: "Legal", - PrivacyPolicy: "Privacy Policy", - CookiesSettings: "Cookies Settings", - PurchaseConditions: "Purchase Conditions", - Company: "Company", - AboutUs: "About Us", - Offices: "Offices", - JoinWithUs: "Join with Us", + DigitalItemsTip1: + 'AiDA captures your boldest thoughts and transforms them into vivid
digital visions—a virtual realm where creativity collides and evolves.', + DigitalItemsTip2: + 'AiDA accelerates style innovation, shaping daily pieces that keep
your wardrobe in sync with modern fashion’s rhythm.', + FooterTip: + "Stylish Parade is a commerce platform for designers, serving as AiDA's commercial extension.", + FooterAidaTip: 'Bloom your Creativity with AiDA!', + Help: 'Help', + FAQ: 'FAQ', + MyAccount: 'My Account', + MyOrders: 'My Orders', + PaymentInvoices: 'Payment and Invoices', + CopyrightLicense: 'Copyright Licence', + Polices: 'Policies', + Legal: 'Legal', + PrivacyPolicy: 'Privacy Policy', + CookiesSettings: 'Cookies Settings', + PurchaseConditions: 'Purchase Conditions', + Company: 'Company', + AboutUs: 'About Us', + Offices: 'Offices', + JoinWithUs: 'Join with Us' }, addShoppingCart: { title: 'Added to your Shopping Cart', @@ -394,18 +401,22 @@ export default { OrderSummary: 'Order Summary', PaymentDetails: 'Payment Details', CreditDebitCard: 'Credit / Debit Card', - AgreementText: 'I agree to the Terms & Conditions and Privacy Policy. All digital item sales are final and non-refundable.', + AgreementText: + 'I agree to the Terms & Conditions and Privacy Policy. All digital item sales are final and non-refundable.', PayWithStripe: 'Pay with Stripe', PayWith: 'Pay with', Cancel: 'Cancel', IHaveCompletedPayment: 'I Have Completed payment', Back: 'Back', - PayTip1: "You'll be redirected to a Stripe popup to log in and confirm. No card details are shared with Stylish Parade — Stripe handles all payment security.", - PayTip2: "Please keep the window open until the payment is completed. If you are to open the payment window, please check your browser settings to see if pop-ups are being blocked. Points may be delayed after successful payment. Please wait 1-3 minutes and click the credits refresh button.", - PurchaseSuccessful: "Purchase Successful", - PurchaseSuccessfulTip: "Your digital items are now available and have been saved in Personal Center → My Wardrobe.", - DownloadAllAssets: "download all Assets", - ExportInvoice: "Export Invoice", - ContinueShopping: "Continue Shopping" + PayTip1: + "You'll be redirected to a Stripe popup to log in and confirm. No card details are shared with Stylish Parade — Stripe handles all payment security.", + PayTip2: + 'Please keep the window open until the payment is completed. If you are to open the payment window, please check your browser settings to see if pop-ups are being blocked. Points may be delayed after successful payment. Please wait 1-3 minutes and click the credits refresh button.', + PurchaseSuccessful: 'Purchase Successful', + PurchaseSuccessfulTip: + 'Your digital items are now available and have been saved in Personal Center → My Wardrobe.', + DownloadAllAssets: 'download all Assets', + ExportInvoice: 'Export Invoice', + ContinueShopping: 'Continue Shopping' } } diff --git a/src/lang/zh-cn.ts b/src/lang/zh-cn.ts index 976a4b5..94eeb40 100644 --- a/src/lang/zh-cn.ts +++ b/src/lang/zh-cn.ts @@ -78,7 +78,7 @@ export default { avatarCrop: { title: '裁剪头像', confirm: '确认', - processing: '处理中...', + processing: '处理中...' }, security: { title: '安全', @@ -154,8 +154,8 @@ export default { other: '其他' }, languages: { - english: '英文', - chinese: '中文' + ENGLISH: '英文', + CHINESE_SIMPLIFIED: '简体中文' }, regions: { hongKongSar: '中国香港特别行政区', @@ -393,18 +393,21 @@ export default { OrderSummary: '订单信息', PaymentDetails: '支付详情', CreditDebitCard: '信用卡/借记卡', - AgreementText: '我同意 使用条款与条件隐私政策。所有数字资产销售均为最终销售,不可退款。', + AgreementText: + '我同意 使用条款与条件隐私政策。所有数字资产销售均为最终销售,不可退款。', PayWithStripe: '使用 Stripe 支付', PayWith: '支付', Cancel: '取消', IHaveCompletedPayment: '我已完成支付', Back: '返回', - PayTip1: "您将被重定向到 Stripe 弹窗以登录并确认支付。您的信用卡信息不会被 Stylish Parade 收集。Stripe 处理所有支付安全。", - PayTip2: "请保持窗口打开,直到支付完成。如果您打开支付窗口,请检查浏览器设置以查看是否已阻止弹窗。支付完成后,积分可能会有延迟。请等待 1-3 分钟并点击积分刷新按钮。", - PurchaseSuccessful: "购买成功", - PurchaseSuccessfulTip: "您的数字资产已保存在个人中心的我的衣橱中。", - DownloadAllAssets: "下载所有资产", - ExportInvoice: "导出发票", - ContinueShopping: "继续购物" + PayTip1: + '您将被重定向到 Stripe 弹窗以登录并确认支付。您的信用卡信息不会被 Stylish Parade 收集。Stripe 处理所有支付安全。', + PayTip2: + '请保持窗口打开,直到支付完成。如果您打开支付窗口,请检查浏览器设置以查看是否已阻止弹窗。支付完成后,积分可能会有延迟。请等待 1-3 分钟并点击积分刷新按钮。', + PurchaseSuccessful: '购买成功', + PurchaseSuccessfulTip: '您的数字资产已保存在个人中心的我的衣橱中。', + DownloadAllAssets: '下载所有资产', + ExportInvoice: '导出发票', + ContinueShopping: '继续购物' } } diff --git a/src/views/main-header.vue b/src/views/main-header.vue index c9e4996..7062f06 100644 --- a/src/views/main-header.vue +++ b/src/views/main-header.vue @@ -175,12 +175,11 @@ const onLanguageClick = () => { locale.value = locale.value === 'ENGLISH' ? 'CHINESE_SIMPLIFIED' : 'ENGLISH' localStorage.setItem('language', locale.value) - console.log(locale.value) - const localeMap: Record = { - ENGLISH: 'en', - CHINESE_SIMPLIFIED: 'zh-CN' - } - setUserLanguage(localeMap[locale.value]) + + setUserLanguage(locale.value).then((res) => { + userInfoStore.setToken(res) + location.reload() + }) } diff --git a/src/views/setting/index.vue b/src/views/setting/index.vue index 7780f5f..38ad3e0 100644 --- a/src/views/setting/index.vue +++ b/src/views/setting/index.vue @@ -119,9 +119,9 @@ loadUserProfile } = useSettingsForm({ t, locale }) - watch(locale, () => { - loadUserProfile() - }) + // watch(locale, () => { + // loadUserProfile() + // }) onMounted(() => { loadUserProfile() diff --git a/src/views/setting/types.ts b/src/views/setting/types.ts index b452b55..78130d7 100644 --- a/src/views/setting/types.ts +++ b/src/views/setting/types.ts @@ -12,7 +12,7 @@ export const roleValues = [ 'other' ] as const -export const languageValues = ['english', 'chinese'] as const +export const languageValues = ['ENGLISH', 'CHINESE_SIMPLIFIED'] as const export type RoleValue = (typeof roleValues)[number] diff --git a/src/views/setting/useSettingsForm.ts b/src/views/setting/useSettingsForm.ts index 6d6f732..08894a5 100644 --- a/src/views/setting/useSettingsForm.ts +++ b/src/views/setting/useSettingsForm.ts @@ -6,7 +6,8 @@ import { type UserProfile, updateUserProfile, verifyEmailCode, - fetchVerifyCode + fetchVerifyCode, + setUserLanguage } from '@/api/user' import regionList from '@/utils/area' import { @@ -18,6 +19,9 @@ import { type SettingsData } from './types' import { validateCase, validateLength, validateSpecial } from '@/views/login/tools' +import {useUserInfoStore} from '@/stores' + +const userInfoStore = useUserInfoStore() type Translate = (key: string, ...args: unknown[]) => string @@ -26,24 +30,6 @@ interface UseSettingsFormOptions { locale: Ref } -// 前端 UI 使用的语言值(用于下拉选择) -const languageLocaleMap: Record = { - english: 'ENGLISH', - chinese: 'CHINESE_SIMPLIFIED' -} - -// 后端 API 使用的语言值 -const backendLanguageMap: Record<'ENGLISH' | 'CHINESE_SIMPLIFIED', 'en' | 'zh-CN'> = { - ENGLISH: 'en', - CHINESE_SIMPLIFIED: 'zh-CN' -} - -// 后端语言值转换为前端语言值 -const backendToFrontendLanguage: Record<'en' | 'zh-CN', LanguageValue> = { - en: 'english', - 'zh-CN': 'chinese' -} - const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ const isRoleValue = (value: string): value is RoleValue => @@ -75,15 +61,10 @@ const normalizeLanguage = (language: string | null | undefined): LanguageValue = if (!language) { return '' as LanguageValue } - - // 后端返回 'en' 或 'zh-CN' const trimmed = language.trim() - if (trimmed === 'en') { - return 'english' - } else if (trimmed === 'zh-CN') { - return 'chinese' + if (trimmed === 'ENGLISH' || trimmed === 'CHINESE_SIMPLIFIED') { + return trimmed as LanguageValue } - return '' as LanguageValue } @@ -182,9 +163,8 @@ export function useSettingsForm({ t, locale }: UseSettingsFormOptions) { } const syncAppLanguage = (language: LanguageValue) => { - const nextLocale = languageLocaleMap[language] - locale.value = nextLocale - localStorage.setItem('language', nextLocale) + locale.value = language + localStorage.setItem('language', language) } const loadUserProfile = async () => { @@ -334,12 +314,8 @@ export function useSettingsForm({ t, locale }: UseSettingsFormOptions) { return } - // 将前端语言值转换为后端格式 - let backendLanguage = '' - if (draftData.value.language) { - const i18nLocale = languageLocaleMap[draftData.value.language as LanguageValue] - backendLanguage = backendLanguageMap[i18nLocale] - } + // 前端语言值直接作为后端格式 + const backendLanguage = draftData.value.language || '' const nextData: UserProfile = { firstName: draftData.value.firstName.trim(), @@ -370,10 +346,8 @@ export function useSettingsForm({ t, locale }: UseSettingsFormOptions) { try { await updateUserProfile(nextData) - // 将后端返回的语言值转换为前端格式 - const frontendLanguage = backendLanguage - ? backendToFrontendLanguage[backendLanguage as 'en' | 'zh-CN'] - : '' + // 后端返回的语言值直接作为前端格式 + const frontendLanguage = backendLanguage as LanguageValue const settingsData: SettingsData = { firstName: nextData.firstName, @@ -388,7 +362,12 @@ export function useSettingsForm({ t, locale }: UseSettingsFormOptions) { console.log(nextData) if (frontendLanguage && frontendLanguage !== previousLanguage) { - syncAppLanguage(frontendLanguage as LanguageValue) + // syncAppLanguage(frontendLanguage as LanguageValue) + setUserLanguage(frontendLanguage).then((res) => { + // console.log(res) + userInfoStore.setToken(res) + location.reload() + }) } draftData.value = cloneSettingsData(sourceData.value)