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 @@