import type { SectionBlock, SectionConfig } from '~/types/site'; /** * 区块内容多语言解析 * * Section 的各文本字段均有 _zh / _en 两个版本, * 该 composable 根据当前语言返回对应的值,避免各布局组件重复判断。 */ export function useSectionContent(section: SectionBlock) { const { locale } = useI18n(); const isEn = computed(() => locale.value === 'en'); const overline = computed(() => (isEn.value ? section.overline_en : section.overline_zh) || ''); const title = computed(() => (isEn.value ? section.title_en : section.title_zh) || ''); const subtitle = computed(() => (isEn.value ? section.subtitle_en : section.subtitle_zh) || ''); const content = computed(() => (isEn.value ? section.content_en : section.content_zh) || ''); const ctaPrimaryText = computed(() => (isEn.value ? section.cta_primary_en : section.cta_primary_zh) || ''); const ctaSecondaryText = computed(() => (isEn.value ? section.cta_secondary_en : section.cta_secondary_zh) || ''); const mediaUrl = computed(() => (isEn.value ? section.media_url_en : section.media_url_zh) || section.media_url_zh || ''); const config = computed(() => section.config ?? {}); /** 深色主题区块 */ const isDark = computed(() => section.theme === 'dark'); return { isEn, overline, title, subtitle, content, ctaPrimaryText, ctaSecondaryText, mediaUrl, config, isDark }; }