Files
jinshen-website/app/pages/products/[...slug].vue
R2m1liA 00c4c80e49 refactor: 重构产品页
- 将产品详情页的相关部分提取为ProductHeader与ProductDetail两个组件
2025-10-29 17:19:49 +08:00

99 lines
2.3 KiB
Vue

<template>
<div class="page-container">
<div v-if="!pending">
<div v-if="product">
<!-- 面包屑导航 -->
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
<!-- 产品详情内容 -->
<product-header :product="product" />
<!-- 产品详细描述 -->
<product-detail :product="product" />
</div>
<!-- 未找到产品 -->
<div v-else class="not-found">
<not-found-result
:title="$t('product-not-found')"
:sub-title="$t('product-not-found-desc')"
:back-text="$t('back-to-products')"
:on-back="() => $router.push($localePath('/products'))"
/>
</div>
</div>
<div v-else class="loading">
<el-skeleton style="--el-skeleton-circle-size: 400px">
<template #template>
<el-skeleton-item variant="circle" />
</template>
</el-skeleton>
<el-skeleton :rows="5" animated />
</div>
</div>
</template>
<script setup lang="ts">
const route = useRoute();
const localePath = useLocalePath();
// 获取路由参数
const id = computed(() => route.params.slug as string);
const { data, pending, error } = await useProduct(id.value);
const rawProduct = computed(() => data.value ?? null);
const product = computed(() => {
if (rawProduct.value === null) {
return null;
}
return toProductView(rawProduct.value);
});
const breadcrumbItems = computed(() => [
{ label: $t('navigation.home'), to: localePath('/') },
{ label: $t('navigation.products'), to: localePath('/products') },
{ label: product.value?.name || '' },
]);
watch(error, (value) => {
if (value) {
console.error('数据获取失败: ', value);
}
});
// SEO
useHead({
title: computed(() => product.value?.name || 'Product Detail'),
meta: [
{
name: 'description',
content: computed(() => product.value?.summary || ''),
},
],
});
</script>
<style scoped>
.page-container {
min-height: 80vh;
max-width: 1200px;
margin: 0 auto;
}
.breadcrumb {
padding: 2rem;
}
.loading {
display: flex;
justify-content: center;
align-items: center;
margin-top: 1rem;
}
.not-found {
display: flex;
justify-content: center;
align-items: center;
min-height: 400px;
}
</style>