From eaf7d3be381aad4954463d80a1dd0f86e5c674a0 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Sat, 16 Aug 2025 15:40:08 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BF=AE=E6=AD=A3=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E6=98=BE=E7=A4=BA=E3=80=81=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/app.vue | 10 ++------ app/components/JinshenFooter.vue | 16 ++++++------ app/components/JinshenHeader.vue | 10 ++++---- app/components/ProductionCard.vue | 5 ++-- app/composables/useLocalizations.ts | 39 +++++++++++++++++++++++++++++ app/pages/productions/[...slug].vue | 36 ++++++++++++++++++++++---- app/pages/productions/index.vue | 13 +++------- nuxt.config.ts | 2 ++ 8 files changed, 94 insertions(+), 37 deletions(-) create mode 100644 app/composables/useLocalizations.ts diff --git a/app/app.vue b/app/app.vue index 8dc70d3..45bc0da 100644 --- a/app/app.vue +++ b/app/app.vue @@ -10,19 +10,13 @@ diff --git a/app/composables/useLocalizations.ts b/app/composables/useLocalizations.ts new file mode 100644 index 0000000..ce613f8 --- /dev/null +++ b/app/composables/useLocalizations.ts @@ -0,0 +1,39 @@ +import type { StrapiLocale } from '@nuxtjs/strapi'; +import type { Language as ElementLanguage } from 'element-plus/es/locale'; +import zhCn from 'element-plus/es/locale/lang/zh-cn'; +import en from 'element-plus/es/locale/lang/en'; + +// Strapi本地化映射 +export const strapiLocales: Record = { + 'zh': 'zh-Hans', + 'en': 'en' +} + +// Element Plus本地化映射 +export const elementPlusLocales: Record = { + 'zh': zhCn, + 'en': en +} + +export const useLocalizations = () => { + const { locale } = useI18n(); + + // 获取Strapi本地化代码 + const getStrapiLocale = (nuxtLocale?: string): StrapiLocale => { + const currentLocale = nuxtLocale || locale.value; + return strapiLocales[currentLocale] || 'zh-Hans'; + } + + // 获取Element Plus本地化 + const getElementPlusLocale = (nuxtLocale?: string) => { + const currentLocale = nuxtLocale || locale.value; + const elementPlusLocale = elementPlusLocales[currentLocale] || elementPlusLocales['zh']; + return elementPlusLocale; + } + + return { + locale: readonly(locale), + getStrapiLocale, + getElementPlusLocale, + } +} \ No newline at end of file diff --git a/app/pages/productions/[...slug].vue b/app/pages/productions/[...slug].vue index 3517f05..0cb88c1 100644 --- a/app/pages/productions/[...slug].vue +++ b/app/pages/productions/[...slug].vue @@ -28,7 +28,7 @@ - + @@ -37,7 +37,12 @@
- {{ $t('loading') }} + + + +
@@ -69,6 +74,9 @@ interface ProductionDetails { const route = useRoute() const { findOne } = useStrapi() +const { getStrapiLocale } = useLocalizations() + +const strapiLocale = getStrapiLocale() const production = ref(null) const pending = ref(true) @@ -78,11 +86,29 @@ const activeName = ref('details') // 默认选中概览标签 // 获取路由参数(slug 或 id) const productionParam = computed(() => route.params.slug as string) +const parsedSpecs = computed(() => { + if (!production.value?.production_specs) return JSON.parse('{}') + + const specs = production.value.production_specs + + if (typeof specs === 'string') { + try { + return JSON.parse(specs) + } catch (error) { + console.error('Failed to parse production_specs:', error) + return specs + } + } + + return specs +}) + onMounted(async () => { try { const response = await findOne('productions', productionParam.value, { populate: '*', + locale: strapiLocale, }) if (response.data) { @@ -95,8 +121,8 @@ onMounted(async () => { production_specs: item.production_specs || '', production_image: { url: item.production_image?.url - ? `http://192.168.86.5:1337${item.production_image.url}` - : '' + ? `http://192.168.86.5:1337${item.production_image.url}` + : '' }, documentId: item.documentId || '', } @@ -176,7 +202,7 @@ useHead({ display: flex; justify-content: center; align-items: center; - height: 300px; + margin-top: 1rem; } .not-found { diff --git a/app/pages/productions/index.vue b/app/pages/productions/index.vue index 5ffe81a..76745a3 100644 --- a/app/pages/productions/index.vue +++ b/app/pages/productions/index.vue @@ -15,10 +15,10 @@