feat(SSR): 将解决方案页改为SSR
- 使用Nuxt的useAsyncData - 添加i18n信息
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<div v-if="!pending">
|
||||
<div v-if="solution">
|
||||
<div class="page-header">
|
||||
<el-breadcrumb class="breadcrumb" separator="/">
|
||||
@ -23,7 +24,8 @@
|
||||
<h1>{{ solution.title }}</h1>
|
||||
<div class="solution-meta">
|
||||
<span class="solution-date">
|
||||
CreatedAt: {{ new Date(solution.createdAt).toLocaleDateString() }}
|
||||
CreatedAt:
|
||||
{{ new Date(solution.createdAt).toLocaleDateString() }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@ -33,6 +35,20 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="not-found">
|
||||
<el-result
|
||||
icon="warning"
|
||||
:title="$t('solution-not-found')"
|
||||
:sub-title="$t('solution-not-found-desc')"
|
||||
>
|
||||
<template #extra>
|
||||
<el-button type="primary" @click="$router.push('/productions')">
|
||||
{{ $t('back-to-solutions') }}
|
||||
</el-button>
|
||||
</template>
|
||||
</el-result>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="loading">
|
||||
<el-skeleton :rows="5" animated />
|
||||
</div>
|
||||
@ -45,27 +61,23 @@
|
||||
const { getStrapiLocale } = useLocalizations();
|
||||
const strapiLocale = getStrapiLocale();
|
||||
|
||||
const solution = ref<Solution | null>(null);
|
||||
|
||||
// 获取路由参数(documentId)
|
||||
const documentId = computed(() => route.params.slug as string);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await findOne<Solution>('solutions', documentId.value, {
|
||||
const { data, pending, error } = useAsyncData(
|
||||
() => `solution-${documentId.value}`,
|
||||
() =>
|
||||
findOne<Solution>('solutions', documentId.value, {
|
||||
populate: '*',
|
||||
locale: strapiLocale,
|
||||
});
|
||||
if (response.data) {
|
||||
solution.value = {
|
||||
...response.data,
|
||||
// 确保 solution_type 保持原始类型
|
||||
solution_type: response.data.solution_type,
|
||||
};
|
||||
}
|
||||
console.log('Fetched Solution:', solution.value);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch solution:', error);
|
||||
})
|
||||
);
|
||||
|
||||
const solution = computed(() => data.value?.data ?? null);
|
||||
|
||||
watch(error, (value) => {
|
||||
if (value) {
|
||||
console.error('数据获取失败: ', value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@ -127,4 +139,11 @@
|
||||
align-items: center;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.not-found {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 400px;
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
</el-breadcrumb-item>
|
||||
</el-breadcrumb>
|
||||
</div>
|
||||
<div class="solutions-container">
|
||||
<div v-if="!pending" class="solutions-container">
|
||||
<el-tabs v-model="activeName" class="solutions-tabs">
|
||||
<el-tab-pane :label="$t('all')" name="all">
|
||||
<div class="solution-list">
|
||||
@ -48,18 +48,34 @@
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-skeleton :rows="6" animated />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { find } = useStrapi();
|
||||
const { getStrapiLocale } = useLocalizations();
|
||||
|
||||
const strapiLocale = getStrapiLocale();
|
||||
|
||||
const { data, pending, error } = useAsyncData('solutions', () =>
|
||||
find<Solution>('solutions', {
|
||||
populate: {
|
||||
cover: {
|
||||
populate: '*',
|
||||
},
|
||||
solution_type: {
|
||||
populate: '*',
|
||||
},
|
||||
},
|
||||
locale: strapiLocale,
|
||||
})
|
||||
);
|
||||
|
||||
const activeName = ref<string>('all');
|
||||
|
||||
const solutions = ref<Solution[]>([]);
|
||||
const solutions = computed(() => data.value?.data ?? []);
|
||||
|
||||
// 按类型分组
|
||||
const groupedSolutions = computed(() => {
|
||||
@ -81,27 +97,9 @@
|
||||
return gourps;
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const response = await find<Solution>('solutions', {
|
||||
populate: {
|
||||
cover: {
|
||||
populate: '*',
|
||||
},
|
||||
solution_type: {
|
||||
populate: '*',
|
||||
},
|
||||
},
|
||||
locale: strapiLocale,
|
||||
});
|
||||
solutions.value = response.data.map((item: Solution) => ({
|
||||
...item,
|
||||
solution_type: item.solution_type,
|
||||
}));
|
||||
console.log('Fetched Solutions:', solutions.value);
|
||||
console.log('Grouped Solutions:', groupedSolutions.value);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch solutions:', error);
|
||||
watch(error, (value) => {
|
||||
if (value) {
|
||||
console.error('数据获取失败: ', value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@ -51,6 +51,9 @@
|
||||
"product-not-found": "Product Not Found",
|
||||
"product-not-found-desc": "Sorry, the product you are looking for does not exist or has been removed.",
|
||||
"back-to-productions": "Back to Products",
|
||||
"solution-not-found": "Solution Not Found",
|
||||
"solution-not-found-desc": "Sorry, the solution you are lokking for does not exist or has been removed.",
|
||||
"back-to-solutions": "Back to Solutions",
|
||||
"no-content-available": "No detailed information available",
|
||||
"loading": "Loading...",
|
||||
"our-productions": "Our Productions",
|
||||
|
||||
@ -51,6 +51,9 @@
|
||||
"product-not-found": "产品未找到",
|
||||
"product-not-found-desc": "抱歉,您访问的产品不存在或已被删除。",
|
||||
"back-to-productions": "返回产品列表",
|
||||
"solution-not-found": "解决方案未找到",
|
||||
"solution-not-found-desc": "抱歉,您访问的解决方案不存在或已被删除",
|
||||
"back-to-solutions": "返回解决方案列表",
|
||||
"no-content-available": "暂无详细信息",
|
||||
"loading": "加载中...",
|
||||
"our-productions": "我们的产品",
|
||||
|
||||
Reference in New Issue
Block a user