Compare commits
15 Commits
f081a3b33a
...
feat/icp
| Author | SHA1 | Date | |
|---|---|---|---|
| ef20832761 | |||
| 03a692afb5 | |||
| 7b21def74f | |||
| 783d482e0a | |||
| 62ec215340 | |||
| e02f975217 | |||
| 5530776035 | |||
| 63cdff9c41 | |||
| f1398a5545 | |||
| 36d24a4740 | |||
| c9b5b1fad9 | |||
| 246a0b9d4f | |||
| c3ac7c0985 | |||
| 63c3e2e364 | |||
| 1245df497b |
@ -38,6 +38,10 @@
|
|||||||
<div class="product-info">
|
<div class="product-info">
|
||||||
<h1>{{ product.name }}</h1>
|
<h1>{{ product.name }}</h1>
|
||||||
<p class="summary">{{ product.summary }}</p>
|
<p class="summary">{{ product.summary }}</p>
|
||||||
|
<p v-if="product.status === 'discontinued'" class="discontinued-warning">
|
||||||
|
<el-icon><ElIconWarning /></el-icon>
|
||||||
|
{{ $t('product-discontinued-warning') }}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -105,6 +109,10 @@
|
|||||||
margin-bottom: 2rem;
|
margin-bottom: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.discontinued-warning {
|
||||||
|
color: var(--el-color-error);
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.product-header {
|
.product-header {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
|
|||||||
75
app/components/pages/search/SearchResultCard.vue
Normal file
75
app/components/pages/search/SearchResultCard.vue
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<template>
|
||||||
|
<el-card class="result-card">
|
||||||
|
<el-row>
|
||||||
|
<el-col :span="12">
|
||||||
|
<h3 class="result-title">{{ item.title }}</h3>
|
||||||
|
<p v-if="item.summary" class="result-summary">
|
||||||
|
{{ item.summary }}
|
||||||
|
</p>
|
||||||
|
<p v-if="item.sectionType" class="result-type">
|
||||||
|
<span>{{ $t('search.section') }}: </span>
|
||||||
|
<span class="result-type-name">{{ typeLabel }}</span>
|
||||||
|
<span v-if="item.type" class="result-type-name"
|
||||||
|
>({{ item.type }})</span
|
||||||
|
>
|
||||||
|
</p>
|
||||||
|
</el-col>
|
||||||
|
<el-col :span="12" class="image-col">
|
||||||
|
<el-image
|
||||||
|
v-if="item.thumbnail"
|
||||||
|
:src="item.thumbnail"
|
||||||
|
:alt="item.title"
|
||||||
|
style="width: 150px"
|
||||||
|
/>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</el-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
item: SearchItemView;
|
||||||
|
typeLabel: string;
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.result-card {
|
||||||
|
border-radius: 12px;
|
||||||
|
transition: box-shadow 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-card:hover {
|
||||||
|
box-shadow: 0 12px 24px rgba(0, 0, 0, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-title {
|
||||||
|
font-size: 1.2rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-summary {
|
||||||
|
font-size: 0.95rem;
|
||||||
|
color: var(--el-text-color-regular);
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-type {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.result-type-name {
|
||||||
|
margin-left: 4px;
|
||||||
|
color: var(--el-color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-col {
|
||||||
|
display: flex;
|
||||||
|
justify-content: end;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@ -3,19 +3,13 @@
|
|||||||
<div class="search-results">
|
<div class="search-results">
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
v-for="hit in paginatedHits"
|
v-for="hit in paginatedHits"
|
||||||
:key="`${hit.type}-${hit.id}`"
|
:key="`${hit.sectionType}-${hit.id}`"
|
||||||
:to="localePath(resolveHitLink(hit))"
|
:to="localePath(resolveHitLink(hit))"
|
||||||
>
|
>
|
||||||
<el-card class="result-card">
|
<search-result-card
|
||||||
<h3 class="result-title">{{ hit.title }}</h3>
|
:item="hit"
|
||||||
<p v-if="hit.summary" class="result-summary">
|
:type-label="getIndexLabel(hit.sectionType)"
|
||||||
{{ hit.summary }}
|
/>
|
||||||
</p>
|
|
||||||
<p v-if="hit.type" class="result-type">
|
|
||||||
<span>{{ $t('search.section') }}: </span>
|
|
||||||
<span class="result-type-name">{{ getIndexLabel(hit.type) }}</span>
|
|
||||||
</p>
|
|
||||||
</el-card>
|
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -72,7 +66,7 @@
|
|||||||
const items = props.searchItems;
|
const items = props.searchItems;
|
||||||
const filteredHits = computed(() => {
|
const filteredHits = computed(() => {
|
||||||
if (props.category) {
|
if (props.category) {
|
||||||
return items.filter((item) => item.type === props.category);
|
return items.filter((item) => item.sectionType === props.category);
|
||||||
} else {
|
} else {
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
@ -116,19 +110,19 @@
|
|||||||
|
|
||||||
const slug = String(slugCandidate);
|
const slug = String(slugCandidate);
|
||||||
|
|
||||||
if (item.type === 'product') {
|
if (item.sectionType === 'product') {
|
||||||
return localePath({ path: `/products/${slug}` });
|
return localePath({ path: `/products/${slug}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.type === 'solution') {
|
if (item.sectionType === 'solution') {
|
||||||
return localePath({ path: `/solutions/${slug}` });
|
return localePath({ path: `/solutions/${slug}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.type === 'document') {
|
if (item.sectionType === 'document') {
|
||||||
return localePath({ path: `/download/${slug}` });
|
return localePath({ path: `/download/${slug}` });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.type === 'question') {
|
if (item.sectionType === 'question') {
|
||||||
return localePath({ path: `/support/faq`, query: { focus: slug } });
|
return localePath({ path: `/support/faq`, query: { focus: slug } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
const resultCount = computed(() => {
|
const resultCount = computed(() => {
|
||||||
const map: Record<string, number> = { all: props.searchItems.length };
|
const map: Record<string, number> = { all: props.searchItems.length };
|
||||||
for (const item of props.searchItems) {
|
for (const item of props.searchItems) {
|
||||||
map[item.type] = (map[item.type] ?? 0) + 1;
|
map[item.sectionType] = (map[item.sectionType] ?? 0) + 1;
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
});
|
});
|
||||||
|
|||||||
@ -7,7 +7,17 @@
|
|||||||
@click="handleClick(doc.fileId)"
|
@click="handleClick(doc.fileId)"
|
||||||
>
|
>
|
||||||
<div class="document-info">
|
<div class="document-info">
|
||||||
<h3>{{ doc.title }}</h3>
|
<div class="document-title">
|
||||||
|
<h3>
|
||||||
|
{{ doc.title }}
|
||||||
|
<span v-if="showCategory && doc.type" class="document-category">
|
||||||
|
|
|
||||||
|
</span>
|
||||||
|
<span v-if="showCategory && doc.type" class="document-category">
|
||||||
|
{{ doc.type.name }}
|
||||||
|
</span>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
<div class="document-content">
|
<div class="document-content">
|
||||||
<span v-if="doc.size" class="document-meta"
|
<span v-if="doc.size" class="document-meta"
|
||||||
>{{ $t('document-meta.size') }}: {{ formatFileSize(doc.size) }}
|
>{{ $t('document-meta.size') }}: {{ formatFileSize(doc.size) }}
|
||||||
@ -28,6 +38,10 @@
|
|||||||
type: Array as () => Array<ProductDocumentView>,
|
type: Array as () => Array<ProductDocumentView>,
|
||||||
default: () => [],
|
default: () => [],
|
||||||
},
|
},
|
||||||
|
showCategory: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const localePath = useLocalePath();
|
const localePath = useLocalePath();
|
||||||
@ -63,6 +77,15 @@
|
|||||||
color: var(--el-text-color-secondary);
|
color: var(--el-text-color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.document-title {
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.document-category {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
.download-button {
|
.download-button {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -84,7 +84,12 @@
|
|||||||
© {{ currentYear }} {{ $t('company-name') }}.
|
© {{ currentYear }} {{ $t('company-name') }}.
|
||||||
{{ $t('all-rights-reserved') }}
|
{{ $t('all-rights-reserved') }}
|
||||||
</p>
|
</p>
|
||||||
<p>备案号: 浙ICP备12003709号-5</p>
|
<p>
|
||||||
|
备案号:
|
||||||
|
<a href="https://beian.miit.gov.cn/" target="_blank"
|
||||||
|
>浙ICP备12003709号-5</a
|
||||||
|
>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div class="footer-links-bottom"> -->
|
<!-- <div class="footer-links-bottom"> -->
|
||||||
<!-- <NuxtLink :to="$localePath('/privacy')">{{ -->
|
<!-- <NuxtLink :to="$localePath('/privacy')">{{ -->
|
||||||
|
|||||||
@ -131,7 +131,9 @@
|
|||||||
mode="vertical"
|
mode="vertical"
|
||||||
@select="mobileMenuVisible = false"
|
@select="mobileMenuVisible = false"
|
||||||
>
|
>
|
||||||
<el-menu-item @click="openExternalLink('http://cal.jinshen.cn')">
|
<el-menu-item
|
||||||
|
@click="openExternalLink('http://cal.3w.jinshen.cn')"
|
||||||
|
>
|
||||||
{{ $t('navigation.calculator') }}
|
{{ $t('navigation.calculator') }}
|
||||||
</el-menu-item>
|
</el-menu-item>
|
||||||
</el-menu>
|
</el-menu>
|
||||||
|
|||||||
@ -53,8 +53,8 @@
|
|||||||
|
|
||||||
// SEO
|
// SEO
|
||||||
usePageSeo({
|
usePageSeo({
|
||||||
title: product.value.name || $t('page-title.products'),
|
title: product.value?.name || $t('page-title.products'),
|
||||||
description: product.value.summary || '',
|
description: product.value?.summary || '',
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1 class="page-title">{{ $t('our-products') }}</h1>
|
<div>
|
||||||
|
<h1 class="page-title">{{ $t('our-products') }}</h1>
|
||||||
|
<p class="page-subtitle">
|
||||||
|
{{ $t('products-desc') }}{{ $t('find-discontinued-products') }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
|
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!pending" class="page-content">
|
<div v-if="!pending" class="page-content">
|
||||||
@ -102,13 +108,18 @@
|
|||||||
|
|
||||||
.page-header {
|
.page-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-title {
|
.page-title {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
color: var(--el-color-primary);
|
color: var(--el-color-primary);
|
||||||
margin-bottom: 1rem;
|
}
|
||||||
|
|
||||||
|
.page-subtitle {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.breadcrumb {
|
.breadcrumb {
|
||||||
|
|||||||
@ -44,8 +44,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
usePageSeo({
|
usePageSeo({
|
||||||
title: solution.value.title || $t('page-title.solutions'),
|
title: solution.value?.title || $t('page-title.solutions'),
|
||||||
description: solution.value.summary || '',
|
description: solution.value?.summary || '',
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="page-container">
|
<div class="page-container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1 class="page-title">{{ $t('learn-our-solutions') }}</h1>
|
<div>
|
||||||
|
<h1 class="page-title">{{ $t('learn-our-solutions') }}</h1>
|
||||||
|
<p class="page-subtitle">{{ $t('solutions-desc') }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
|
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="!pending" class="solutions-container">
|
<div v-if="!pending" class="solutions-container">
|
||||||
@ -94,15 +98,20 @@
|
|||||||
|
|
||||||
.page-header {
|
.page-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
margin-bottom: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.page-title {
|
.page-title {
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 1rem;
|
|
||||||
color: var(--el-color-primary);
|
color: var(--el-color-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.page-subtitle {
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: var(--el-text-color-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
.breadcrumb {
|
.breadcrumb {
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,13 @@
|
|||||||
:document-type-options="documentTypeOptions"
|
:document-type-options="documentTypeOptions"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<document-list :documents="paginatedDocuments" />
|
<document-list
|
||||||
|
:documents="paginatedDocuments"
|
||||||
|
:show-category="
|
||||||
|
filters.selectedDocumentType === null ||
|
||||||
|
filters.selectedDocumentType === undefined
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
|
||||||
<el-pagination
|
<el-pagination
|
||||||
v-model:current-page="page"
|
v-model:current-page="page"
|
||||||
|
|||||||
@ -23,8 +23,8 @@
|
|||||||
"company-name": "Jinshen Machinary Manufacturing Co., Ltd.",
|
"company-name": "Jinshen Machinary Manufacturing Co., Ltd.",
|
||||||
"company-description": "We specialize in manufacturing a range of paper tube and can equipment, integrating design, manufacturing, sales, and service.",
|
"company-description": "We specialize in manufacturing a range of paper tube and can equipment, integrating design, manufacturing, sales, and service.",
|
||||||
"learn-more": "Learn More",
|
"learn-more": "Learn More",
|
||||||
"products-desc": "We provide high-quality product solutions to meet various business needs.",
|
"products-desc": "We provide the latest products an instant service support to meet various business needs of our customers.",
|
||||||
"solutions-desc": "Providing customized technology solutions for enterprises to accelerate digital transformation.",
|
"solutions-desc": "We offer diversified technical solutions for enterprises, supporting various fields such as industry and packaging.",
|
||||||
"support-desc": "24/7 professional technical support to ensure stable operation of your business.",
|
"support-desc": "24/7 professional technical support to ensure stable operation of your business.",
|
||||||
"quick-links": "Quick Links",
|
"quick-links": "Quick Links",
|
||||||
"utilities": "Utilities",
|
"utilities": "Utilities",
|
||||||
@ -63,7 +63,9 @@
|
|||||||
"back-to-home": "Back to Home",
|
"back-to-home": "Back to Home",
|
||||||
"no-content-available": "No detailed information available",
|
"no-content-available": "No detailed information available",
|
||||||
"loading": "Loading...",
|
"loading": "Loading...",
|
||||||
"our-products": "Our Products",
|
"our-products": "Our Latest Products",
|
||||||
|
"find-discontinued-products": "To find discontinued products, please use the search function.",
|
||||||
|
"product-discontinued-warning": "Product is discontinued and may no longer receive immediate support or updates",
|
||||||
"learn-our-solutions": "Learn Our Solutions",
|
"learn-our-solutions": "Learn Our Solutions",
|
||||||
"all": "All",
|
"all": "All",
|
||||||
"support-page-desc": "Zhejiang Jinshen Machinery Manufacturing Co., Ltd is committed to providing high-quality products and services to our customers. For products such as paper tube machines, slitting machines, and paper straw equipment, we offer comprehensive after-sales support to ensure our customers can use our products with confidence.",
|
"support-page-desc": "Zhejiang Jinshen Machinery Manufacturing Co., Ltd is committed to providing high-quality products and services to our customers. For products such as paper tube machines, slitting machines, and paper straw equipment, we offer comprehensive after-sales support to ensure our customers can use our products with confidence.",
|
||||||
|
|||||||
@ -23,8 +23,8 @@
|
|||||||
"company-name": "Jinshen Machinary Manufacturing Co., Ltd.",
|
"company-name": "Jinshen Machinary Manufacturing Co., Ltd.",
|
||||||
"company-description": "Especializado en la producción de una serie de equipos de tubos y latas de papel, integrando diseño, fabricación, ventas y servicio.",
|
"company-description": "Especializado en la producción de una serie de equipos de tubos y latas de papel, integrando diseño, fabricación, ventas y servicio.",
|
||||||
"learn-more": "Saber más",
|
"learn-more": "Saber más",
|
||||||
"products-desc": "Ofrecemos soluciones de productos de alta calidad que satisfacen diversas necesidades empresariales.",
|
"products-desc": "Ofrecemos los últimos productos y un servicio de asistencia instantáneo para satisfacer las diversas necesidades comerciales de nuestros clientes.",
|
||||||
"solutions-desc": "Providing customized technology solutions for enterprises to accelerate digital transformation.",
|
"solutions-desc": "Ofrecemos soluciones técnicas diversificadas para empresas, prestando apoyo en diversos campos, como la industria y el embalaje.",
|
||||||
"support-desc": "Soporte técnico profesional 24/7, asegurando la estabilidad de su negocio.",
|
"support-desc": "Soporte técnico profesional 24/7, asegurando la estabilidad de su negocio.",
|
||||||
"quick-links": "Enlaces rápidos",
|
"quick-links": "Enlaces rápidos",
|
||||||
"utilities": "Herramientas útiles",
|
"utilities": "Herramientas útiles",
|
||||||
@ -63,7 +63,9 @@
|
|||||||
"back-to-home": "Volver al inicio",
|
"back-to-home": "Volver al inicio",
|
||||||
"no-content-available": "No hay información disponible",
|
"no-content-available": "No hay información disponible",
|
||||||
"loading": "Cargando...",
|
"loading": "Cargando...",
|
||||||
"our-products": "Nuestros productos",
|
"our-products": "Nuestros últimos productos",
|
||||||
|
"find-discontinued-products": "Para encontrar productos descatalogados, utilice la función de búsqueda.",
|
||||||
|
"product-discontinued-warning": "Este producto ha sido descontinuado y puede que ya no reciba soporte o actualizaciones inmediatas.",
|
||||||
"learn-our-solutions": "Aprenda sobre nuestras soluciones",
|
"learn-our-solutions": "Aprenda sobre nuestras soluciones",
|
||||||
"all": "Todo",
|
"all": "Todo",
|
||||||
"support-page-desc": "Zhejiang Jinshen Machinery Manufacturing Co., Ltd se dedica a proporcionar productos y servicios de alta calidad a los clientes. Para máquinas de tubos de papel, máquinas de corte y pajitas de papel, ofrecemos un servicio postventa integral para garantizar que los clientes puedan usar nuestros productos con confianza.",
|
"support-page-desc": "Zhejiang Jinshen Machinery Manufacturing Co., Ltd se dedica a proporcionar productos y servicios de alta calidad a los clientes. Para máquinas de tubos de papel, máquinas de corte y pajitas de papel, ofrecemos un servicio postventa integral para garantizar que los clientes puedan usar nuestros productos con confianza.",
|
||||||
|
|||||||
@ -23,8 +23,8 @@
|
|||||||
"company-name": "Jinshen Machinary Manufacturing Co., Ltd.",
|
"company-name": "Jinshen Machinary Manufacturing Co., Ltd.",
|
||||||
"company-description": "Профессионально производим оборудование для бумажных трубок и канистр, услуги по проектированию, производству, продаже и сервисному обслуживанию.",
|
"company-description": "Профессионально производим оборудование для бумажных трубок и канистр, услуги по проектированию, производству, продаже и сервисному обслуживанию.",
|
||||||
"learn-more": "Узнать больше",
|
"learn-more": "Узнать больше",
|
||||||
"products-desc": "Мы предоставляем высококачественные решения для различных бизнес-потребностей.",
|
"products-desc": "Мы предоставляем новейшие продукты и мгновенную сервисную поддержку для удовлетворения различных бизнес-потребностей наших клиентов.",
|
||||||
"solutions-desc": "Предлагаем индивидуальные технологические решения для содействия цифровой трансформации.",
|
"solutions-desc": "Мы предлагаем разнообразные технические решения для предприятий, поддерживая различные области, такие как промышленность и упаковка.",
|
||||||
"support-desc": "Профессиональная техническая поддержка 24/7, обеспечивающая стабильную работу вашего бизнеса.",
|
"support-desc": "Профессиональная техническая поддержка 24/7, обеспечивающая стабильную работу вашего бизнеса.",
|
||||||
"quick-links": "Быстрые ссылки",
|
"quick-links": "Быстрые ссылки",
|
||||||
"utilities": "Полезные инструменты",
|
"utilities": "Полезные инструменты",
|
||||||
@ -63,7 +63,9 @@
|
|||||||
"back-to-home": "Вернуться на главную",
|
"back-to-home": "Вернуться на главную",
|
||||||
"no-content-available": "Нет доступной информации",
|
"no-content-available": "Нет доступной информации",
|
||||||
"loading": "Загрузка...",
|
"loading": "Загрузка...",
|
||||||
"our-products": "Наши продукты",
|
"our-products": "Наши последние продукты",
|
||||||
|
"find-discontinued-products": "Чтобы найти другие продукты, используйте функцию поиска.",
|
||||||
|
"product-discontinued-warning": "Этот продукт снят с производства и может больше не получать мгновенную поддержку или обновления",
|
||||||
"learn-our-solutions": "Узнайте о наших решениях",
|
"learn-our-solutions": "Узнайте о наших решениях",
|
||||||
"all": "Все",
|
"all": "Все",
|
||||||
"support-page-desc": "Zhejiang Jinshen Machinery Manufacturing Co., Ltd Стремится предоставлять клиентам высококачественные продукты и услуги. Мы предлагаем послепродажное обслуживание для таких продуктов, как машины для бумажных трубок и соломинок, обеспечивая уверенность клиентов в использовании нашей продукции.",
|
"support-page-desc": "Zhejiang Jinshen Machinery Manufacturing Co., Ltd Стремится предоставлять клиентам высококачественные продукты и услуги. Мы предлагаем послепродажное обслуживание для таких продуктов, как машины для бумажных трубок и соломинок, обеспечивая уверенность клиентов в использовании нашей продукции.",
|
||||||
|
|||||||
@ -23,8 +23,8 @@
|
|||||||
"company-name": "金申机械制造有限公司",
|
"company-name": "金申机械制造有限公司",
|
||||||
"company-description": "专业生产一系列纸管、纸罐设备,集设计、制造、销售、服务于一体。",
|
"company-description": "专业生产一系列纸管、纸罐设备,集设计、制造、销售、服务于一体。",
|
||||||
"learn-more": "了解更多",
|
"learn-more": "了解更多",
|
||||||
"products-desc": "我们提供高质量的产品解决方案,满足各种业务需求。",
|
"products-desc": "我们提供最新的产品与即时的服务支持,满足客户的各类业务需求。",
|
||||||
"solutions-desc": "为企业提供定制化的技术解决方案,助力数字化转型。",
|
"solutions-desc": "我们为企业提供多样化的技术解决方案,在工业、包装等多种领域提供支持。",
|
||||||
"support-desc": "7x24小时专业技术支持,确保您的业务稳定运行。",
|
"support-desc": "7x24小时专业技术支持,确保您的业务稳定运行。",
|
||||||
"quick-links": "快速链接",
|
"quick-links": "快速链接",
|
||||||
"utilities": "实用工具",
|
"utilities": "实用工具",
|
||||||
@ -63,7 +63,9 @@
|
|||||||
"back-to-home": "返回首页",
|
"back-to-home": "返回首页",
|
||||||
"no-content-available": "暂无详细信息",
|
"no-content-available": "暂无详细信息",
|
||||||
"loading": "加载中...",
|
"loading": "加载中...",
|
||||||
"our-products": "我们的产品",
|
"our-products": "我们的最新产品",
|
||||||
|
"find-discontinued-products": "如需查找其他产品,请使用搜索功能",
|
||||||
|
"product-discontinued-warning": "本产品已停产,可能不再提供即时的支持或更新",
|
||||||
"learn-our-solutions": "了解我们的解决方案",
|
"learn-our-solutions": "了解我们的解决方案",
|
||||||
"all": "全部",
|
"all": "全部",
|
||||||
"support-page-desc": "金申机械制造有限公司致力于为客户提供优质的产品与服务。针对纸管机、分纸机、纸吸管等产品,我们提供全方位的售后服务,确保客户能够安心地使用我们的产品。",
|
"support-page-desc": "金申机械制造有限公司致力于为客户提供优质的产品与服务。针对纸管机、分纸机、纸吸管等产品,我们提供全方位的售后服务,确保客户能够安心地使用我们的产品。",
|
||||||
|
|||||||
@ -51,6 +51,13 @@ query GetProduct($id: ID!, $locale: String!) {
|
|||||||
id
|
id
|
||||||
product_documents_id(filter: { status: { _eq: "published" } }) {
|
product_documents_id(filter: { status: { _eq: "published" } }) {
|
||||||
id
|
id
|
||||||
|
type {
|
||||||
|
id
|
||||||
|
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||||
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
file {
|
file {
|
||||||
id
|
id
|
||||||
filesize
|
filesize
|
||||||
|
|||||||
@ -1,9 +1,5 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
import { describe, test, expect } from 'vitest';
|
||||||
import {
|
import { toDocumentListView, toDocumentTypeView } from './documentMapper';
|
||||||
toProductDocumentView,
|
|
||||||
toDocumentListView,
|
|
||||||
toDocumentTypeView,
|
|
||||||
} from './documentMapper';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单元测试: toDocumentTypeView
|
* 单元测试: toDocumentTypeView
|
||||||
@ -46,63 +42,6 @@ describe('toDocumentTypeView', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
/**
|
|
||||||
* 单元测试: toProductDocumentView
|
|
||||||
*/
|
|
||||||
describe('toProductDocumentView', () => {
|
|
||||||
const baseData: ProductDocument = {
|
|
||||||
id: 1,
|
|
||||||
file: {
|
|
||||||
id: 'rand-om__-uuid-1234',
|
|
||||||
filename_download: 'document.pdf',
|
|
||||||
filesize: 2048,
|
|
||||||
},
|
|
||||||
translations: [{ id: 10, title: 'Document Title' }],
|
|
||||||
};
|
|
||||||
|
|
||||||
test('convert raw data with fileMeta to ProductDocumentView correctly', () => {
|
|
||||||
const rawData: ProductDocument = { ...baseData };
|
|
||||||
expect(toProductDocumentView(rawData)).toEqual({
|
|
||||||
id: '1',
|
|
||||||
fileId: 'rand-om__-uuid-1234',
|
|
||||||
filename: 'document.pdf',
|
|
||||||
title: 'Document Title',
|
|
||||||
url: '/api/assets/rand-om__-uuid-1234',
|
|
||||||
size: 2048,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('convert raw data with fileId', () => {
|
|
||||||
const rawData: ProductDocument = {
|
|
||||||
...baseData,
|
|
||||||
file: 'rand-om__-uuid-1234',
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(toProductDocumentView(rawData)).toEqual({
|
|
||||||
id: '1',
|
|
||||||
fileId: '',
|
|
||||||
filename: '',
|
|
||||||
title: 'Document Title',
|
|
||||||
url: '/api/assets/',
|
|
||||||
size: 0,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('convert raw data with missing translations', () => {
|
|
||||||
const rawData: ProductDocument = {
|
|
||||||
...baseData,
|
|
||||||
translations: [],
|
|
||||||
};
|
|
||||||
expect(toProductDocumentView(rawData)).toEqual({
|
|
||||||
id: '1',
|
|
||||||
fileId: 'rand-om__-uuid-1234',
|
|
||||||
filename: 'document.pdf',
|
|
||||||
title: '',
|
|
||||||
url: '/api/assets/rand-om__-uuid-1234',
|
|
||||||
size: 2048,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单元测试: toDocumentListView
|
* 单元测试: toDocumentListView
|
||||||
|
|||||||
@ -26,34 +26,6 @@ export function toDocumentTypeView(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 Directus 返回的 Document 数据转换为 ProductDocumentView 视图模型
|
|
||||||
*
|
|
||||||
* @param raw: 原始的 Document 数据
|
|
||||||
* @returns 转换后的 ProductDocumentView 对象
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const view = toProductDocumentView(rawDocument);
|
|
||||||
*/
|
|
||||||
export function toProductDocumentView(
|
|
||||||
raw: ProductDocument
|
|
||||||
): ProductDocumentView {
|
|
||||||
const trans = raw.translations?.[0];
|
|
||||||
const file = isObject<DirectusFile>(raw.file) ? raw.file : undefined;
|
|
||||||
const fileId = file?.id ?? '';
|
|
||||||
|
|
||||||
const url = `/api/assets/${fileId}`;
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: raw.id.toString(),
|
|
||||||
fileId: fileId,
|
|
||||||
filename: file?.filename_download ?? '',
|
|
||||||
title: trans?.title ?? '',
|
|
||||||
url: url,
|
|
||||||
size: file?.filesize ?? 0,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 Directus 返回的 Document 数据转换为 DocumentListView 视图模型
|
* 将 Directus 返回的 Document 数据转换为 DocumentListView 视图模型
|
||||||
*
|
*
|
||||||
|
|||||||
125
server/mappers/productListMapper.test.ts
Normal file
125
server/mappers/productListMapper.test.ts
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
import { describe, expect, test } from 'vitest';
|
||||||
|
import { toProductTypeView, toProductListView } from './productListMapper';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元测试: toProductTypeView
|
||||||
|
*/
|
||||||
|
describe('toProductTypeView', () => {
|
||||||
|
const baseData: ProductType = {
|
||||||
|
id: 1,
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'Type Name',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
sort: 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
test('convert raw data to ProductTypeView correctly', () => {
|
||||||
|
const rawData: ProductType = { ...baseData };
|
||||||
|
|
||||||
|
expect(toProductTypeView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: 'Type Name',
|
||||||
|
sort: 5,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing translations', () => {
|
||||||
|
const rawData: ProductType = {
|
||||||
|
...baseData,
|
||||||
|
translations: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(toProductTypeView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: '',
|
||||||
|
sort: 5,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing sort', () => {
|
||||||
|
const rawData: ProductType = {
|
||||||
|
...baseData,
|
||||||
|
sort: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(toProductTypeView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: 'Type Name',
|
||||||
|
sort: 999,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert null input to default value', () => {
|
||||||
|
const rawData: ProductType | string | null = null;
|
||||||
|
|
||||||
|
expect(toProductTypeView(rawData)).toEqual({
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
sort: 999,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元测试: toProductListView
|
||||||
|
*/
|
||||||
|
describe('toProductListView', () => {
|
||||||
|
test('convert raw data to ProductListView correctly', () => {
|
||||||
|
const rawData: Product = {
|
||||||
|
id: 1,
|
||||||
|
translations: [
|
||||||
|
{ id: 10, name: 'Product Name', summary: 'Product Summary' },
|
||||||
|
],
|
||||||
|
cover: {
|
||||||
|
id: 'cover-file-uuid-1234',
|
||||||
|
},
|
||||||
|
product_type: {
|
||||||
|
id: 1,
|
||||||
|
translations: [{ id: 20, name: 'Type Name' }],
|
||||||
|
sort: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(toProductListView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: 'Product Name',
|
||||||
|
summary: 'Product Summary',
|
||||||
|
cover: 'cover-file-uuid-1234',
|
||||||
|
product_type: {
|
||||||
|
id: '1',
|
||||||
|
name: 'Type Name',
|
||||||
|
sort: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing translations', () => {
|
||||||
|
const rawData: Product = {
|
||||||
|
id: 1,
|
||||||
|
translations: [],
|
||||||
|
cover: {
|
||||||
|
id: 'cover-file-uuid-1234',
|
||||||
|
},
|
||||||
|
product_type: {
|
||||||
|
id: 20,
|
||||||
|
translations: [],
|
||||||
|
sort: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(toProductListView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: '',
|
||||||
|
summary: '',
|
||||||
|
cover: 'cover-file-uuid-1234',
|
||||||
|
product_type: {
|
||||||
|
id: '20',
|
||||||
|
name: '',
|
||||||
|
sort: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
54
server/mappers/productListMapper.ts
Normal file
54
server/mappers/productListMapper.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { isObject } from '../../server/utils/object';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Directus返回的ProductType数据转换为ProductTypeView视图模型
|
||||||
|
*
|
||||||
|
* @param raw: 原始的ProductType数据
|
||||||
|
* @returns 转换后的ProductTypeView对象
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const view = toProductTypeView(rawProductType);
|
||||||
|
*/
|
||||||
|
export function toProductTypeView(
|
||||||
|
raw: ProductType | string | null
|
||||||
|
): ProductTypeView {
|
||||||
|
if (typeof raw === 'string' || raw === null) {
|
||||||
|
return {
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
sort: 999,
|
||||||
|
} satisfies ProductTypeView;
|
||||||
|
}
|
||||||
|
const trans = raw.translations?.[0] ?? { name: '' };
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: raw.id.toString(),
|
||||||
|
name: trans.name,
|
||||||
|
sort: raw?.sort ?? 999,
|
||||||
|
} satisfies ProductTypeView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Directus返回的 Product 数据转换为 ProductListView 视图模型
|
||||||
|
*
|
||||||
|
* @param raw: 原始的 Product 数据
|
||||||
|
* @returns 转换后的 ProductListView 对象
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const view = toProductListView(rawProduct);
|
||||||
|
*/
|
||||||
|
export function toProductListView(raw: Product): ProductListView {
|
||||||
|
const trans = raw.translations?.[0];
|
||||||
|
|
||||||
|
const type = toProductTypeView(raw.product_type ?? null);
|
||||||
|
|
||||||
|
const cover = isObject<DirectusFile>(raw.cover) ? raw.cover.id : '';
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: raw.id.toString(),
|
||||||
|
product_type: type,
|
||||||
|
name: trans?.name ?? '',
|
||||||
|
summary: trans?.summary ?? '',
|
||||||
|
cover: cover,
|
||||||
|
} satisfies ProductListView;
|
||||||
|
}
|
||||||
@ -1,69 +1,111 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
import { describe, test, expect } from 'vitest';
|
||||||
import {
|
import {
|
||||||
toProductListView,
|
toProductImageView,
|
||||||
toProductSpecView,
|
toProductSpecView,
|
||||||
toProductSpecGroupView,
|
toProductSpecGroupView,
|
||||||
|
toProductQuestionView,
|
||||||
|
toProductDocumentView,
|
||||||
toProductView,
|
toProductView,
|
||||||
} from './productMapper';
|
} from './productMapper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单元测试: toProductListView
|
* 单元测试: toProductImageView
|
||||||
*/
|
*/
|
||||||
describe('toProductListView', () => {
|
describe('toProductImageView', () => {
|
||||||
test('convert raw data to ProductListView correctly', () => {
|
const baseData: Array<ProductsProductImage> = [
|
||||||
const rawData: Product = {
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
translations: [
|
product_images_id: {
|
||||||
{ id: 10, name: 'Product Name', summary: 'Product Summary' },
|
|
||||||
],
|
|
||||||
cover: {
|
|
||||||
id: 'cover-file-uuid-1234',
|
|
||||||
},
|
|
||||||
product_type: {
|
|
||||||
id: 1,
|
id: 1,
|
||||||
translations: [{ id: 20, name: 'Type Name' }],
|
image: {
|
||||||
sort: 1,
|
id: 'rand-om__-uuid-1234',
|
||||||
|
},
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
caption: 'Image Caption',
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
};
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
product_images_id: {
|
||||||
|
id: 2,
|
||||||
|
image: {
|
||||||
|
id: 'rand-om__-uuid-5678',
|
||||||
|
},
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
caption: 'Image Caption 2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
expect(toProductListView(rawData)).toEqual({
|
test('convert raw data to ProductImageView correctly', () => {
|
||||||
id: '1',
|
const rawData: Array<ProductsProductImage> = [...baseData];
|
||||||
name: 'Product Name',
|
|
||||||
summary: 'Product Summary',
|
expect(toProductImageView(rawData)).toEqual([
|
||||||
cover: 'cover-file-uuid-1234',
|
{
|
||||||
product_type: {
|
|
||||||
id: '1',
|
id: '1',
|
||||||
name: 'Type Name',
|
image: 'rand-om__-uuid-1234',
|
||||||
sort: 1,
|
caption: 'Image Caption',
|
||||||
},
|
},
|
||||||
});
|
{
|
||||||
|
id: '2',
|
||||||
|
image: 'rand-om__-uuid-5678',
|
||||||
|
caption: 'Image Caption 2',
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('convert raw data with missing translations', () => {
|
test('convert raw data with missing translations', () => {
|
||||||
const rawData: Product = {
|
const rawData: Array<ProductsProductImage> = [
|
||||||
id: 1,
|
{
|
||||||
translations: [],
|
id: 1,
|
||||||
cover: {
|
product_images_id: {
|
||||||
id: 'cover-file-uuid-1234',
|
id: 1,
|
||||||
|
image: {
|
||||||
|
id: 'rand-om__-uuid-1234',
|
||||||
|
},
|
||||||
|
translations: [],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
product_type: {
|
];
|
||||||
id: 20,
|
|
||||||
translations: [],
|
|
||||||
sort: 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(toProductListView(rawData)).toEqual({
|
expect(toProductImageView(rawData)).toEqual([
|
||||||
id: '1',
|
{
|
||||||
name: '',
|
id: '1',
|
||||||
summary: '',
|
image: 'rand-om__-uuid-1234',
|
||||||
cover: 'cover-file-uuid-1234',
|
caption: '',
|
||||||
product_type: {
|
|
||||||
id: '20',
|
|
||||||
name: '',
|
|
||||||
sort: 1,
|
|
||||||
},
|
},
|
||||||
});
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert empty array to empty ProductImageView array', () => {
|
||||||
|
const rawData: Array<ProductsProductImage> = [];
|
||||||
|
|
||||||
|
expect(toProductImageView(rawData)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert input with wrong type to default value', () => {
|
||||||
|
const rawData: string[] = ['1', '2'];
|
||||||
|
|
||||||
|
expect(toProductImageView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
image: '',
|
||||||
|
caption: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
image: '',
|
||||||
|
caption: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -71,30 +113,78 @@ describe('toProductListView', () => {
|
|||||||
* 单元测试: toProductSpecView
|
* 单元测试: toProductSpecView
|
||||||
*/
|
*/
|
||||||
describe('toProductSpecView', () => {
|
describe('toProductSpecView', () => {
|
||||||
test('convert raw data to ProductSpecView correctly', () => {
|
const baseData: ProductSpec[] = [
|
||||||
const rawData: ProductSpec = {
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
translations: [{ id: 1, key: 'Key', value: 'Value' }],
|
translations: [
|
||||||
};
|
{
|
||||||
|
id: 1,
|
||||||
|
key: 'key 1',
|
||||||
|
value: 'value 1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
key: 'key 2',
|
||||||
|
value: 'value 2',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
test('convert raw data to ProductSpecView correctly', () => {
|
||||||
|
const rawData: ProductSpec[] = [...baseData];
|
||||||
|
|
||||||
expect(toProductSpecView(rawData)).toEqual({
|
expect(toProductSpecView(rawData)).toEqual([
|
||||||
id: '1',
|
{
|
||||||
key: 'Key',
|
id: '1',
|
||||||
value: 'Value',
|
key: 'key 1',
|
||||||
});
|
value: 'value 1',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
key: 'key 2',
|
||||||
|
value: 'value 2',
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('convert raw data with missing translations', () => {
|
test('convert raw data with missing translations', () => {
|
||||||
const rawData: ProductSpec = {
|
const rawData: ProductSpec[] = [{ id: 1, translations: [] }];
|
||||||
id: 1,
|
|
||||||
translations: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(toProductSpecView(rawData)).toEqual({
|
expect(toProductSpecView(rawData)).toEqual([
|
||||||
id: '1',
|
{
|
||||||
key: '',
|
id: '1',
|
||||||
value: '',
|
key: '',
|
||||||
});
|
value: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert empty input to empty array', () => {
|
||||||
|
const rawData: ProductSpec[] = [];
|
||||||
|
|
||||||
|
expect(toProductSpecView(rawData)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert input with wrong type to default value', () => {
|
||||||
|
const rawData: string[] = ['1', '2'];
|
||||||
|
|
||||||
|
expect(toProductSpecView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
key: '',
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
key: '',
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -103,37 +193,262 @@ describe('toProductSpecView', () => {
|
|||||||
*/
|
*/
|
||||||
describe('toProductSpecGroupView', () => {
|
describe('toProductSpecGroupView', () => {
|
||||||
test('convert raw data to ProductSpecGroupView correctly', () => {
|
test('convert raw data to ProductSpecGroupView correctly', () => {
|
||||||
const rawData: ProductSpecGroup = {
|
const rawData: ProductSpecGroup[] = [
|
||||||
id: 1,
|
{
|
||||||
translations: [{ id: 1, name: 'Group Name' }],
|
id: 1,
|
||||||
specs: [
|
translations: [{ id: 1, name: 'Group Name' }],
|
||||||
{ id: 1, translations: [{ id: 1, key: 'Key1', value: 'Value1' }] },
|
specs: [
|
||||||
{ id: 2, translations: [{ id: 2, key: 'Key2', value: 'Value2' }] },
|
{ id: 1, translations: [{ id: 1, key: 'Key1', value: 'Value1' }] },
|
||||||
],
|
{ id: 2, translations: [{ id: 2, key: 'Key2', value: 'Value2' }] },
|
||||||
};
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
expect(toProductSpecGroupView(rawData)).toEqual({
|
expect(toProductSpecGroupView(rawData)).toEqual([
|
||||||
id: '1',
|
{
|
||||||
name: 'Group Name',
|
id: '1',
|
||||||
specs: [
|
name: 'Group Name',
|
||||||
{ id: '1', key: 'Key1', value: 'Value1' },
|
specs: [
|
||||||
{ id: '2', key: 'Key2', value: 'Value2' },
|
{ id: '1', key: 'Key1', value: 'Value1' },
|
||||||
],
|
{ id: '2', key: 'Key2', value: 'Value2' },
|
||||||
});
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('convert raw data with missing translations', () => {
|
test('convert raw data with missing translations', () => {
|
||||||
const rawData: ProductSpecGroup = {
|
const rawData: ProductSpecGroup[] = [
|
||||||
id: 1,
|
{
|
||||||
translations: [],
|
id: 1,
|
||||||
specs: [],
|
translations: [],
|
||||||
};
|
specs: [],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
expect(toProductSpecGroupView(rawData)).toEqual({
|
expect(toProductSpecGroupView(rawData)).toEqual([
|
||||||
id: '1',
|
{
|
||||||
name: '',
|
id: '1',
|
||||||
specs: [],
|
name: '',
|
||||||
});
|
specs: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert input with wrong type to default value', () => {
|
||||||
|
const rawData: string[] = ['1', '2'];
|
||||||
|
|
||||||
|
expect(toProductSpecGroupView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
name: '',
|
||||||
|
specs: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
name: '',
|
||||||
|
specs: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert empty ar ray to empty ProductSpecGroupView array', () => {
|
||||||
|
const rawData: ProductSpec[] = [];
|
||||||
|
|
||||||
|
expect(toProductSpecGroupView(rawData)).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元测试: toProductQuestionView
|
||||||
|
*/
|
||||||
|
describe('toProductQuestionView', () => {
|
||||||
|
test('convert raw data to ProductQuestionView correctly', () => {
|
||||||
|
const rawData: ProductsQuestion[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
questions_id: {
|
||||||
|
id: 1,
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
title: 'Question Title',
|
||||||
|
content: 'Question Content',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(toProductQuestionView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
title: 'Question Title',
|
||||||
|
content: 'Question Content',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing translations', () => {
|
||||||
|
const rawData: ProductsQuestion[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
questions_id: {
|
||||||
|
id: 1,
|
||||||
|
translations: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(toProductQuestionView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert empty array to empty ProductQuestionView array', () => {
|
||||||
|
const rawData: ProductsQuestion[] = [];
|
||||||
|
|
||||||
|
expect(toProductQuestionView(rawData)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert input with wrong type to default value', () => {
|
||||||
|
const rawData: string[] = ['1', '2'];
|
||||||
|
|
||||||
|
expect(toProductQuestionView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元测试: toProductDocumentView
|
||||||
|
*/
|
||||||
|
describe('toProductDocumentView', () => {
|
||||||
|
test('convert raw data to ProductDocumentView correctly', () => {
|
||||||
|
const rawData: ProductsProductDocument[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
product_documents_id: {
|
||||||
|
id: 1,
|
||||||
|
file: {
|
||||||
|
id: 'rand-om__-uuid-1234',
|
||||||
|
filesize: 1000,
|
||||||
|
filename_download: 'doc1.pdf',
|
||||||
|
},
|
||||||
|
type: {
|
||||||
|
id: 1,
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'manual',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
title: 'Document Title 1',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(toProductDocumentView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
fileId: 'rand-om__-uuid-1234',
|
||||||
|
filename: 'doc1.pdf',
|
||||||
|
title: 'Document Title 1',
|
||||||
|
type: {
|
||||||
|
id: '1',
|
||||||
|
name: 'manual',
|
||||||
|
},
|
||||||
|
size: 1000,
|
||||||
|
url: '/api/assets/rand-om__-uuid-1234',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing translations', () => {
|
||||||
|
const rawData: ProductsProductDocument[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
product_documents_id: {
|
||||||
|
id: 1,
|
||||||
|
file: {
|
||||||
|
id: 'rand-om__-uuid-1234',
|
||||||
|
filesize: 1000,
|
||||||
|
filename_download: 'doc1.pdf',
|
||||||
|
},
|
||||||
|
translations: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(toProductDocumentView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
fileId: 'rand-om__-uuid-1234',
|
||||||
|
filename: 'doc1.pdf',
|
||||||
|
title: '',
|
||||||
|
type: {
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
size: 1000,
|
||||||
|
url: '/api/assets/rand-om__-uuid-1234',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert empty array to empty ProductDocumentView array', () => {
|
||||||
|
const rawData: ProductsProductDocument[] = [];
|
||||||
|
|
||||||
|
expect(toProductDocumentView(rawData)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert input with wrong type to default value', () => {
|
||||||
|
const rawData: string[] = ['1', '2'];
|
||||||
|
|
||||||
|
expect(toProductDocumentView(rawData)).toEqual([
|
||||||
|
{
|
||||||
|
id: '1',
|
||||||
|
fileId: '',
|
||||||
|
filename: '',
|
||||||
|
title: '',
|
||||||
|
size: 0,
|
||||||
|
type: {
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
url: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '2',
|
||||||
|
fileId: '',
|
||||||
|
filename: '',
|
||||||
|
title: '',
|
||||||
|
size: 0,
|
||||||
|
type: {
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
url: '',
|
||||||
|
},
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -141,25 +456,29 @@ describe('toProductSpecGroupView', () => {
|
|||||||
* 单元测试: toProductView
|
* 单元测试: toProductView
|
||||||
*/
|
*/
|
||||||
describe('toProductView', () => {
|
describe('toProductView', () => {
|
||||||
|
const baseData: Product = {
|
||||||
|
id: 1,
|
||||||
|
status: 'in-production',
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'Product Name',
|
||||||
|
summary: 'Product Summary',
|
||||||
|
description: 'Product Description',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
test('convert raw data to ProductView correctly', () => {
|
test('convert raw data to ProductView correctly', () => {
|
||||||
const rawData: Product = {
|
const rawData: Product = {
|
||||||
id: 1,
|
...baseData,
|
||||||
translations: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: 'Product Name',
|
|
||||||
summary: 'Product Summary',
|
|
||||||
description: 'Product Description',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(toProductView(rawData)).toEqual({
|
expect(toProductView(rawData)).toEqual({
|
||||||
id: '1',
|
id: '1',
|
||||||
|
status: 'in-production',
|
||||||
name: 'Product Name',
|
name: 'Product Name',
|
||||||
summary: 'Product Summary',
|
summary: 'Product Summary',
|
||||||
description: 'Product Description',
|
description: 'Product Description',
|
||||||
product_type: '',
|
|
||||||
images: [],
|
images: [],
|
||||||
documents: [],
|
documents: [],
|
||||||
faqs: [],
|
faqs: [],
|
||||||
@ -169,16 +488,35 @@ describe('toProductView', () => {
|
|||||||
|
|
||||||
test('convert raw data with missing translations', () => {
|
test('convert raw data with missing translations', () => {
|
||||||
const rawData: Product = {
|
const rawData: Product = {
|
||||||
id: 1,
|
...baseData,
|
||||||
translations: [],
|
translations: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(toProductView(rawData)).toEqual({
|
expect(toProductView(rawData)).toEqual({
|
||||||
id: '1',
|
id: '1',
|
||||||
|
status: 'in-production',
|
||||||
name: '',
|
name: '',
|
||||||
summary: '',
|
summary: '',
|
||||||
description: '',
|
description: '',
|
||||||
product_type: '',
|
images: [],
|
||||||
|
documents: [],
|
||||||
|
faqs: [],
|
||||||
|
specs: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('conert raw data with missing status', () => {
|
||||||
|
const rawData: Product = {
|
||||||
|
...baseData,
|
||||||
|
status: undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(toProductView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
status: 'discontinued',
|
||||||
|
name: 'Product Name',
|
||||||
|
summary: 'Product Summary',
|
||||||
|
description: 'Product Description',
|
||||||
images: [],
|
images: [],
|
||||||
documents: [],
|
documents: [],
|
||||||
faqs: [],
|
faqs: [],
|
||||||
|
|||||||
@ -1,55 +1,42 @@
|
|||||||
import { toProductQuestionView } from './questionMapper';
|
|
||||||
import { toProductDocumentView } from './documentMapper';
|
|
||||||
import { isObject } from '../../server/utils/object';
|
import { isObject } from '../../server/utils/object';
|
||||||
|
import { toDocumentTypeView } from './documentMapper';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将Directus返回的ProductType数据转换为ProductTypeView视图模型
|
* 将 Directus 返回的 ProductImage 数据转换为 ProductImageView 视图模型
|
||||||
*
|
*
|
||||||
* @param raw: 原始的ProductType数据
|
* @param raw: 原始的 ProductsProductImage 数据
|
||||||
* @returns 转换后的ProductTypeView对象
|
* @returns 转换后的 ProductImageView 对象
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const view = toProductTypeView(rawProductType);
|
* const view = toProductImageView(rawProductImage);
|
||||||
*/
|
*/
|
||||||
export function toProductTypeView(raw: ProductType): ProductTypeView {
|
export function toProductImageView(
|
||||||
const trans = raw.translations?.[0] ?? { name: '' };
|
raw: (ProductsProductImage | string)[]
|
||||||
|
): ProductImageView[] {
|
||||||
|
return (raw ?? []).map((item) => {
|
||||||
|
if (!isObject<ProductsProductImage>(item))
|
||||||
|
return {
|
||||||
|
id: item,
|
||||||
|
image: '',
|
||||||
|
caption: '',
|
||||||
|
} satisfies ProductImageView;
|
||||||
|
|
||||||
return {
|
const image = item.product_images_id;
|
||||||
id: raw.id.toString(),
|
if (!isObject<ProductImage>(image))
|
||||||
name: trans.name,
|
return {
|
||||||
sort: raw?.sort ?? 999,
|
id: item.id.toString(),
|
||||||
};
|
image: '',
|
||||||
}
|
caption: '',
|
||||||
|
} satisfies ProductImageView;
|
||||||
|
|
||||||
/**
|
const trans = image.translations?.[0];
|
||||||
* 将 Directus返回的 Product 数据转换为 ProductListView 视图模型
|
|
||||||
*
|
|
||||||
* @param raw: 原始的 Product 数据
|
|
||||||
* @returns 转换后的 ProductListView 对象
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const view = toProductListView(rawProduct);
|
|
||||||
*/
|
|
||||||
export function toProductListView(raw: Product): ProductListView {
|
|
||||||
const trans = raw.translations?.[0];
|
|
||||||
|
|
||||||
const type = isObject<ProductType>(raw.product_type)
|
return {
|
||||||
? toProductTypeView(raw.product_type)
|
id: item.id.toString(),
|
||||||
: ({
|
image: isObject<DirectusFile>(image.image) ? image.image.id : '',
|
||||||
id: '',
|
caption: trans?.caption || '',
|
||||||
name: '',
|
} satisfies ProductImageView;
|
||||||
sort: 999,
|
});
|
||||||
} satisfies ProductTypeView);
|
|
||||||
|
|
||||||
const cover = isObject<DirectusFile>(raw.cover) ? raw.cover.id : '';
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: raw.id.toString(),
|
|
||||||
product_type: type,
|
|
||||||
name: trans?.name ?? '',
|
|
||||||
summary: trans?.summary ?? '',
|
|
||||||
cover: cover,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,19 +49,26 @@ export function toProductListView(raw: Product): ProductListView {
|
|||||||
* const view = toProductSpecGroupView(rawSpecGroup);
|
* const view = toProductSpecGroupView(rawSpecGroup);
|
||||||
*/
|
*/
|
||||||
export function toProductSpecGroupView(
|
export function toProductSpecGroupView(
|
||||||
raw: ProductSpecGroup
|
raw: (ProductSpecGroup | string)[]
|
||||||
): ProductSpecGroupView {
|
): ProductSpecGroupView[] {
|
||||||
const trans = raw.translations?.[0];
|
return (raw ?? []).map((item) => {
|
||||||
|
if (!isObject<ProductSpecGroup>(item)) {
|
||||||
|
return {
|
||||||
|
id: item,
|
||||||
|
name: '',
|
||||||
|
specs: [],
|
||||||
|
} satisfies ProductSpecGroupView;
|
||||||
|
}
|
||||||
|
const trans = item.translations?.[0];
|
||||||
|
|
||||||
const specs = raw.specs ?? [];
|
const specs = toProductSpecView(item?.specs ?? []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: raw.id.toString(),
|
id: item.id.toString(),
|
||||||
name: trans?.name ?? '',
|
name: trans?.name ?? '',
|
||||||
specs: specs
|
specs: specs,
|
||||||
.filter(isObject<ProductSpec>)
|
} satisfies ProductSpecGroupView;
|
||||||
.map((item) => toProductSpecView(item)),
|
});
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,14 +80,131 @@ export function toProductSpecGroupView(
|
|||||||
* @example
|
* @example
|
||||||
* const view = toProductSpecView(rawSpecGroup);
|
* const view = toProductSpecView(rawSpecGroup);
|
||||||
*/
|
*/
|
||||||
export function toProductSpecView(raw: ProductSpec): ProductSpecView {
|
export function toProductSpecView(
|
||||||
const trans = raw.translations?.[0];
|
raw: (ProductSpec | string)[]
|
||||||
|
): ProductSpecView[] {
|
||||||
|
return (raw ?? []).map((item) => {
|
||||||
|
if (!isObject<ProductSpec>(item)) {
|
||||||
|
return {
|
||||||
|
id: item,
|
||||||
|
key: '',
|
||||||
|
value: '',
|
||||||
|
} satisfies ProductSpecView;
|
||||||
|
}
|
||||||
|
const trans = item.translations?.[0];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: raw.id.toString(),
|
id: item.id.toString(),
|
||||||
key: trans?.key ?? '',
|
key: trans?.key ?? '',
|
||||||
value: trans?.value ?? '',
|
value: trans?.value ?? '',
|
||||||
};
|
} satisfies ProductSpecView;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Directus 返回的 ProductQuestion 数据转换为 ProductQuestionView 视图模型
|
||||||
|
*
|
||||||
|
* @param raw: 原始的ProductQuestion 数据
|
||||||
|
* @returns 转换后的 ProductQuestionView 对象
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const view = toProductQuestionView(rawQuestion);
|
||||||
|
*/
|
||||||
|
export function toProductQuestionView(
|
||||||
|
raw: (ProductsQuestion | string)[]
|
||||||
|
): ProductQuestionView[] {
|
||||||
|
return (raw ?? []).map((item) => {
|
||||||
|
if (!isObject<ProductsQuestion>(item)) {
|
||||||
|
return {
|
||||||
|
id: item,
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
} satisfies ProductQuestionView;
|
||||||
|
}
|
||||||
|
|
||||||
|
const question = item.questions_id;
|
||||||
|
if (!isObject<Question>(question)) {
|
||||||
|
return {
|
||||||
|
id: item.id.toString(),
|
||||||
|
title: '',
|
||||||
|
content: '',
|
||||||
|
} satisfies ProductQuestionView;
|
||||||
|
}
|
||||||
|
|
||||||
|
const trans = question.translations?.[0];
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: item.id.toString(),
|
||||||
|
title: trans?.title ?? '',
|
||||||
|
content: trans?.content ?? '',
|
||||||
|
} satisfies ProductQuestionView;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Directus 返回的 ProductDocument 数据转换为 ProductDocumentView 视图模型
|
||||||
|
*
|
||||||
|
* @param raw: 原始的ProductDocument 数据
|
||||||
|
* @returns 转换后的 ProductDocumentView 对象
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const view = toProductDocumentView(rawDocument);
|
||||||
|
*/
|
||||||
|
export function toProductDocumentView(
|
||||||
|
raw: (ProductsProductDocument | string)[]
|
||||||
|
): ProductDocumentView[] {
|
||||||
|
return (raw ?? []).map((item) => {
|
||||||
|
if (!isObject<ProductsProductDocument>(item)) {
|
||||||
|
return {
|
||||||
|
id: item,
|
||||||
|
fileId: '',
|
||||||
|
filename: '',
|
||||||
|
size: 0,
|
||||||
|
title: '',
|
||||||
|
url: '',
|
||||||
|
type: {
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
} satisfies ProductDocumentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
const document = item.product_documents_id;
|
||||||
|
if (!isObject<ProductDocument>(document)) {
|
||||||
|
return {
|
||||||
|
id: item.id.toString(),
|
||||||
|
fileId: '',
|
||||||
|
filename: '',
|
||||||
|
size: 0,
|
||||||
|
title: '',
|
||||||
|
url: '',
|
||||||
|
type: {
|
||||||
|
id: '-1',
|
||||||
|
name: '',
|
||||||
|
},
|
||||||
|
} satisfies ProductDocumentView;
|
||||||
|
}
|
||||||
|
|
||||||
|
const file = isObject<DirectusFile>(document.file)
|
||||||
|
? document.file
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const url = file ? `/api/assets/${file.id}` : '';
|
||||||
|
|
||||||
|
const trans = document.translations?.[0];
|
||||||
|
|
||||||
|
const typeView = toDocumentTypeView(document.type ?? null);
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: item.id.toString(),
|
||||||
|
fileId: file?.id ?? '',
|
||||||
|
filename: file?.filename_download ?? '',
|
||||||
|
size: file?.filesize ?? 0,
|
||||||
|
title: trans?.title ?? '',
|
||||||
|
url: url,
|
||||||
|
type: typeView,
|
||||||
|
} satisfies ProductDocumentView;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,42 +219,19 @@ export function toProductSpecView(raw: ProductSpec): ProductSpecView {
|
|||||||
export function toProductView(raw: Product): ProductView {
|
export function toProductView(raw: Product): ProductView {
|
||||||
const trans = raw.translations?.[0];
|
const trans = raw.translations?.[0];
|
||||||
|
|
||||||
const images = (raw.images ?? [])
|
const status = raw.status ?? 'discontinued';
|
||||||
.filter(isObject<ProductsProductImage>)
|
|
||||||
.map((item) => item.product_images_id)
|
|
||||||
.filter(isObject<ProductImage>)
|
|
||||||
.map((item) => {
|
|
||||||
const image = isObject<DirectusFile>(item.image) ? item.image.id : '';
|
|
||||||
return {
|
|
||||||
id: item.id.toString(),
|
|
||||||
image: image,
|
|
||||||
caption: item.translations?.[0]?.caption || '',
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
const type = isObject<ProductType>(raw.product_type)
|
const images = toProductImageView(raw.images ?? []);
|
||||||
? (raw.product_type.translations?.[0]?.name ?? '')
|
|
||||||
: '';
|
|
||||||
|
|
||||||
const specs = (raw.specs ?? [])
|
const specs = toProductSpecGroupView(raw.specs ?? []);
|
||||||
.filter(isObject<ProductSpecGroup>)
|
|
||||||
.map((item) => toProductSpecGroupView(item));
|
|
||||||
|
|
||||||
const faqs = (raw.faqs ?? [])
|
const faqs = toProductQuestionView(raw.faqs ?? []);
|
||||||
.filter(isObject<ProductsQuestion>)
|
|
||||||
.map((item) => item.questions_id)
|
|
||||||
.filter(isObject<Question>)
|
|
||||||
.map((item) => toProductQuestionView(item));
|
|
||||||
|
|
||||||
const documents = (raw.documents ?? [])
|
const documents = toProductDocumentView(raw.documents ?? []);
|
||||||
.filter(isObject<ProductsProductDocument>)
|
|
||||||
.map((item) => item.product_documents_id)
|
|
||||||
.filter(isObject<ProductDocument>)
|
|
||||||
.map((item) => toProductDocumentView(item));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: raw.id.toString(),
|
id: raw.id.toString(),
|
||||||
product_type: type,
|
status: status,
|
||||||
name: trans?.name ?? '',
|
name: trans?.name ?? '',
|
||||||
summary: trans?.summary ?? '',
|
summary: trans?.summary ?? '',
|
||||||
images: images,
|
images: images,
|
||||||
@ -151,5 +239,5 @@ export function toProductView(raw: Product): ProductView {
|
|||||||
specs: specs,
|
specs: specs,
|
||||||
faqs: faqs,
|
faqs: faqs,
|
||||||
documents: documents,
|
documents: documents,
|
||||||
};
|
} satisfies ProductView;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,5 @@
|
|||||||
import { describe, expect, test } from 'vitest';
|
import { describe, expect, test } from 'vitest';
|
||||||
import {
|
import { toQuestionListView, toQuestionTypeView } from './questionMapper';
|
||||||
toProductQuestionView,
|
|
||||||
toQuestionListView,
|
|
||||||
toQuestionTypeView,
|
|
||||||
} from './questionMapper';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单元测试: toQuestionTypeView
|
* 单元测试: toQuestionTypeView
|
||||||
@ -47,42 +43,6 @@ describe('toQuestionTypeView', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
|
||||||
* 单元测试: toProductQuestionView
|
|
||||||
*/
|
|
||||||
describe('toProductQuestionView', () => {
|
|
||||||
const baseData: Question = {
|
|
||||||
id: 1,
|
|
||||||
translations: [
|
|
||||||
{ id: 1, title: 'Question Title', content: 'Question Answer' },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
test('convert raw data to ProductQuestionView correctly', () => {
|
|
||||||
const rawData: Question = {
|
|
||||||
...baseData,
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(toProductQuestionView(rawData)).toEqual({
|
|
||||||
id: '1',
|
|
||||||
title: 'Question Title',
|
|
||||||
content: 'Question Answer',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('convert raw data with missing translations', () => {
|
|
||||||
const rawData: Question = {
|
|
||||||
...baseData,
|
|
||||||
translations: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(toProductQuestionView(rawData)).toEqual({
|
|
||||||
id: '1',
|
|
||||||
title: '',
|
|
||||||
content: '',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单元测试: toQuestionListView
|
* 单元测试: toQuestionListView
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -26,25 +26,6 @@ export function toQuestionTypeView(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 Directus 返回的 Question 数据转换为 ProductQuestionView 视图模型
|
|
||||||
*
|
|
||||||
* @param raw: 原始的 Question 数据
|
|
||||||
* @returns 转换后的 ProductQuestionView 对象
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const view = toProductQuestionView(rawQuestion);
|
|
||||||
*/
|
|
||||||
export function toProductQuestionView(raw: Question): ProductQuestionView {
|
|
||||||
const trans = raw.translations?.[0];
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: raw.id.toString(),
|
|
||||||
title: trans?.title ?? '',
|
|
||||||
content: trans?.content ?? '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 Directus 返回的 Question 数据转换为 QuestionListView 视图模型
|
* 将 Directus 返回的 Question 数据转换为 QuestionListView 视图模型
|
||||||
*
|
*
|
||||||
|
|||||||
109
server/mappers/solutionListMapper.test.ts
Normal file
109
server/mappers/solutionListMapper.test.ts
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
import { toSolutionListView, toSolutionTypeView } from './solutionListMapper';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元测试: toSolutionTypeView
|
||||||
|
*/
|
||||||
|
describe('toSolutionTypeView', () => {
|
||||||
|
const baseData: SolutionType = {
|
||||||
|
id: 1,
|
||||||
|
translations: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: 'Type Name',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
sort: 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
test('convert raw data to SolutionTypeView correctly', () => {
|
||||||
|
const rawData: SolutionType = { ...baseData };
|
||||||
|
|
||||||
|
expect(toSolutionTypeView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: 'Type Name',
|
||||||
|
sort: 5,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing translations', () => {
|
||||||
|
const rawData: SolutionType = { ...baseData, translations: [] };
|
||||||
|
|
||||||
|
expect(toSolutionTypeView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: '',
|
||||||
|
sort: 5,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing sort', () => {
|
||||||
|
const rawData: SolutionType = { ...baseData, sort: undefined };
|
||||||
|
|
||||||
|
expect(toSolutionTypeView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
name: 'Type Name',
|
||||||
|
sort: 999,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert null input to default value', () => {
|
||||||
|
const rawData: SolutionType | string | null = null;
|
||||||
|
|
||||||
|
expect(toSolutionTypeView(rawData)).toEqual({
|
||||||
|
id: '-1',
|
||||||
|
name: 'uncategory',
|
||||||
|
sort: 999,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单元测试: toSolutionListView
|
||||||
|
*/
|
||||||
|
describe('toSolutionListView', () => {
|
||||||
|
const baseData: Solution = {
|
||||||
|
id: 1,
|
||||||
|
translations: [
|
||||||
|
{ id: 1, title: 'Solution Title', summary: 'Solution Summary' },
|
||||||
|
],
|
||||||
|
type: {
|
||||||
|
id: 1,
|
||||||
|
translations: [{ id: 1, name: 'Type Name' }],
|
||||||
|
sort: 1,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
test('convert raw data to SolutionListView correctly', () => {
|
||||||
|
const rawData: Solution = { ...baseData };
|
||||||
|
|
||||||
|
expect(toSolutionListView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
title: 'Solution Title',
|
||||||
|
summary: 'Solution Summary',
|
||||||
|
solution_type: {
|
||||||
|
id: '1',
|
||||||
|
name: 'Type Name',
|
||||||
|
sort: 1,
|
||||||
|
},
|
||||||
|
cover: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('convert raw data with missing translations', () => {
|
||||||
|
const rawData: Solution = {
|
||||||
|
...baseData,
|
||||||
|
translations: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(toSolutionListView(rawData)).toEqual({
|
||||||
|
id: '1',
|
||||||
|
title: '',
|
||||||
|
summary: '',
|
||||||
|
solution_type: {
|
||||||
|
id: '1',
|
||||||
|
name: 'Type Name',
|
||||||
|
sort: 1,
|
||||||
|
},
|
||||||
|
cover: '',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
58
server/mappers/solutionListMapper.ts
Normal file
58
server/mappers/solutionListMapper.ts
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import { isObject } from '../../server/utils/object';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Directus 返回的 SolutionType 数据转换为 SolutionTypeView 视图模型
|
||||||
|
*
|
||||||
|
* @param raw: 原始的 SolutionType 数据
|
||||||
|
* @returns 转换后的 SolutionTypeView 对象
|
||||||
|
*
|
||||||
|
* ---
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const view = toSolutionTypeView(rawSolutionType);
|
||||||
|
*/
|
||||||
|
export function toSolutionTypeView(
|
||||||
|
raw: SolutionType | string | null
|
||||||
|
): SolutionTypeView {
|
||||||
|
if (typeof raw === 'string' || raw === null) {
|
||||||
|
return {
|
||||||
|
id: '-1',
|
||||||
|
name: 'uncategory',
|
||||||
|
sort: 999,
|
||||||
|
} satisfies SolutionTypeView;
|
||||||
|
}
|
||||||
|
const trans = raw?.translations?.[0];
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: raw.id.toString(),
|
||||||
|
name: trans?.name ?? '',
|
||||||
|
sort: raw?.sort ?? 999,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 Directus 返回的 Solution 数据转换为 SolutionListView 视图模型
|
||||||
|
*
|
||||||
|
* @param raw: 原始的 Solution 数据
|
||||||
|
* @returns 转换后的 SolutionListView 对象
|
||||||
|
*
|
||||||
|
* ---
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* const view = toSolutionListView(rawSolution);
|
||||||
|
*/
|
||||||
|
export function toSolutionListView(raw: Solution): SolutionListView {
|
||||||
|
const trans = raw.translations?.[0];
|
||||||
|
|
||||||
|
const type = toSolutionTypeView(raw.type ?? null);
|
||||||
|
|
||||||
|
const cover = isObject<DirectusFile>(raw.cover) ? (raw?.cover.id ?? '') : '';
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: raw.id.toString(),
|
||||||
|
title: trans?.title ?? '',
|
||||||
|
summary: trans?.summary ?? '',
|
||||||
|
solution_type: type,
|
||||||
|
cover: cover,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -1,56 +1,5 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
import { describe, test, expect } from 'vitest';
|
||||||
import { toSolutionListView, toSolutionView } from './solutionMapper';
|
import { toSolutionView } from './solutionMapper';
|
||||||
|
|
||||||
/**
|
|
||||||
* 单元测试: toSolutionListView
|
|
||||||
*/
|
|
||||||
describe('toSolutionListView', () => {
|
|
||||||
const baseData: Solution = {
|
|
||||||
id: 1,
|
|
||||||
translations: [
|
|
||||||
{ id: 1, title: 'Solution Title', summary: 'Solution Summary' },
|
|
||||||
],
|
|
||||||
type: {
|
|
||||||
id: 1,
|
|
||||||
translations: [{ id: 1, name: 'Type Name' }],
|
|
||||||
sort: 1,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
test('convert raw data to SolutionListView correctly', () => {
|
|
||||||
const rawData: Solution = { ...baseData };
|
|
||||||
|
|
||||||
expect(toSolutionListView(rawData)).toEqual({
|
|
||||||
id: '1',
|
|
||||||
title: 'Solution Title',
|
|
||||||
summary: 'Solution Summary',
|
|
||||||
solution_type: {
|
|
||||||
id: '1',
|
|
||||||
name: 'Type Name',
|
|
||||||
sort: 1,
|
|
||||||
},
|
|
||||||
cover: '',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('convert raw data with missing translations', () => {
|
|
||||||
const rawData: Solution = {
|
|
||||||
...baseData,
|
|
||||||
translations: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
expect(toSolutionListView(rawData)).toEqual({
|
|
||||||
id: '1',
|
|
||||||
title: '',
|
|
||||||
summary: '',
|
|
||||||
solution_type: {
|
|
||||||
id: '1',
|
|
||||||
name: 'Type Name',
|
|
||||||
sort: 1,
|
|
||||||
},
|
|
||||||
cover: '',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单元测试: toSolutionView
|
* 单元测试: toSolutionView
|
||||||
|
|||||||
@ -1,59 +1,3 @@
|
|||||||
import { isObject } from '../../server/utils/object';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 Directus 返回的 SolutionType 数据转换为 SolutionTypeView 视图模型
|
|
||||||
*
|
|
||||||
* @param raw: 原始的 SolutionType 数据
|
|
||||||
* @returns 转换后的 SolutionTypeView 对象
|
|
||||||
*
|
|
||||||
* ---
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const view = toSolutionTypeView(rawSolutionType);
|
|
||||||
*/
|
|
||||||
export function toSolutionTypeView(raw: SolutionType): SolutionTypeView {
|
|
||||||
const trans = raw?.translations?.[0];
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: raw.id.toString(),
|
|
||||||
name: trans?.name ?? '',
|
|
||||||
sort: raw?.sort ?? 999,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 将 Directus 返回的 Solution 数据转换为 SolutionListView 视图模型
|
|
||||||
*
|
|
||||||
* @param raw: 原始的 Solution 数据
|
|
||||||
* @returns 转换后的 SolutionListView 对象
|
|
||||||
*
|
|
||||||
* ---
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const view = toSolutionListView(rawSolution);
|
|
||||||
*/
|
|
||||||
export function toSolutionListView(raw: Solution): SolutionListView {
|
|
||||||
const trans = raw.translations?.[0];
|
|
||||||
|
|
||||||
const type = isObject<SolutionType>(raw.type)
|
|
||||||
? toSolutionTypeView(raw.type)
|
|
||||||
: ({
|
|
||||||
id: '',
|
|
||||||
name: 'uncategory',
|
|
||||||
sort: 999,
|
|
||||||
} satisfies SolutionTypeView);
|
|
||||||
|
|
||||||
const cover = isObject<DirectusFile>(raw.cover) ? (raw?.cover.id ?? '') : '';
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: raw.id.toString(),
|
|
||||||
title: trans?.title ?? '',
|
|
||||||
summary: trans?.summary ?? '',
|
|
||||||
solution_type: type,
|
|
||||||
cover: cover,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 Directus 返回的 Solution 数据转换为 SolutionView 视图模型
|
* 将 Directus 返回的 Solution 数据转换为 SolutionView 视图模型
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import {
|
import { toProductView } from '~~/server/mappers/productMapper';
|
||||||
toProductView,
|
import { toProductListView } from '~~/server/mappers/productListMapper';
|
||||||
toProductListView,
|
|
||||||
} from '~~/server/mappers/productMapper';
|
|
||||||
|
|
||||||
export const productService = {
|
export const productService = {
|
||||||
async getProductList(locale: string) {
|
async getProductList(locale: string) {
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
import {
|
import { toSolutionView } from '~~/server/mappers/solutionMapper';
|
||||||
toSolutionView,
|
import { toSolutionListView } from '~~/server/mappers/solutionListMapper';
|
||||||
toSolutionListView,
|
|
||||||
} from '~~/server/mappers/solutionMapper';
|
|
||||||
|
|
||||||
export const solutionService = {
|
export const solutionService = {
|
||||||
async getSolutionList(locale: string) {
|
async getSolutionList(locale: string) {
|
||||||
|
|||||||
@ -12,13 +12,16 @@ describe('converters', () => {
|
|||||||
summary: 'High efficiency',
|
summary: 'High efficiency',
|
||||||
description: 'Detailed description',
|
description: 'Detailed description',
|
||||||
type: 'pump',
|
type: 'pump',
|
||||||
|
cover: 'rand-om__-uuid-1234',
|
||||||
};
|
};
|
||||||
const result = converters.products(item);
|
const result = converters.products(item);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
id: 1,
|
id: 1,
|
||||||
type: 'product',
|
sectionType: 'product',
|
||||||
title: 'Hydraulic Pump',
|
title: 'Hydraulic Pump',
|
||||||
summary: 'High efficiency',
|
summary: 'High efficiency',
|
||||||
|
type: 'pump',
|
||||||
|
thumbnail: '/api/assets/rand-om__-uuid-1234',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -29,13 +32,16 @@ describe('converters', () => {
|
|||||||
summary: 'Effective solution',
|
summary: 'Effective solution',
|
||||||
content: 'Detailed content',
|
content: 'Detailed content',
|
||||||
type: 'Type A',
|
type: 'Type A',
|
||||||
|
cover: 'rand-om__-uuid-5678',
|
||||||
};
|
};
|
||||||
const result = converters.solutions(item);
|
const result = converters.solutions(item);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
id: 1,
|
id: 1,
|
||||||
type: 'solution',
|
sectionType: 'solution',
|
||||||
title: 'Solution A',
|
title: 'Solution A',
|
||||||
summary: 'Effective solution',
|
summary: 'Effective solution',
|
||||||
|
type: 'Type A',
|
||||||
|
thumbnail: '/api/assets/rand-om__-uuid-5678',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -47,13 +53,15 @@ describe('converters', () => {
|
|||||||
'This is a detailed explanation of how to use the product effectively.',
|
'This is a detailed explanation of how to use the product effectively.',
|
||||||
products: ['Product A'],
|
products: ['Product A'],
|
||||||
product_types: ['Type A'],
|
product_types: ['Type A'],
|
||||||
|
type: 'Question Type',
|
||||||
};
|
};
|
||||||
const result = converters.questions(item);
|
const result = converters.questions(item);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
id: 1,
|
id: 1,
|
||||||
title: 'How to use product?',
|
title: 'How to use product?',
|
||||||
summary: '',
|
summary: undefined,
|
||||||
type: 'question',
|
type: 'Question Type',
|
||||||
|
sectionType: 'question',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -64,13 +72,15 @@ describe('converters', () => {
|
|||||||
products: ['Product A'],
|
products: ['Product A'],
|
||||||
product_types: ['Type A'],
|
product_types: ['Type A'],
|
||||||
fileUUID: 'TEST-UUID',
|
fileUUID: 'TEST-UUID',
|
||||||
|
type: 'manual',
|
||||||
};
|
};
|
||||||
const result = converters.product_documents(item);
|
const result = converters.product_documents(item);
|
||||||
expect(result).toEqual({
|
expect(result).toEqual({
|
||||||
id: 'TEST-UUID',
|
id: 'TEST-UUID',
|
||||||
title: 'User Manual',
|
title: 'User Manual',
|
||||||
summary: '',
|
summary: undefined,
|
||||||
type: 'document',
|
sectionType: 'document',
|
||||||
|
type: 'manual',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -6,31 +6,35 @@ export const converters: {
|
|||||||
} = {
|
} = {
|
||||||
products: (item: MeiliIndexMap['products']): SearchItemView => ({
|
products: (item: MeiliIndexMap['products']): SearchItemView => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
type: 'product',
|
sectionType: 'product',
|
||||||
title: item.name,
|
title: item.name,
|
||||||
summary: item.summary,
|
summary: item?.summary,
|
||||||
|
type: item?.type,
|
||||||
|
thumbnail: item?.cover ? `/api/assets/${item.cover}` : undefined,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
solutions: (item: MeiliIndexMap['solutions']): SearchItemView => ({
|
solutions: (item: MeiliIndexMap['solutions']): SearchItemView => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
type: 'solution',
|
sectionType: 'solution',
|
||||||
title: item.title,
|
title: item.title,
|
||||||
summary: item.summary,
|
summary: item?.summary,
|
||||||
|
type: item?.type,
|
||||||
|
thumbnail: item?.cover ? `/api/assets/${item.cover}` : undefined,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
questions: (item: MeiliIndexMap['questions']): SearchItemView => ({
|
questions: (item: MeiliIndexMap['questions']): SearchItemView => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
type: 'question',
|
sectionType: 'question',
|
||||||
title: item.title,
|
title: item.title,
|
||||||
summary: '',
|
type: item?.type,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
product_documents: (
|
product_documents: (
|
||||||
item: MeiliIndexMap['product_documents']
|
item: MeiliIndexMap['product_documents']
|
||||||
): SearchItemView => ({
|
): SearchItemView => ({
|
||||||
id: item.fileUUID || item.id,
|
id: item.fileUUID || item.id,
|
||||||
type: 'document',
|
sectionType: 'document',
|
||||||
title: item.title,
|
title: item.title,
|
||||||
summary: '',
|
type: item?.type,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,13 +9,16 @@ export interface MeiliProductIndex {
|
|||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
/** 产品简介 **/
|
/** 产品简介 **/
|
||||||
summary: string;
|
summary?: string;
|
||||||
|
|
||||||
/** 产品详情 **/
|
/** 产品详情 **/
|
||||||
description: string;
|
description?: string;
|
||||||
|
|
||||||
/** 产品类型 **/
|
/** 产品类型 **/
|
||||||
type: string;
|
type?: string;
|
||||||
|
|
||||||
|
/** 产品缩略图 **/
|
||||||
|
cover?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -29,13 +32,16 @@ export interface MeiliSolutionIndex {
|
|||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
/** 解决方案摘要 **/
|
/** 解决方案摘要 **/
|
||||||
summary: string;
|
summary?: string;
|
||||||
|
|
||||||
/** 解决方案内容 **/
|
/** 解决方案内容 **/
|
||||||
content: string;
|
content?: string;
|
||||||
|
|
||||||
/** 解决方案类型 **/
|
/** 解决方案类型 **/
|
||||||
type: string;
|
type?: string;
|
||||||
|
|
||||||
|
/** 解决方案缩略图 **/
|
||||||
|
cover?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -49,7 +55,10 @@ export interface MeiliQuestionIndex {
|
|||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
/** 问题内容 **/
|
/** 问题内容 **/
|
||||||
content: string;
|
content?: string;
|
||||||
|
|
||||||
|
/** 问题类型 **/
|
||||||
|
type?: string;
|
||||||
|
|
||||||
/** 相关产品 **/
|
/** 相关产品 **/
|
||||||
products: string[];
|
products: string[];
|
||||||
@ -68,6 +77,9 @@ export interface MeiliProductDocumentIndex {
|
|||||||
/** 文档标题 **/
|
/** 文档标题 **/
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
|
/** 文档类型 **/
|
||||||
|
type?: string;
|
||||||
|
|
||||||
/** 相关产品 **/
|
/** 相关产品 **/
|
||||||
products: string[];
|
products: string[];
|
||||||
|
|
||||||
|
|||||||
@ -2,9 +2,6 @@ export * from './solution-view';
|
|||||||
export * from './solution-list-view';
|
export * from './solution-list-view';
|
||||||
export * from './product-view';
|
export * from './product-view';
|
||||||
export * from './product-list-view';
|
export * from './product-list-view';
|
||||||
export * from './product-spec-group-view';
|
|
||||||
export * from './product-document-view';
|
|
||||||
export * from './product-question-view';
|
|
||||||
export * from './document-list-view';
|
export * from './document-list-view';
|
||||||
export * from './question-list-view';
|
export * from './question-list-view';
|
||||||
export * from './company-profile-view';
|
export * from './company-profile-view';
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
/**
|
|
||||||
* 文档视图模型
|
|
||||||
* 用于文档列表渲染的数据结构
|
|
||||||
*/
|
|
||||||
export interface ProductDocumentView {
|
|
||||||
/** 唯一标识符 **/
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
/** 文件UUID **/
|
|
||||||
fileId: string;
|
|
||||||
|
|
||||||
/** 文件名 **/
|
|
||||||
filename: string;
|
|
||||||
|
|
||||||
/** 文档标题 **/
|
|
||||||
title: string;
|
|
||||||
|
|
||||||
/** 文档大小 **/
|
|
||||||
size: number;
|
|
||||||
|
|
||||||
/** 文档链接 **/
|
|
||||||
url: string;
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
/**
|
|
||||||
* 常见问题视图模型
|
|
||||||
* 用于产品页常见问题渲染的数据结构
|
|
||||||
*/
|
|
||||||
export interface ProductQuestionView {
|
|
||||||
/** 唯一标识符 **/
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
/** 问题标题 **/
|
|
||||||
title: string;
|
|
||||||
|
|
||||||
/** 问题内容 **/
|
|
||||||
content: string;
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
/**
|
|
||||||
* 产品规格模型
|
|
||||||
* 用于产品规格渲染的数据结构
|
|
||||||
*/
|
|
||||||
export interface ProductSpecView {
|
|
||||||
/** 唯一标识符 **/
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
/** 规格名称 **/
|
|
||||||
key: string;
|
|
||||||
|
|
||||||
/** 规格值 **/
|
|
||||||
value: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 产品规格表模型
|
|
||||||
* 用于产品规格表渲染的数据结构
|
|
||||||
*/
|
|
||||||
export interface ProductSpecGroupView {
|
|
||||||
/** 唯一标识符 **/
|
|
||||||
id: string;
|
|
||||||
|
|
||||||
/** 规格组名称 **/
|
|
||||||
name: string;
|
|
||||||
|
|
||||||
/** 规格组 **/
|
|
||||||
specs: ProductSpecView[];
|
|
||||||
}
|
|
||||||
@ -1,13 +1,90 @@
|
|||||||
import type { ProductSpecGroupView } from './product-spec-group-view';
|
import type { DocumentTypeView } from './document-list-view';
|
||||||
import type { ProductQuestionView } from './product-question-view';
|
import type { Product } from '../directus/my-schema.ts';
|
||||||
import type { ProductDocumentView } from './product-document-view';
|
|
||||||
|
|
||||||
interface ImageView {
|
type ProductStatus = Product['status'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品图片视图模型
|
||||||
|
* 用于产品详情页(/products/[slug])中的产品图片数据结构
|
||||||
|
*/
|
||||||
|
export interface ProductImageView {
|
||||||
id: string;
|
id: string;
|
||||||
image: string;
|
image: string;
|
||||||
caption: string;
|
caption: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品规格模型
|
||||||
|
* 用于产品规格渲染的数据结构
|
||||||
|
*/
|
||||||
|
export interface ProductSpecView {
|
||||||
|
/** 唯一标识符 **/
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
/** 规格名称 **/
|
||||||
|
key: string;
|
||||||
|
|
||||||
|
/** 规格值 **/
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 产品规格表模型
|
||||||
|
* 用于产品规格表渲染的数据结构
|
||||||
|
*/
|
||||||
|
export interface ProductSpecGroupView {
|
||||||
|
/** 唯一标识符 **/
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
/** 规格组名称 **/
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
/** 规格组 **/
|
||||||
|
specs: ProductSpecView[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常见问题视图模型
|
||||||
|
* 用于产品页常见问题渲染的数据结构
|
||||||
|
*/
|
||||||
|
export interface ProductQuestionView {
|
||||||
|
/** 唯一标识符 **/
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
/** 问题标题 **/
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
/** 问题内容 **/
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文档视图模型
|
||||||
|
* 用于文档列表渲染的数据结构
|
||||||
|
*/
|
||||||
|
export interface ProductDocumentView {
|
||||||
|
/** 唯一标识符 **/
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
/** 文件UUID **/
|
||||||
|
fileId: string;
|
||||||
|
|
||||||
|
/** 文件名 **/
|
||||||
|
filename: string;
|
||||||
|
|
||||||
|
/** 文档标题 **/
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
/** 文档大小 **/
|
||||||
|
size: number;
|
||||||
|
|
||||||
|
/** 文档类型 **/
|
||||||
|
type: DocumentTypeView;
|
||||||
|
|
||||||
|
/** 文档链接 **/
|
||||||
|
url: string;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 产品视图模型
|
* 产品视图模型
|
||||||
* 用于产品详情页(/products/[slug])渲染的数据结构
|
* 用于产品详情页(/products/[slug])渲染的数据结构
|
||||||
@ -16,17 +93,17 @@ export interface ProductView {
|
|||||||
/** 唯一标识符 **/
|
/** 唯一标识符 **/
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
|
/** 产品状态 **/
|
||||||
|
status: ProductStatus;
|
||||||
|
|
||||||
/** 产品名称 **/
|
/** 产品名称 **/
|
||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
/** 产品简介 **/
|
/** 产品简介 **/
|
||||||
summary: string;
|
summary: string;
|
||||||
|
|
||||||
/** 产品类型 **/
|
|
||||||
product_type: string;
|
|
||||||
|
|
||||||
/** 产品图片 **/
|
/** 产品图片 **/
|
||||||
images: ImageView[];
|
images: ProductImageView[];
|
||||||
|
|
||||||
/** 产品详情 **/
|
/** 产品详情 **/
|
||||||
description: string;
|
description: string;
|
||||||
|
|||||||
@ -3,11 +3,17 @@ export interface SearchItemView {
|
|||||||
id: number | string;
|
id: number | string;
|
||||||
|
|
||||||
/** 条目类型 **/
|
/** 条目类型 **/
|
||||||
type: 'product' | 'solution' | 'question' | 'document';
|
sectionType: 'product' | 'solution' | 'question' | 'document';
|
||||||
|
|
||||||
/** 条目标题 **/
|
/** 条目标题 **/
|
||||||
title: string;
|
title: string;
|
||||||
|
|
||||||
/** 条目摘要 **/
|
/** 条目摘要 **/
|
||||||
summary: string;
|
summary?: string;
|
||||||
|
|
||||||
|
/** 条目分类 **/
|
||||||
|
type?: string;
|
||||||
|
|
||||||
|
/** 条目预览图 **/
|
||||||
|
thumbnail?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user