Fix: 修正产品规格参数显示问题
This commit is contained in:
@ -13,7 +13,9 @@
|
||||
<!-- 产品详情内容 -->
|
||||
<div class="production-header">
|
||||
<div class="production-image">
|
||||
<el-image :src="useStrapiMedia(production?.production_image?.url || '')" :alt="production.title" fit="contain" />
|
||||
<el-image
|
||||
:src="useStrapiMedia(production?.production_image?.url || '')" :alt="production.title"
|
||||
fit="contain" />
|
||||
</div>
|
||||
<div class="production-info">
|
||||
<h1>{{ production.title }}</h1>
|
||||
@ -28,7 +30,7 @@
|
||||
<markdown-renderer :content="production.production_details || ''" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="技术规格" name="specs">
|
||||
<spec-table :data="parsedSpecs" />
|
||||
<spec-table :data="production.production_specs" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="相关文档" name="documents" />
|
||||
</el-tabs>
|
||||
@ -59,10 +61,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { Production } from '~/types/strapi/production'
|
||||
|
||||
const route = useRoute()
|
||||
const { findOne } = useStrapi()
|
||||
const { getStrapiLocale } = useLocalizations()
|
||||
|
||||
const strapiLocale = getStrapiLocale()
|
||||
|
||||
const production = ref<Production | null>(null)
|
||||
@ -73,42 +76,28 @@ const activeName = ref('details') // 默认选中概览标签
|
||||
// 获取路由参数(slug 或 id)
|
||||
const documentId = 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<Production>('productions', documentId.value, {
|
||||
populate: '*',
|
||||
populate: {
|
||||
production_specs: {
|
||||
populate: '*',
|
||||
},
|
||||
production_image: {
|
||||
populate: '*',
|
||||
},
|
||||
},
|
||||
locale: strapiLocale,
|
||||
})
|
||||
if (response.data) {
|
||||
const item = response.data
|
||||
production.value = {
|
||||
title: item.title,
|
||||
summary: item.summary,
|
||||
production_type: item.production_type,
|
||||
production_details: item.production_details,
|
||||
production_specs: item.production_specs,
|
||||
production_image: item.production_image,
|
||||
documentId: item.documentId,
|
||||
documents: item.documents || [] }
|
||||
...item,
|
||||
}
|
||||
console.log('Production details:', production.value)
|
||||
}
|
||||
console.log('Parsed production:', production.value?.production_specs)
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch production:', error)
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user