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