refactor: 将Data到ViewModel的转换由App转移至Server端
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m15s

- 将逻辑转移到Server端后,简化前端逻辑
This commit is contained in:
2025-11-13 20:45:43 +08:00
parent e215a4d498
commit 23f2700c0f
70 changed files with 904 additions and 614 deletions

View File

@ -4,7 +4,7 @@
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
<div class="content">
<markdown-renderer :content="content.content || ''" />
<markdown-renderer :content="companyProfile.content || ''" />
</div>
<el-divider content-position="left">{{ $t('learn-more') }}</el-divider>
@ -32,9 +32,7 @@
{ label: $t('navigation.home'), to: localePath('/') },
{ label: $t('navigation.about-us') },
];
const { data, pending, error } = await useCompanyProfile();
const content = computed(() => toCompanyProfileView(data.value));
const { data: companyProfile, pending, error } = await useCompanyProfile();
watch(error, (value) => {
if (value) {

View File

@ -1,24 +1,14 @@
<template>
<div class="homepage">
<homepage-carousel :homepage-data="homepageData" :pending="pending" />
<homepage-product-section
:homepage-data="homepageData"
:pending="pending"
/>
<homepage-solution-section
:homepage-data="homepageData"
:pending="pending"
/>
<homepage-carousel :homepage-data="data" :pending="pending" />
<homepage-product-section :homepage-data="data" :pending="pending" />
<homepage-solution-section :homepage-data="data" :pending="pending" />
</div>
</template>
<script setup lang="ts">
const { data, pending, error } = await useHomepage();
const homepageData = computed(() => {
return toHomepageView(data.value);
});
const pageTilte = $t('page-title.homepage');
watch(error, (value) => {

View File

@ -37,16 +37,7 @@
// 获取路由参数
const id = route.params.slug as string;
const { data, pending, error } = await useProduct(id);
const rawProduct = computed(() => data.value ?? null);
const product = computed(() => {
if (rawProduct.value === null) {
return null;
}
return toProductView(rawProduct.value);
});
const { data: product, pending, error } = await useProduct(id);
const breadcrumbItems = computed(() => [
{ label: $t('navigation.home'), to: localePath('/') },

View File

@ -37,7 +37,7 @@
const localePath = useLocalePath();
const { getImageUrl } = useDirectusImage();
const { data, pending, error } = await useProductList();
const { data: products, pending, error } = await useProductList();
const activeNames = ref<string[]>([]);
@ -46,14 +46,6 @@
{ label: $t('navigation.products') },
];
const productsRaw = computed(() => data.value ?? []);
const products = computed(() =>
productsRaw.value.map((item) => toProductListView(item))
);
logger.debug('产品列表数据: ', products.value);
// 按类型分组
const groupedProducts = computed(() => {
const groups: Record<string, { data: ProductListView[]; sort: number }> =

View File

@ -29,14 +29,7 @@
// 获取路由参数
const id = route.params.slug as string;
const { data, pending, error } = await useSolution(id);
const solution = computed(() => {
if (!data.value) {
return null;
}
return toSolutionView(data.value);
});
const { data: solution, pending, error } = await useSolution(id);
const breadcrumbItems = computed(() => [
{ label: $t('navigation.home'), to: localePath('/') },

View File

@ -52,12 +52,7 @@
{ label: $t('navigation.solutions') },
];
const { data, pending, error } = await useSolutionList();
const solutionsRaw = computed(() => data.value ?? []);
const solutions = computed(() =>
solutionsRaw.value.map((item) => toSolutionListView(item))
);
const { data: solutions, pending, error } = await useSolutionList();
const activeName = ref<string>('all');

View File

@ -7,7 +7,7 @@
</div>
<div v-if="!pending" class="page-content">
<markdown-renderer :content="content.content || ''" />
<markdown-renderer :content="contactInfo.content || ''" />
</div>
<div v-else class="loading">
<el-skeleton :rows="5" animated />
@ -22,9 +22,7 @@
{ label: $t('navigation.support'), to: localePath('/support') },
{ label: $t('navigation.contact-info') },
];
const { data, pending, error } = await useContactInfo();
const content = computed(() => toContactInfoView(data.value));
const { data: contactInfo, pending, error } = await useContactInfo();
watch(error, (value) => {
if (value) {

View File

@ -35,11 +35,7 @@
keyword: '',
});
const { data, pending, error } = await useDocumentList();
const documents = computed(
() => data?.value.map((item) => toDocumentListView(item)) ?? []
);
const { data: documents, pending, error } = await useDocumentList();
const productTypeOptions = computed(() => {
const types: DocumentListProductType[] = [];

View File

@ -38,11 +38,7 @@
{ label: $t('navigation.faq') },
];
const { data, pending, error } = await useQuestionList();
const questions = computed(
() => data.value.map((item) => toQuestionListView(item)) ?? null
);
const { data: questions, pending, error } = await useQuestionList();
const productTypeOptions = computed(() => {
const types: QuestionListProductType[] = [];