Compare commits
40 Commits
51042c395a
...
feat/icp
| Author | SHA1 | Date | |
|---|---|---|---|
| ef20832761 | |||
| 03a692afb5 | |||
| 7b21def74f | |||
| 783d482e0a | |||
| 62ec215340 | |||
| e02f975217 | |||
| 5530776035 | |||
| 63cdff9c41 | |||
| f1398a5545 | |||
| 36d24a4740 | |||
| c9b5b1fad9 | |||
| 246a0b9d4f | |||
| c3ac7c0985 | |||
| 63c3e2e364 | |||
| 1245df497b | |||
| f081a3b33a | |||
| 3c6bff4d31 | |||
| 5011448902 | |||
| 53f3e99d90 | |||
| 815df40745 | |||
| c27337a145 | |||
| 3fb721f278 | |||
| a4dc28fc97 | |||
| 55a35b5498 | |||
| f4ec82a150 | |||
| c82fea48b8 | |||
| 39a23fb382 | |||
| 871b203a5e | |||
| b746247ccc | |||
| 97069815dc | |||
| 5194c72695 | |||
| dbe75ee080 | |||
| 4471851c62 | |||
| 15a75f965b | |||
| 5a4cef52be | |||
| 30ffc7e557 | |||
| c4b9ed7bae | |||
| fc6c922ac3 | |||
| 54389b32ac | |||
| d8002a8265 |
@ -38,6 +38,10 @@
|
||||
<div class="product-info">
|
||||
<h1>{{ product.name }}</h1>
|
||||
<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>
|
||||
</template>
|
||||
@ -105,6 +109,10 @@
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.discontinued-warning {
|
||||
color: var(--el-color-error);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.product-header {
|
||||
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">
|
||||
<NuxtLink
|
||||
v-for="hit in paginatedHits"
|
||||
:key="`${hit.type}-${hit.id}`"
|
||||
:key="`${hit.sectionType}-${hit.id}`"
|
||||
:to="localePath(resolveHitLink(hit))"
|
||||
>
|
||||
<el-card class="result-card">
|
||||
<h3 class="result-title">{{ hit.title }}</h3>
|
||||
<p v-if="hit.summary" class="result-summary">
|
||||
{{ hit.summary }}
|
||||
</p>
|
||||
<p v-if="hit.type" class="result-type">
|
||||
<span>内容类型: </span>
|
||||
<span class="result-type-name">{{ getIndexLabel(hit.type) }}</span>
|
||||
</p>
|
||||
</el-card>
|
||||
<search-result-card
|
||||
:item="hit"
|
||||
:type-label="getIndexLabel(hit.sectionType)"
|
||||
/>
|
||||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
@ -72,7 +66,7 @@
|
||||
const items = props.searchItems;
|
||||
const filteredHits = computed(() => {
|
||||
if (props.category) {
|
||||
return items.filter((item) => item.type === props.category);
|
||||
return items.filter((item) => item.sectionType === props.category);
|
||||
} else {
|
||||
return items;
|
||||
}
|
||||
@ -116,19 +110,19 @@
|
||||
|
||||
const slug = String(slugCandidate);
|
||||
|
||||
if (item.type === 'product') {
|
||||
if (item.sectionType === 'product') {
|
||||
return localePath({ path: `/products/${slug}` });
|
||||
}
|
||||
|
||||
if (item.type === 'solution') {
|
||||
if (item.sectionType === 'solution') {
|
||||
return localePath({ path: `/solutions/${slug}` });
|
||||
}
|
||||
|
||||
if (item.type === 'document') {
|
||||
if (item.sectionType === 'document') {
|
||||
return localePath({ path: `/download/${slug}` });
|
||||
}
|
||||
|
||||
if (item.type === 'question') {
|
||||
if (item.sectionType === 'question') {
|
||||
return localePath({ path: `/support/faq`, query: { focus: slug } });
|
||||
}
|
||||
|
||||
|
||||
@ -22,17 +22,17 @@
|
||||
}>();
|
||||
|
||||
const tabs = [
|
||||
{ name: 'all', label: '全部' },
|
||||
{ name: 'product', label: '产品' },
|
||||
{ name: 'solution', label: '解决方案' },
|
||||
{ name: 'question', label: '相关问题' },
|
||||
{ name: 'document', label: '文档资料' },
|
||||
{ name: 'all', label: $t('all') },
|
||||
{ name: 'product', label: $t('search.sections.product') },
|
||||
{ name: 'solution', label: $t('search.sections.solution') },
|
||||
{ name: 'question', label: $t('search.sections.faq') },
|
||||
{ name: 'document', label: $t('search.sections.document') },
|
||||
];
|
||||
|
||||
const resultCount = computed(() => {
|
||||
const map: Record<string, number> = { all: props.searchItems.length };
|
||||
for (const item of props.searchItems) {
|
||||
map[item.type] = (map[item.type] ?? 0) + 1;
|
||||
map[item.sectionType] = (map[item.sectionType] ?? 0) + 1;
|
||||
}
|
||||
return map;
|
||||
});
|
||||
|
||||
113
app/components/pages/support/DocumentFilter.vue
Normal file
113
app/components/pages/support/DocumentFilter.vue
Normal file
@ -0,0 +1,113 @@
|
||||
<template>
|
||||
<div class="document-category">
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12" :xs="12">
|
||||
<span class="select-label">{{
|
||||
$t('product-filter.product-type')
|
||||
}}</span>
|
||||
<el-select
|
||||
v-model="model.selectedProductType"
|
||||
:placeholder="$t('product-filter.select-product-type')"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="type in productTypeOptions"
|
||||
:key="type.id"
|
||||
:label="type.name"
|
||||
:value="type.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" :xs="12">
|
||||
<span class="select-label">{{
|
||||
$t('product-filter.product-model')
|
||||
}}</span>
|
||||
<el-select
|
||||
v-model="model.selectedProduct"
|
||||
:placeholder="$t('product-filter.select-product-model')"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="product in productOptions"
|
||||
:key="product.id"
|
||||
:label="product.name"
|
||||
:value="product.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" :xs="24">
|
||||
<span class="select-label">
|
||||
{{ $t('product-filter.document-type') }}
|
||||
</span>
|
||||
<el-select
|
||||
v-model="model.selectedDocumentType"
|
||||
:placeholder="$t('product-filter.select-document-type')"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="questionType in documentTypeOptions"
|
||||
:key="questionType.id"
|
||||
:label="questionType.name"
|
||||
:value="questionType.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" :xs="24">
|
||||
<span class="select-label">{{ $t('product-filter.keyword') }}</span>
|
||||
<el-input
|
||||
v-model="model.keyword"
|
||||
:placeholder="$t('product-filter.enter-keyword')"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Search } from '@element-plus/icons-vue';
|
||||
|
||||
defineProps({
|
||||
productTypeOptions: {
|
||||
type: Array as () => Array<DocumentListProductType>,
|
||||
default: () => [],
|
||||
},
|
||||
productOptions: {
|
||||
type: Array as () => Array<DocumentListProduct>,
|
||||
default: () => [],
|
||||
},
|
||||
documentTypeOptions: {
|
||||
type: Array as () => Array<DocumentTypeView>,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const model = defineModel<{
|
||||
selectedProduct: string | null;
|
||||
selectedProductType: string | null;
|
||||
selectedDocumentType: string | null;
|
||||
keyword: string;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.document-category {
|
||||
margin-bottom: 1rem;
|
||||
padding: 0 0;
|
||||
}
|
||||
|
||||
.select-label {
|
||||
color: var(--el-text-color-secondary);
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
:deep(.el-select__wrapper),
|
||||
:deep(.el-input__wrapper) {
|
||||
height: 40px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
</style>
|
||||
@ -1,12 +1,12 @@
|
||||
<template>
|
||||
<div class="question-category">
|
||||
<el-row class="hide-on-mobile" :gutter="12">
|
||||
<el-col :span="8">
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="12" :xs="12">
|
||||
<span class="select-label">{{
|
||||
$t('product-filter.product-type')
|
||||
}}</span>
|
||||
<el-select
|
||||
v-model="model.selectedType"
|
||||
v-model="model.selectedProductType"
|
||||
:placeholder="$t('product-filter.select-product-type')"
|
||||
clearable
|
||||
>
|
||||
@ -19,7 +19,7 @@
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="8">
|
||||
<el-col :span="12" :xs="12">
|
||||
<span class="select-label">{{
|
||||
$t('product-filter.product-model')
|
||||
}}</span>
|
||||
@ -37,7 +37,25 @@
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="8">
|
||||
<el-col :span="12" :xs="24">
|
||||
<span class="select-label">
|
||||
{{ $t('product-filter.question-type') }}
|
||||
</span>
|
||||
<el-select
|
||||
v-model="model.selectedQuestionType"
|
||||
:placeholder="$t('product-filter.select-question-type')"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="questionType in questionTypeOptions"
|
||||
:key="questionType.id"
|
||||
:label="questionType.name"
|
||||
:value="questionType.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12" :xs="24">
|
||||
<span class="select-label">{{ $t('product-filter.keyword') }}</span>
|
||||
<el-input
|
||||
v-model="model.keyword"
|
||||
@ -47,52 +65,6 @@
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row class="display-on-mobile" :gutter="12">
|
||||
<el-col :span="12">
|
||||
<span class="select-label">{{
|
||||
$t('product-filter.product-type')
|
||||
}}</span>
|
||||
<el-select
|
||||
v-model="model.selectedType"
|
||||
:placeholder="$t('product-filter.select-product-type')"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="type in productTypeOptions"
|
||||
:key="type.id"
|
||||
:label="type.name"
|
||||
:value="type.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<span class="select-label">{{
|
||||
$t('product-filter.product-model')
|
||||
}}</span>
|
||||
<el-select
|
||||
v-model="model.selectedProduct"
|
||||
:placeholder="$t('product-filter.select-product-model')"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="product in productOptions"
|
||||
:key="product.id"
|
||||
:label="product.name"
|
||||
:value="product.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row class="display-on-mobile">
|
||||
<span class="select-label">{{ $t('product-filter.keyword') }}</span>
|
||||
<el-input
|
||||
v-model="model.keyword"
|
||||
:placeholder="$t('product-filter.enter-keyword')"
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
/>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -101,19 +73,24 @@
|
||||
|
||||
defineProps({
|
||||
productTypeOptions: {
|
||||
type: Array as () => Array<{ id: number; name: string }>,
|
||||
type: Array as () => Array<QuestionListProductType>,
|
||||
default: () => [],
|
||||
},
|
||||
productOptions: {
|
||||
type: Array as () => Array<{ id: number; name: string }>,
|
||||
type: Array as () => Array<QuestionListProduct>,
|
||||
default: () => [],
|
||||
},
|
||||
questionTypeOptions: {
|
||||
type: Array as () => Array<QuestionTypeView>,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const model = defineModel<{
|
||||
selectedProduct: string | null;
|
||||
selectedProductType: string | null;
|
||||
selectedQuestionType: string | null;
|
||||
keyword: string;
|
||||
selectedType: number | null;
|
||||
selectedProduct: number | null;
|
||||
}>();
|
||||
</script>
|
||||
|
||||
@ -132,18 +109,4 @@
|
||||
height: 40px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.display-on-mobile {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.hide-on-mobile {
|
||||
display: none;
|
||||
}
|
||||
.display-on-mobile {
|
||||
display: flex;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -7,7 +7,17 @@
|
||||
@click="handleClick(doc.fileId)"
|
||||
>
|
||||
<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">
|
||||
<span v-if="doc.size" class="document-meta"
|
||||
>{{ $t('document-meta.size') }}: {{ formatFileSize(doc.size) }}
|
||||
@ -28,6 +38,10 @@
|
||||
type: Array as () => Array<ProductDocumentView>,
|
||||
default: () => [],
|
||||
},
|
||||
showCategory: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
});
|
||||
|
||||
const localePath = useLocalePath();
|
||||
@ -63,6 +77,15 @@
|
||||
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 {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@
|
||||
<ul class="footer-links">
|
||||
<li>
|
||||
<a
|
||||
href="http://cal.jinshen.cn"
|
||||
href="http://cal.3w.jinshen.cn"
|
||||
target="_blank"
|
||||
rel="noopener noreferer"
|
||||
>
|
||||
@ -84,7 +84,12 @@
|
||||
© {{ currentYear }} {{ $t('company-name') }}.
|
||||
{{ $t('all-rights-reserved') }}
|
||||
</p>
|
||||
<p>备案号: 浙ICP备12003709号-5</p>
|
||||
<p>
|
||||
备案号:
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank"
|
||||
>浙ICP备12003709号-5</a
|
||||
>
|
||||
</p>
|
||||
</div>
|
||||
<!-- <div class="footer-links-bottom"> -->
|
||||
<!-- <NuxtLink :to="$localePath('/privacy')">{{ -->
|
||||
|
||||
@ -53,7 +53,7 @@
|
||||
class="hide-on-mobile"
|
||||
type="info"
|
||||
:underline="false"
|
||||
href="http://cal.jinshen.cn"
|
||||
href="http://cal.3w.jinshen.cn"
|
||||
target="_blank"
|
||||
>
|
||||
<el-icon class="mdi mdi-calculator action-icon" />
|
||||
@ -67,6 +67,12 @@
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh">简体中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en">English</el-dropdown-item>
|
||||
<el-dropdown-item command="es"
|
||||
>Español(Machine Translate)</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item command="ru"
|
||||
>Русский(Machine Translate)</el-dropdown-item
|
||||
>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
@ -125,7 +131,9 @@
|
||||
mode="vertical"
|
||||
@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') }}
|
||||
</el-menu-item>
|
||||
</el-menu>
|
||||
@ -140,6 +148,12 @@
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item command="zh">简体中文</el-dropdown-item>
|
||||
<el-dropdown-item command="en">English</el-dropdown-item>
|
||||
<el-dropdown-item command="es"
|
||||
>Español(Machine Translate)</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item command="ru"
|
||||
>Русский(Machine Translate)</el-dropdown-item
|
||||
>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import type { Language as ElementLanguage } from 'element-plus/es/locale';
|
||||
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
||||
import en from 'element-plus/es/locale/lang/en';
|
||||
import es from 'element-plus/es/locale/lang/es';
|
||||
import ru from 'element-plus/es/locale/lang/ru';
|
||||
|
||||
/**
|
||||
* 应用语言映射结构
|
||||
@ -28,6 +30,14 @@ export const localeMap = {
|
||||
directus: 'en-US',
|
||||
element: en,
|
||||
},
|
||||
es: {
|
||||
directus: 'es-ES',
|
||||
element: es,
|
||||
},
|
||||
ru: {
|
||||
directus: 'ru-RU',
|
||||
element: ru,
|
||||
},
|
||||
} satisfies Record<string, LocaleMapping>;
|
||||
|
||||
/** 应用支持的语言键类型 **/
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
<learn-more-card
|
||||
:title="$t('navigation.address')"
|
||||
:icon="ElIconMapLocation"
|
||||
:to="$localePath('/locate?lng=120.123&lat=30.231&name=xxx')"
|
||||
@click="openMap"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@ -44,6 +44,10 @@
|
||||
];
|
||||
const { data: companyProfile, pending, error } = await useCompanyProfile();
|
||||
|
||||
const openMap = () => {
|
||||
window.open(localePath('/locate'));
|
||||
};
|
||||
|
||||
watch(error, (value) => {
|
||||
if (value) {
|
||||
logger.error('数据获取失败: ', value);
|
||||
|
||||
@ -53,8 +53,8 @@
|
||||
|
||||
// SEO
|
||||
usePageSeo({
|
||||
title: product.value.name || $t('page-title.products'),
|
||||
description: product.value.summary || '',
|
||||
title: product.value?.name || $t('page-title.products'),
|
||||
description: product.value?.summary || '',
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<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" />
|
||||
</div>
|
||||
<div v-if="!pending" class="page-content">
|
||||
@ -102,13 +108,18 @@
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 2rem;
|
||||
font-weight: bold;
|
||||
color: var(--el-color-primary);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.page-subtitle {
|
||||
font-size: 0.8rem;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.breadcrumb {
|
||||
|
||||
@ -44,8 +44,8 @@
|
||||
});
|
||||
|
||||
usePageSeo({
|
||||
title: solution.value.title || $t('page-title.solutions'),
|
||||
description: solution.value.summary || '',
|
||||
title: solution.value?.title || $t('page-title.solutions'),
|
||||
description: solution.value?.summary || '',
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
<template>
|
||||
<div class="page-container">
|
||||
<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" />
|
||||
</div>
|
||||
<div v-if="!pending" class="solutions-container">
|
||||
@ -94,15 +98,20 @@
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 2rem;
|
||||
font-weight: bold;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--el-color-primary);
|
||||
}
|
||||
|
||||
.page-subtitle {
|
||||
font-size: 0.8rem;
|
||||
color: var(--el-text-color-secondary);
|
||||
}
|
||||
|
||||
.breadcrumb {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
@ -10,12 +10,29 @@
|
||||
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
|
||||
</div>
|
||||
<div class="page-content">
|
||||
<product-filter
|
||||
<document-filter
|
||||
v-model="filters"
|
||||
:product-type-options="productTypeOptions"
|
||||
:product-options="productOptions"
|
||||
:document-type-options="documentTypeOptions"
|
||||
/>
|
||||
|
||||
<document-list
|
||||
:documents="paginatedDocuments"
|
||||
:show-category="
|
||||
filters.selectedDocumentType === null ||
|
||||
filters.selectedDocumentType === undefined
|
||||
"
|
||||
/>
|
||||
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
class="justify-center pagination-container"
|
||||
layout="prev, pager, next"
|
||||
hide-on-single-page
|
||||
:page-size="documentsPerPage"
|
||||
:total="filteredDocuments.length"
|
||||
/>
|
||||
<document-list :documents="filteredDocuments" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -30,13 +47,35 @@
|
||||
];
|
||||
|
||||
const filters = reactive({
|
||||
selectedType: null as number | null,
|
||||
selectedProduct: null as number | null,
|
||||
selectedDocumentType: null as string | null,
|
||||
selectedProductType: null as string | null,
|
||||
selectedProduct: null as string | null,
|
||||
keyword: '',
|
||||
});
|
||||
|
||||
const page = ref(1);
|
||||
const documentsPerPage = 10;
|
||||
|
||||
const { data: documents, pending, error } = await useDocumentList();
|
||||
|
||||
const documentTypeOptions = computed(() => {
|
||||
const types: DocumentTypeView[] = [];
|
||||
documents.value.forEach((doc: DocumentListView) => {
|
||||
if (!types.some((item) => item.id === doc.type.id)) {
|
||||
if (doc.type.id === '-1') {
|
||||
types.push({
|
||||
id: '-1',
|
||||
name: $t('product-filter.misc'),
|
||||
});
|
||||
} else {
|
||||
types.push(doc.type);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return types;
|
||||
});
|
||||
|
||||
const productTypeOptions = computed(() => {
|
||||
const types: DocumentListProductType[] = [];
|
||||
documents.value.forEach((doc: DocumentListView) => {
|
||||
@ -52,13 +91,13 @@
|
||||
});
|
||||
|
||||
const productOptions = computed(() => {
|
||||
if (!filters.selectedType) return [];
|
||||
if (!filters.selectedProductType) return [];
|
||||
const products: DocumentListProduct[] = [];
|
||||
|
||||
documents.value.forEach((doc: DocumentListView) => {
|
||||
doc.products?.forEach((product: DocumentListProduct) => {
|
||||
if (
|
||||
product.type.id === filters.selectedType &&
|
||||
product.type.id === filters.selectedProductType &&
|
||||
!products.some((item) => item.id === product.id)
|
||||
) {
|
||||
products.push(product);
|
||||
@ -81,19 +120,30 @@
|
||||
(product: DocumentListProduct) =>
|
||||
product.id === filters.selectedProduct
|
||||
)
|
||||
: filters.selectedType
|
||||
: filters.selectedProductType
|
||||
? doc.products?.some(
|
||||
(product: DocumentListProduct) =>
|
||||
product.type?.id === filters.selectedType
|
||||
product.type?.id === filters.selectedProductType
|
||||
)
|
||||
: true;
|
||||
|
||||
return matchProduct;
|
||||
const matchDocumentType = filters.selectedDocumentType
|
||||
? doc.type.id === filters.selectedDocumentType
|
||||
: true;
|
||||
|
||||
return matchProduct && matchDocumentType;
|
||||
});
|
||||
});
|
||||
|
||||
const paginatedDocuments = computed(() => {
|
||||
return filteredDocuments.value.slice(
|
||||
(page.value - 1) * documentsPerPage,
|
||||
page.value * documentsPerPage
|
||||
);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => filters.selectedType,
|
||||
() => filters.selectedProductType,
|
||||
() => {
|
||||
filters.selectedProduct = null;
|
||||
}
|
||||
@ -133,12 +183,6 @@
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.document-category {
|
||||
padding: 0rem 2rem;
|
||||
gap: 4px;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.page-content {
|
||||
padding: 1rem 2rem 2rem;
|
||||
}
|
||||
@ -153,4 +197,35 @@
|
||||
height: 40px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
:deep(.el-pagination) {
|
||||
.btn-prev,
|
||||
.btn-next {
|
||||
.el-icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-pager {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.el-pager li {
|
||||
font-size: 1rem;
|
||||
/* border: 1px solid #409eff; */
|
||||
border-radius: 50%;
|
||||
|
||||
&:hover {
|
||||
background-color: #ecf5ff;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
background-color: var(--el-color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -11,13 +11,23 @@
|
||||
</div>
|
||||
|
||||
<div class="page-content">
|
||||
<product-filter
|
||||
<question-filter
|
||||
v-model="filters"
|
||||
:product-type-options="productTypeOptions"
|
||||
:product-options="productOptions"
|
||||
:question-type-options="questionTypeOptions"
|
||||
/>
|
||||
|
||||
<question-list :questions="filteredQuestions" />
|
||||
<question-list :questions="paginatedQuestions" />
|
||||
|
||||
<el-pagination
|
||||
v-model:current-page="page"
|
||||
class="justify-center pagination-container"
|
||||
layout="prev, pager, next"
|
||||
hide-on-single-page
|
||||
:page-size="questionsPerPage"
|
||||
:total="filteredQuestions.length"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -25,13 +35,22 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
const localePath = useLocalePath();
|
||||
const route = useRoute();
|
||||
|
||||
const filters = reactive({
|
||||
selectedType: null as number | null,
|
||||
selectedProduct: null as number | null,
|
||||
selectedQuestionType: null as string | null,
|
||||
selectedProduct: null as string | null,
|
||||
selectedProductType: null as string | null,
|
||||
keyword: '',
|
||||
});
|
||||
|
||||
const page = ref(1);
|
||||
const questionsPerPage = 10;
|
||||
|
||||
const focusQuestionId = ref<string | null>(
|
||||
route.query.focus as string | null
|
||||
);
|
||||
|
||||
const breadcrumbItems = [
|
||||
{ label: $t('navigation.home'), to: localePath('/') },
|
||||
{ label: $t('navigation.support'), to: localePath('/support') },
|
||||
@ -40,6 +59,23 @@
|
||||
|
||||
const { data: questions, pending, error } = await useQuestionList();
|
||||
|
||||
const questionTypeOptions = computed(() => {
|
||||
const types: QuestionTypeView[] = [];
|
||||
questions.value.forEach((q: QuestionListView) => {
|
||||
if (!types.some((t) => t.id === q.type.id)) {
|
||||
if (q.type.id === '-1') {
|
||||
types.push({
|
||||
id: '-1',
|
||||
name: $t('product-filter.misc'),
|
||||
});
|
||||
} else {
|
||||
types.push(q.type);
|
||||
}
|
||||
}
|
||||
});
|
||||
return types;
|
||||
});
|
||||
|
||||
const productTypeOptions = computed(() => {
|
||||
const types: QuestionListProductType[] = [];
|
||||
questions.value.forEach((q: QuestionListView) => {
|
||||
@ -54,12 +90,12 @@
|
||||
});
|
||||
|
||||
const productOptions = computed(() => {
|
||||
if (!filters.selectedType) return [];
|
||||
if (!filters.selectedProductType) return [];
|
||||
const products: QuestionListProduct[] = [];
|
||||
questions.value.forEach((q: QuestionListView) => {
|
||||
q.products.forEach((product: QuestionListProduct) => {
|
||||
if (
|
||||
product.type.id === filters.selectedType &&
|
||||
product.type.id === filters.selectedProductType &&
|
||||
!products.some((p) => p.id === product.id)
|
||||
) {
|
||||
products.push(product);
|
||||
@ -81,19 +117,51 @@
|
||||
(product: QuestionListProduct) =>
|
||||
product.id === filters.selectedProduct
|
||||
)
|
||||
: filters.selectedType
|
||||
: filters.selectedProductType
|
||||
? question.products?.some(
|
||||
(product: QuestionListProduct) =>
|
||||
product.type.id === filters.selectedType
|
||||
product.type.id === filters.selectedProductType
|
||||
)
|
||||
: true;
|
||||
|
||||
return matchProduct;
|
||||
const matchQuestionType = filters.selectedQuestionType
|
||||
? question.type.id === filters.selectedQuestionType
|
||||
: true;
|
||||
|
||||
return matchProduct && matchQuestionType;
|
||||
});
|
||||
});
|
||||
|
||||
const paginatedQuestions = computed(() => {
|
||||
const start = (page.value - 1) * questionsPerPage;
|
||||
const end = page.value * questionsPerPage;
|
||||
return filteredQuestions.value.slice(start, end);
|
||||
});
|
||||
|
||||
watch(
|
||||
() => filters.selectedType,
|
||||
focusQuestionId,
|
||||
async (focusId) => {
|
||||
if (!focusId) return;
|
||||
if (!import.meta.client) return;
|
||||
|
||||
await nextTick();
|
||||
|
||||
const question = filteredQuestions.value.find((q) => q.id === focusId);
|
||||
if (!question) return;
|
||||
|
||||
const targetIndex = filteredQuestions.value.indexOf(question);
|
||||
const targetPage = Math.floor(targetIndex / questionsPerPage) + 1;
|
||||
onMounted(() => {
|
||||
if (page.value !== targetPage) {
|
||||
page.value = targetPage;
|
||||
}
|
||||
});
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
watch(
|
||||
() => filters.selectedProductType,
|
||||
() => {
|
||||
filters.selectedProduct = null;
|
||||
}
|
||||
@ -136,4 +204,34 @@
|
||||
.page-content {
|
||||
padding: 1rem 2rem 2rem;
|
||||
}
|
||||
.pagination-container {
|
||||
margin-top: 2rem;
|
||||
}
|
||||
|
||||
:deep(.el-pagination) {
|
||||
.btn-prev,
|
||||
.btn-next {
|
||||
.el-icon {
|
||||
font-size: 24px;
|
||||
}
|
||||
}
|
||||
|
||||
.el-pager {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
.el-pager li {
|
||||
font-size: 1rem;
|
||||
/* border: 1px solid #409eff; */
|
||||
border-radius: 50%;
|
||||
|
||||
&:hover {
|
||||
background-color: #ecf5ff;
|
||||
}
|
||||
|
||||
&.is-active {
|
||||
background-color: var(--el-color-primary);
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
"result-count": "{count} results",
|
||||
"no-results": "No results found for \"{query}\".",
|
||||
"no-query": "Enter a keyword to start searching.",
|
||||
"section": "Section",
|
||||
"untitled": "Untitled",
|
||||
"sections": {
|
||||
"product": "Products",
|
||||
@ -22,8 +23,8 @@
|
||||
"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.",
|
||||
"learn-more": "Learn More",
|
||||
"products-desc": "We provide high-quality product solutions to meet various business needs.",
|
||||
"solutions-desc": "Providing customized technology solutions for enterprises to accelerate digital transformation.",
|
||||
"products-desc": "We provide the latest products an instant service support to meet various business needs of our customers.",
|
||||
"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.",
|
||||
"quick-links": "Quick Links",
|
||||
"utilities": "Utilities",
|
||||
@ -62,7 +63,9 @@
|
||||
"back-to-home": "Back to Home",
|
||||
"no-content-available": "No detailed information available",
|
||||
"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",
|
||||
"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.",
|
||||
@ -78,7 +81,12 @@
|
||||
"keyword": "Keyword",
|
||||
"select-product-type": "Select product type",
|
||||
"select-product-model": "Select product model",
|
||||
"enter-keyword": "Enter keyword"
|
||||
"enter-keyword": "Enter keyword",
|
||||
"question-type": "Question Type",
|
||||
"select-question-type": "Select question type",
|
||||
"document-type": "Document Type",
|
||||
"select-document-type": "Select document type",
|
||||
"misc": "Misc"
|
||||
},
|
||||
"document-meta": {
|
||||
"size": "Size",
|
||||
|
||||
130
i18n/locales/es.json
Normal file
130
i18n/locales/es.json
Normal file
@ -0,0 +1,130 @@
|
||||
{
|
||||
"back": "Volver",
|
||||
"not-found": "Página no encontrada",
|
||||
"search-placeholder": "Buscar...",
|
||||
"search": {
|
||||
"title": "Búsqueda en el sitio",
|
||||
"head-title": "Búsqueda",
|
||||
"search-button": "Buscar",
|
||||
"results-for": "Resultados de la búsqueda para \"{query}\"",
|
||||
"result-count": "{count} resultados",
|
||||
"no-results": "No se encontraron coincidencias para \"{query}\".",
|
||||
"no-query": "Ingrese una palabra clave para comenzar a buscar.",
|
||||
"section": "sección",
|
||||
"untitled": "sin título",
|
||||
"sections": {
|
||||
"product": "Productos",
|
||||
"solution": "Soluciones",
|
||||
"faq": "FAQ",
|
||||
"document": "Documentaciones",
|
||||
"default": "Otros contenidos"
|
||||
}
|
||||
},
|
||||
"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.",
|
||||
"learn-more": "Saber más",
|
||||
"products-desc": "Ofrecemos los últimos productos y un servicio de asistencia instantáneo para satisfacer las diversas necesidades comerciales de nuestros clientes.",
|
||||
"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.",
|
||||
"quick-links": "Enlaces rápidos",
|
||||
"utilities": "Herramientas útiles",
|
||||
"navigation": {
|
||||
"home": "Inicio",
|
||||
"products": "Productos",
|
||||
"solutions": "Soluciones",
|
||||
"support": "Soporte",
|
||||
"about-us": "Sobre nosotros",
|
||||
"contact-info": "Información de contacto",
|
||||
"downloads": "Descargas",
|
||||
"faq": "FAQ",
|
||||
"documents": "Documentaciones",
|
||||
"calculator": "Herramienta de cálculo de tubos de papel",
|
||||
"address": "Dirección de la empresa"
|
||||
},
|
||||
"contact-info": "Contáctenos",
|
||||
"telephone": "Teléfono",
|
||||
"email": "Correo electrónico",
|
||||
"address": "Dirección",
|
||||
"company-address": "No. 689 Qiushi Road, Wutong Industrial Zone, Tongxiang City, Zhejiang Province, China",
|
||||
"follow-us": "Síguenos",
|
||||
"all-rights-reserved": "All rights reserved",
|
||||
"privacy-policy": "Política de privacidad",
|
||||
"terms-of-service": "Términos del servicio",
|
||||
"sitemap": "Mapa del sitio",
|
||||
"product-details": "Detalles del producto",
|
||||
"product-not-found": "Producto no encontrado",
|
||||
"product-not-found-desc": "Lo sentimos, el producto que busca no existe o ha sido eliminado.",
|
||||
"back-to-products": "Volver a la lista de productos",
|
||||
"solution-not-found": "Solución no encontrada",
|
||||
"solution-not-found-desc": "Lo sentimos, la solución que busca no existe o ha sido eliminada.",
|
||||
"back-to-solutions": "Volver a la lista de soluciones",
|
||||
"page-not-found": "Página no encontrada",
|
||||
"page-not-found-desc": "Lo sentimos, la página que busca no existe o ha sido eliminada.",
|
||||
"back-to-home": "Volver al inicio",
|
||||
"no-content-available": "No hay información disponible",
|
||||
"loading": "Cargando...",
|
||||
"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",
|
||||
"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-card-desc": {
|
||||
"faq": "Hemos compilado respuestas a preguntas frecuentes para ayudarle a resolver dudas rápidamente.",
|
||||
"documents": "Proporcionamos manuales de productos, especificaciones técnicas y otros documentos para la comodidad del usuario.",
|
||||
"contact-info": "Contáctenos por teléfono o correo electrónico, y le brindaremos servicio presencial."
|
||||
},
|
||||
"product-filter": {
|
||||
"product-type": "Tipo de producto",
|
||||
"product-model": "Modelo del producto",
|
||||
"keyword": "Palabra clave",
|
||||
"select-product-type": "Seleccione el tipo de producto",
|
||||
"select-product-model": "Seleccione modelo de producto",
|
||||
"enter-keyword": "Ingrese palabra clave",
|
||||
"misc": "Varios",
|
||||
"document-type": "Tipo de documento",
|
||||
"select-document-type": "Seleccionar tipo de documento",
|
||||
"question-type": "Tipo de pregunta",
|
||||
"select-question-type": "Seleccionar tipo de pregunta"
|
||||
},
|
||||
"document-meta": {
|
||||
"size": "Tamaño",
|
||||
"format": "Formato",
|
||||
"type": "Tipo",
|
||||
"upload-at": "Fecha de carga"
|
||||
},
|
||||
"document-action": {
|
||||
"download": "Descargar",
|
||||
"open-in-new-tab": "Abrir en una nueva pestaña",
|
||||
"preview": "Vista previa"
|
||||
},
|
||||
"mobile-menu": {
|
||||
"title": "Menú",
|
||||
"navigation": "Navegación del sitio",
|
||||
"utilities": "Herramientas útiles"
|
||||
},
|
||||
"homepage": {
|
||||
"recommended-products": "Productos recomendados",
|
||||
"recommended-products-desc": "Explore nuestros productos seleccionados para satisfacer sus diversas necesidades. Ya sea tecnología innovadora o diseño clásico, ofrecemos opciones de calidad para usted.",
|
||||
"recommended-solutions": "Soluciones recomendadas",
|
||||
"recommended-solutions-desc": "Aprenda sobre nuestras soluciones personalizadas, que le ayudarán a optimizar sus procesos de negocio y mejorar la eficiencia."
|
||||
},
|
||||
"page-title": {
|
||||
"homepage": "Página principal",
|
||||
"products": "Productos",
|
||||
"solutions": "Soluciones",
|
||||
"support": "Soporte",
|
||||
"faq": "FAQ",
|
||||
"documents": "Documentos",
|
||||
"contact-us": "Contáctenos",
|
||||
"download": "Descarga de documentos",
|
||||
"preview": "Vista previa de documentos",
|
||||
"about-us": "Sobre nosotros"
|
||||
},
|
||||
"product-tab": {
|
||||
"details": "Detalles",
|
||||
"specs": "Especificaciones",
|
||||
"faq": "FAQ",
|
||||
"documents": "Documentos"
|
||||
}
|
||||
}
|
||||
130
i18n/locales/ru.json
Normal file
130
i18n/locales/ru.json
Normal file
@ -0,0 +1,130 @@
|
||||
{
|
||||
"back": "Назад",
|
||||
"not-found": "Страница не найдена",
|
||||
"search-placeholder": "Поиск...",
|
||||
"search": {
|
||||
"title": "Поиск на сайте",
|
||||
"head-title": "Поиск",
|
||||
"search-button": "Поиск",
|
||||
"results-for": "Результаты поиска для \"{query}\"",
|
||||
"result-count": "Всего {count} результатов",
|
||||
"no-results": "Ничего не найдено по запросу \"{query}\".",
|
||||
"no-query": "Введите ключевые слова для начала поиска.",
|
||||
"section": "раздел",
|
||||
"untitled": "Без названия",
|
||||
"sections": {
|
||||
"product": "Продукты",
|
||||
"solution": "Решения",
|
||||
"faq": "Часто задаваемые вопросы",
|
||||
"document": "Документация",
|
||||
"default": "Другие материалы"
|
||||
}
|
||||
},
|
||||
"company-name": "Jinshen Machinary Manufacturing Co., Ltd.",
|
||||
"company-description": "Профессионально производим оборудование для бумажных трубок и канистр, услуги по проектированию, производству, продаже и сервисному обслуживанию.",
|
||||
"learn-more": "Узнать больше",
|
||||
"products-desc": "Мы предоставляем новейшие продукты и мгновенную сервисную поддержку для удовлетворения различных бизнес-потребностей наших клиентов.",
|
||||
"solutions-desc": "Мы предлагаем разнообразные технические решения для предприятий, поддерживая различные области, такие как промышленность и упаковка.",
|
||||
"support-desc": "Профессиональная техническая поддержка 24/7, обеспечивающая стабильную работу вашего бизнеса.",
|
||||
"quick-links": "Быстрые ссылки",
|
||||
"utilities": "Полезные инструменты",
|
||||
"navigation": {
|
||||
"home": "Главная",
|
||||
"products": "Центр продуктов",
|
||||
"solutions": "Решения",
|
||||
"support": "Поддержка",
|
||||
"about-us": "О нас",
|
||||
"contact-info": "Контактная информация",
|
||||
"downloads": "Файлы для скачивания",
|
||||
"faq": "Часто задаваемые вопросы",
|
||||
"documents": "Документация",
|
||||
"calculator": "Калькулятор бумажных трубок",
|
||||
"address": "Адрес компании"
|
||||
},
|
||||
"contact-info": "Свяжитесь с нами",
|
||||
"telephone": "Телефон",
|
||||
"email": "Электронная почта",
|
||||
"address": "Адрес",
|
||||
"company-address": "No. 689 Qiushi Road, Wutong Industrial Zone, Tongxiang City, Zhejiang Province, China",
|
||||
"follow-us": "Следуйте за нами",
|
||||
"all-rights-reserved": "All rights reserved",
|
||||
"privacy-policy": "Политика конфиденциальности",
|
||||
"terms-of-service": "Условия обслуживания",
|
||||
"sitemap": "Карта сайта",
|
||||
"product-details": "Детали продукта",
|
||||
"product-not-found": "Продукт не найден",
|
||||
"product-not-found-desc": "Извините, продукт, который вы ищете, не существует или был удален.",
|
||||
"back-to-products": "Вернуться к списку продуктов",
|
||||
"solution-not-found": "Решение не найдено",
|
||||
"solution-not-found-desc": "Извините, решение, которое вы ищете, не существует или было удалено.",
|
||||
"back-to-solutions": "Вернуться к списку решений",
|
||||
"page-not-found": "Страница не найдена",
|
||||
"page-not-found-desc": "Извините, страница, которую вы ищете, не существует или была удалена.",
|
||||
"back-to-home": "Вернуться на главную",
|
||||
"no-content-available": "Нет доступной информации",
|
||||
"loading": "Загрузка...",
|
||||
"our-products": "Наши последние продукты",
|
||||
"find-discontinued-products": "Чтобы найти другие продукты, используйте функцию поиска.",
|
||||
"product-discontinued-warning": "Этот продукт снят с производства и может больше не получать мгновенную поддержку или обновления",
|
||||
"learn-our-solutions": "Узнайте о наших решениях",
|
||||
"all": "Все",
|
||||
"support-page-desc": "Zhejiang Jinshen Machinery Manufacturing Co., Ltd Стремится предоставлять клиентам высококачественные продукты и услуги. Мы предлагаем послепродажное обслуживание для таких продуктов, как машины для бумажных трубок и соломинок, обеспечивая уверенность клиентов в использовании нашей продукции.",
|
||||
"support-card-desc": {
|
||||
"faq": "Мы собрали ответы на часто задаваемые вопросы, чтобы помочь вам быстро решить свои проблемы.",
|
||||
"documents": "Предоставляем документацию, такую как руководства по продуктам, технические спецификации, для удобства пользователей.",
|
||||
"contact-info": "Свяжитесь с нами по телефону или электронной почте, и мы оперативно вам поможем."
|
||||
},
|
||||
"product-filter": {
|
||||
"product-type": "Тип продукта",
|
||||
"product-model": "Модель продукта",
|
||||
"keyword": "Ключевое слово",
|
||||
"select-product-type": "Выберите тип продукта",
|
||||
"select-product-model": "Выберите модель продукта",
|
||||
"enter-keyword": "Введите ключевое слово",
|
||||
"misc": "разное",
|
||||
"document-type": "Тип документа",
|
||||
"question-type": "Тип вопроса",
|
||||
"select-document-type": "Выберите тип документа",
|
||||
"select-question-type": "Выберите тип вопроса"
|
||||
},
|
||||
"document-meta": {
|
||||
"size": "Размер",
|
||||
"format": "Формат",
|
||||
"type": "Тип",
|
||||
"upload-at": "Дата загрузки"
|
||||
},
|
||||
"document-action": {
|
||||
"download": "Скачать",
|
||||
"open-in-new-tab": "Открыть в новой вкладке",
|
||||
"preview": "Предварительный просмотр"
|
||||
},
|
||||
"mobile-menu": {
|
||||
"title": "Меню",
|
||||
"navigation": "Навигация по сайту",
|
||||
"utilities": "Полезные инструменты"
|
||||
},
|
||||
"homepage": {
|
||||
"recommended-products": "Рекомендуемые продукты",
|
||||
"recommended-products-desc": "Исследуйте наши тщательно отобранные продукты, которые удовлетворят все ваши потребности. Мы предлагаем как инновационные технологии, так и классические решения.",
|
||||
"recommended-solutions": "Рекомендуемые решения",
|
||||
"recommended-solutions-desc": "Узнайте о наших индивидуальных решениях, чтобы оптимизировать бизнес-процессы и повысить эффективность."
|
||||
},
|
||||
"page-title": {
|
||||
"homepage": "Главная",
|
||||
"products": "Центр продуктов",
|
||||
"solutions": "Решения",
|
||||
"support": "Поддержка",
|
||||
"faq": "Часто задаваемые вопросы",
|
||||
"documents": "Документация",
|
||||
"contact-us": "Свяжитесь с нами",
|
||||
"download": "Скачать докумен",
|
||||
"preview": "Просмотр документа",
|
||||
"about-us": "О нас"
|
||||
},
|
||||
"product-tab": {
|
||||
"details": "Детали продукта",
|
||||
"specs": "Технические спецификации",
|
||||
"faq": "Часто задаваемые вопросы",
|
||||
"documents": "Связанные документы"
|
||||
}
|
||||
}
|
||||
@ -10,6 +10,7 @@
|
||||
"result-count": "共 {count} 条结果",
|
||||
"no-results": "没有找到与 “{query}” 匹配的内容。",
|
||||
"no-query": "请输入关键字开始搜索。",
|
||||
"section": "内容类型",
|
||||
"untitled": "未命名条目",
|
||||
"sections": {
|
||||
"product": "产品",
|
||||
@ -22,8 +23,8 @@
|
||||
"company-name": "金申机械制造有限公司",
|
||||
"company-description": "专业生产一系列纸管、纸罐设备,集设计、制造、销售、服务于一体。",
|
||||
"learn-more": "了解更多",
|
||||
"products-desc": "我们提供高质量的产品解决方案,满足各种业务需求。",
|
||||
"solutions-desc": "为企业提供定制化的技术解决方案,助力数字化转型。",
|
||||
"products-desc": "我们提供最新的产品与即时的服务支持,满足客户的各类业务需求。",
|
||||
"solutions-desc": "我们为企业提供多样化的技术解决方案,在工业、包装等多种领域提供支持。",
|
||||
"support-desc": "7x24小时专业技术支持,确保您的业务稳定运行。",
|
||||
"quick-links": "快速链接",
|
||||
"utilities": "实用工具",
|
||||
@ -62,7 +63,9 @@
|
||||
"back-to-home": "返回首页",
|
||||
"no-content-available": "暂无详细信息",
|
||||
"loading": "加载中...",
|
||||
"our-products": "我们的产品",
|
||||
"our-products": "我们的最新产品",
|
||||
"find-discontinued-products": "如需查找其他产品,请使用搜索功能",
|
||||
"product-discontinued-warning": "本产品已停产,可能不再提供即时的支持或更新",
|
||||
"learn-our-solutions": "了解我们的解决方案",
|
||||
"all": "全部",
|
||||
"support-page-desc": "金申机械制造有限公司致力于为客户提供优质的产品与服务。针对纸管机、分纸机、纸吸管等产品,我们提供全方位的售后服务,确保客户能够安心地使用我们的产品。",
|
||||
@ -77,7 +80,12 @@
|
||||
"keyword": "关键词",
|
||||
"select-product-type": "选择产品类型",
|
||||
"select-product-model": "选择产品系列",
|
||||
"enter-keyword": "输入关键词"
|
||||
"enter-keyword": "输入关键词",
|
||||
"question-type": "问题类型",
|
||||
"select-question-type": "选择问题类型",
|
||||
"document-type": "文档类型",
|
||||
"select-document-type": "选择文档类型",
|
||||
"misc": "其他"
|
||||
},
|
||||
"document-meta": {
|
||||
"size": "大小",
|
||||
|
||||
@ -122,6 +122,8 @@ export default defineNuxtConfig({
|
||||
locales: [
|
||||
{ code: 'en', language: 'en-US', name: 'English', file: 'en.json' },
|
||||
{ code: 'zh', language: 'zh-CN', name: '简体中文', file: 'zh.json' },
|
||||
{ code: 'es', language: 'es-ES', name: 'Español', file: 'es.json' },
|
||||
{ code: 'ru', language: 'ru-RU', name: 'Русский', file: 'ru.json' },
|
||||
],
|
||||
defaultLocale: 'zh',
|
||||
strategy: 'prefix_except_default',
|
||||
|
||||
@ -10,6 +10,13 @@ query GetDocumentList($locale: String!) {
|
||||
id
|
||||
title
|
||||
}
|
||||
type {
|
||||
id
|
||||
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
products {
|
||||
id
|
||||
products_id {
|
||||
|
||||
@ -51,6 +51,13 @@ query GetProduct($id: ID!, $locale: String!) {
|
||||
id
|
||||
product_documents_id(filter: { status: { _eq: "published" } }) {
|
||||
id
|
||||
type {
|
||||
id
|
||||
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
file {
|
||||
id
|
||||
filesize
|
||||
|
||||
@ -1,6 +1,13 @@
|
||||
query GetQuestionList($locale: String!) {
|
||||
questions(filter: { status: { _eq: "published" } }) {
|
||||
id
|
||||
type {
|
||||
id
|
||||
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
|
||||
id
|
||||
title
|
||||
|
||||
@ -1,60 +1,44 @@
|
||||
import { describe, test, expect } from 'vitest';
|
||||
import { toProductDocumentView, toDocumentListView } from './documentMapper';
|
||||
import { toDocumentListView, toDocumentTypeView } from './documentMapper';
|
||||
|
||||
/**
|
||||
* 单元测试: toProductDocumentView
|
||||
* 单元测试: toDocumentTypeView
|
||||
*/
|
||||
describe('toProductDocumentView', () => {
|
||||
const baseData: ProductDocument = {
|
||||
describe('toDocumentTypeView', () => {
|
||||
const baseData: DocumentType = {
|
||||
id: 1,
|
||||
file: {
|
||||
id: 'rand-om__-uuid-1234',
|
||||
filename_download: 'document.pdf',
|
||||
filesize: 2048,
|
||||
},
|
||||
translations: [{ id: 10, title: 'Document Title' }],
|
||||
translations: [{ id: 1, name: 'Type Name' }],
|
||||
};
|
||||
|
||||
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 = {
|
||||
test('convert raw data to DocumentTypeView correctly', () => {
|
||||
const rawData: DocumentType = {
|
||||
...baseData,
|
||||
file: 'rand-om__-uuid-1234',
|
||||
};
|
||||
|
||||
expect(toProductDocumentView(rawData)).toEqual({
|
||||
expect(toDocumentTypeView(rawData)).toEqual({
|
||||
id: '1',
|
||||
fileId: '',
|
||||
filename: '',
|
||||
title: 'Document Title',
|
||||
url: '/api/assets/',
|
||||
size: 0,
|
||||
name: 'Type Name',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: ProductDocument = {
|
||||
const rawData: DocumentType = {
|
||||
...baseData,
|
||||
translations: [],
|
||||
};
|
||||
expect(toProductDocumentView(rawData)).toEqual({
|
||||
|
||||
expect(toDocumentTypeView(rawData)).toEqual({
|
||||
id: '1',
|
||||
fileId: 'rand-om__-uuid-1234',
|
||||
filename: 'document.pdf',
|
||||
title: '',
|
||||
url: '/api/assets/rand-om__-uuid-1234',
|
||||
size: 2048,
|
||||
name: '',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert null input to default DocumentTypeView', () => {
|
||||
const rawData: DocumentType | null = null;
|
||||
|
||||
expect(toDocumentTypeView(rawData)).toEqual({
|
||||
id: '-1',
|
||||
name: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -65,6 +49,15 @@ describe('toProductDocumentView', () => {
|
||||
describe('toDocumentListView', () => {
|
||||
const baseData: ProductDocument = {
|
||||
id: 1,
|
||||
type: {
|
||||
id: 1,
|
||||
translations: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Type A',
|
||||
},
|
||||
],
|
||||
},
|
||||
file: {
|
||||
id: 'rand-om__-uuid-1234',
|
||||
filename_download: 'document.pdf',
|
||||
@ -94,6 +87,10 @@ describe('toDocumentListView', () => {
|
||||
title: 'Document Title',
|
||||
url: '/api/assets/rand-om__-uuid-1234',
|
||||
size: 2048,
|
||||
type: {
|
||||
id: '1',
|
||||
name: 'Type A',
|
||||
},
|
||||
products: [
|
||||
{
|
||||
id: '1',
|
||||
|
||||
@ -1,30 +1,28 @@
|
||||
import { isObject } from '../../server/utils/object';
|
||||
|
||||
/**
|
||||
* 将 Directus 返回的 Document 数据转换为 ProductDocumentView 视图模型
|
||||
* 将 Directus 返回的 DocumentType 数据转换为 DocumentTypeView 视图模型
|
||||
*
|
||||
* @param raw: 原始的 Document 数据
|
||||
* @returns 转换后的 ProductDocumentView 对象
|
||||
* @param raw: 原始的 DocumentType 数据
|
||||
* @returns 转换后的 DocumentTypeView 对象
|
||||
*
|
||||
* @example
|
||||
* const view = toProductDocumentView(rawDocument);
|
||||
* const view = toDocumentTypeView(rawDocumentType);
|
||||
*/
|
||||
export function toProductDocumentView(
|
||||
raw: ProductDocument
|
||||
): ProductDocumentView {
|
||||
export function toDocumentTypeView(
|
||||
raw: DocumentType | string | null
|
||||
): DocumentTypeView {
|
||||
if (typeof raw === 'string' || raw === null) {
|
||||
return {
|
||||
id: '-1',
|
||||
name: '',
|
||||
} satisfies DocumentTypeView;
|
||||
}
|
||||
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,
|
||||
name: trans?.name ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
@ -40,6 +38,8 @@ export function toProductDocumentView(
|
||||
export function toDocumentListView(raw: ProductDocument): DocumentListView {
|
||||
const trans = raw.translations?.[0];
|
||||
|
||||
const type = toDocumentTypeView(raw.type ?? null);
|
||||
|
||||
const file = isObject<DirectusFile>(raw.file) ? raw.file : undefined;
|
||||
const fileId = file?.id ?? '';
|
||||
|
||||
@ -73,6 +73,7 @@ export function toDocumentListView(raw: ProductDocument): DocumentListView {
|
||||
title: trans?.title ?? '',
|
||||
url: url,
|
||||
size: file?.filesize ?? 0,
|
||||
type: type,
|
||||
products: related_products,
|
||||
};
|
||||
}
|
||||
|
||||
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 {
|
||||
toProductListView,
|
||||
toProductImageView,
|
||||
toProductSpecView,
|
||||
toProductSpecGroupView,
|
||||
toProductQuestionView,
|
||||
toProductDocumentView,
|
||||
toProductView,
|
||||
} from './productMapper';
|
||||
|
||||
/**
|
||||
* 单元测试: toProductListView
|
||||
* 单元测试: toProductImageView
|
||||
*/
|
||||
describe('toProductListView', () => {
|
||||
test('convert raw data to ProductListView correctly', () => {
|
||||
const rawData: Product = {
|
||||
describe('toProductImageView', () => {
|
||||
const baseData: Array<ProductsProductImage> = [
|
||||
{
|
||||
id: 1,
|
||||
translations: [
|
||||
{ id: 10, name: 'Product Name', summary: 'Product Summary' },
|
||||
],
|
||||
cover: {
|
||||
id: 'cover-file-uuid-1234',
|
||||
},
|
||||
product_type: {
|
||||
product_images_id: {
|
||||
id: 1,
|
||||
translations: [{ id: 20, name: 'Type Name' }],
|
||||
sort: 1,
|
||||
image: {
|
||||
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({
|
||||
id: '1',
|
||||
name: 'Product Name',
|
||||
summary: 'Product Summary',
|
||||
cover: 'cover-file-uuid-1234',
|
||||
product_type: {
|
||||
test('convert raw data to ProductImageView correctly', () => {
|
||||
const rawData: Array<ProductsProductImage> = [...baseData];
|
||||
|
||||
expect(toProductImageView(rawData)).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
name: 'Type Name',
|
||||
sort: 1,
|
||||
image: 'rand-om__-uuid-1234',
|
||||
caption: 'Image Caption',
|
||||
},
|
||||
});
|
||||
{
|
||||
id: '2',
|
||||
image: 'rand-om__-uuid-5678',
|
||||
caption: 'Image Caption 2',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: Product = {
|
||||
id: 1,
|
||||
translations: [],
|
||||
cover: {
|
||||
id: 'cover-file-uuid-1234',
|
||||
const rawData: Array<ProductsProductImage> = [
|
||||
{
|
||||
id: 1,
|
||||
product_images_id: {
|
||||
id: 1,
|
||||
image: {
|
||||
id: 'rand-om__-uuid-1234',
|
||||
},
|
||||
translations: [],
|
||||
},
|
||||
},
|
||||
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,
|
||||
expect(toProductImageView(rawData)).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
image: 'rand-om__-uuid-1234',
|
||||
caption: '',
|
||||
},
|
||||
});
|
||||
]);
|
||||
});
|
||||
|
||||
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
|
||||
*/
|
||||
describe('toProductSpecView', () => {
|
||||
test('convert raw data to ProductSpecView correctly', () => {
|
||||
const rawData: ProductSpec = {
|
||||
const baseData: ProductSpec[] = [
|
||||
{
|
||||
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({
|
||||
id: '1',
|
||||
key: 'Key',
|
||||
value: 'Value',
|
||||
});
|
||||
expect(toProductSpecView(rawData)).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
key: 'key 1',
|
||||
value: 'value 1',
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
key: 'key 2',
|
||||
value: 'value 2',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: ProductSpec = {
|
||||
id: 1,
|
||||
translations: [],
|
||||
};
|
||||
const rawData: ProductSpec[] = [{ id: 1, translations: [] }];
|
||||
|
||||
expect(toProductSpecView(rawData)).toEqual({
|
||||
id: '1',
|
||||
key: '',
|
||||
value: '',
|
||||
});
|
||||
expect(toProductSpecView(rawData)).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
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', () => {
|
||||
test('convert raw data to ProductSpecGroupView correctly', () => {
|
||||
const rawData: ProductSpecGroup = {
|
||||
id: 1,
|
||||
translations: [{ id: 1, name: 'Group Name' }],
|
||||
specs: [
|
||||
{ id: 1, translations: [{ id: 1, key: 'Key1', value: 'Value1' }] },
|
||||
{ id: 2, translations: [{ id: 2, key: 'Key2', value: 'Value2' }] },
|
||||
],
|
||||
};
|
||||
const rawData: ProductSpecGroup[] = [
|
||||
{
|
||||
id: 1,
|
||||
translations: [{ id: 1, name: 'Group Name' }],
|
||||
specs: [
|
||||
{ id: 1, translations: [{ id: 1, key: 'Key1', value: 'Value1' }] },
|
||||
{ id: 2, translations: [{ id: 2, key: 'Key2', value: 'Value2' }] },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
expect(toProductSpecGroupView(rawData)).toEqual({
|
||||
id: '1',
|
||||
name: 'Group Name',
|
||||
specs: [
|
||||
{ id: '1', key: 'Key1', value: 'Value1' },
|
||||
{ id: '2', key: 'Key2', value: 'Value2' },
|
||||
],
|
||||
});
|
||||
expect(toProductSpecGroupView(rawData)).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
name: 'Group Name',
|
||||
specs: [
|
||||
{ id: '1', key: 'Key1', value: 'Value1' },
|
||||
{ id: '2', key: 'Key2', value: 'Value2' },
|
||||
],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: ProductSpecGroup = {
|
||||
id: 1,
|
||||
translations: [],
|
||||
specs: [],
|
||||
};
|
||||
const rawData: ProductSpecGroup[] = [
|
||||
{
|
||||
id: 1,
|
||||
translations: [],
|
||||
specs: [],
|
||||
},
|
||||
];
|
||||
|
||||
expect(toProductSpecGroupView(rawData)).toEqual({
|
||||
id: '1',
|
||||
name: '',
|
||||
specs: [],
|
||||
});
|
||||
expect(toProductSpecGroupView(rawData)).toEqual([
|
||||
{
|
||||
id: '1',
|
||||
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
|
||||
*/
|
||||
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', () => {
|
||||
const rawData: Product = {
|
||||
id: 1,
|
||||
translations: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Product Name',
|
||||
summary: 'Product Summary',
|
||||
description: 'Product Description',
|
||||
},
|
||||
],
|
||||
...baseData,
|
||||
};
|
||||
|
||||
expect(toProductView(rawData)).toEqual({
|
||||
id: '1',
|
||||
status: 'in-production',
|
||||
name: 'Product Name',
|
||||
summary: 'Product Summary',
|
||||
description: 'Product Description',
|
||||
product_type: '',
|
||||
images: [],
|
||||
documents: [],
|
||||
faqs: [],
|
||||
@ -169,16 +488,35 @@ describe('toProductView', () => {
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: Product = {
|
||||
id: 1,
|
||||
...baseData,
|
||||
translations: [],
|
||||
};
|
||||
|
||||
expect(toProductView(rawData)).toEqual({
|
||||
id: '1',
|
||||
status: 'in-production',
|
||||
name: '',
|
||||
summary: '',
|
||||
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: [],
|
||||
documents: [],
|
||||
faqs: [],
|
||||
|
||||
@ -1,55 +1,42 @@
|
||||
import { toProductQuestionView } from './questionMapper';
|
||||
import { toProductDocumentView } from './documentMapper';
|
||||
import { isObject } from '../../server/utils/object';
|
||||
import { toDocumentTypeView } from './documentMapper';
|
||||
|
||||
/**
|
||||
* 将Directus返回的ProductType数据转换为ProductTypeView视图模型
|
||||
* 将 Directus 返回的 ProductImage 数据转换为 ProductImageView 视图模型
|
||||
*
|
||||
* @param raw: 原始的ProductType数据
|
||||
* @returns 转换后的ProductTypeView对象
|
||||
* @param raw: 原始的 ProductsProductImage 数据
|
||||
* @returns 转换后的 ProductImageView 对象
|
||||
*
|
||||
* @example
|
||||
* const view = toProductTypeView(rawProductType);
|
||||
* const view = toProductImageView(rawProductImage);
|
||||
*/
|
||||
export function toProductTypeView(raw: ProductType): ProductTypeView {
|
||||
const trans = raw.translations?.[0] ?? { name: '' };
|
||||
export function toProductImageView(
|
||||
raw: (ProductsProductImage | string)[]
|
||||
): ProductImageView[] {
|
||||
return (raw ?? []).map((item) => {
|
||||
if (!isObject<ProductsProductImage>(item))
|
||||
return {
|
||||
id: item,
|
||||
image: '',
|
||||
caption: '',
|
||||
} satisfies ProductImageView;
|
||||
|
||||
return {
|
||||
id: raw.id.toString(),
|
||||
name: trans.name,
|
||||
sort: raw?.sort ?? 999,
|
||||
};
|
||||
}
|
||||
const image = item.product_images_id;
|
||||
if (!isObject<ProductImage>(image))
|
||||
return {
|
||||
id: item.id.toString(),
|
||||
image: '',
|
||||
caption: '',
|
||||
} satisfies ProductImageView;
|
||||
|
||||
/**
|
||||
* 将 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 trans = image.translations?.[0];
|
||||
|
||||
const type = isObject<ProductType>(raw.product_type)
|
||||
? toProductTypeView(raw.product_type)
|
||||
: ({
|
||||
id: '',
|
||||
name: '',
|
||||
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,
|
||||
};
|
||||
return {
|
||||
id: item.id.toString(),
|
||||
image: isObject<DirectusFile>(image.image) ? image.image.id : '',
|
||||
caption: trans?.caption || '',
|
||||
} satisfies ProductImageView;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,19 +49,26 @@ export function toProductListView(raw: Product): ProductListView {
|
||||
* const view = toProductSpecGroupView(rawSpecGroup);
|
||||
*/
|
||||
export function toProductSpecGroupView(
|
||||
raw: ProductSpecGroup
|
||||
): ProductSpecGroupView {
|
||||
const trans = raw.translations?.[0];
|
||||
raw: (ProductSpecGroup | string)[]
|
||||
): ProductSpecGroupView[] {
|
||||
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 {
|
||||
id: raw.id.toString(),
|
||||
name: trans?.name ?? '',
|
||||
specs: specs
|
||||
.filter(isObject<ProductSpec>)
|
||||
.map((item) => toProductSpecView(item)),
|
||||
};
|
||||
return {
|
||||
id: item.id.toString(),
|
||||
name: trans?.name ?? '',
|
||||
specs: specs,
|
||||
} satisfies ProductSpecGroupView;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,14 +80,131 @@ export function toProductSpecGroupView(
|
||||
* @example
|
||||
* const view = toProductSpecView(rawSpecGroup);
|
||||
*/
|
||||
export function toProductSpecView(raw: ProductSpec): ProductSpecView {
|
||||
const trans = raw.translations?.[0];
|
||||
export function toProductSpecView(
|
||||
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 {
|
||||
id: raw.id.toString(),
|
||||
key: trans?.key ?? '',
|
||||
value: trans?.value ?? '',
|
||||
};
|
||||
return {
|
||||
id: item.id.toString(),
|
||||
key: trans?.key ?? '',
|
||||
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 {
|
||||
const trans = raw.translations?.[0];
|
||||
|
||||
const images = (raw.images ?? [])
|
||||
.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 status = raw.status ?? 'discontinued';
|
||||
|
||||
const type = isObject<ProductType>(raw.product_type)
|
||||
? (raw.product_type.translations?.[0]?.name ?? '')
|
||||
: '';
|
||||
const images = toProductImageView(raw.images ?? []);
|
||||
|
||||
const specs = (raw.specs ?? [])
|
||||
.filter(isObject<ProductSpecGroup>)
|
||||
.map((item) => toProductSpecGroupView(item));
|
||||
const specs = toProductSpecGroupView(raw.specs ?? []);
|
||||
|
||||
const faqs = (raw.faqs ?? [])
|
||||
.filter(isObject<ProductsQuestion>)
|
||||
.map((item) => item.questions_id)
|
||||
.filter(isObject<Question>)
|
||||
.map((item) => toProductQuestionView(item));
|
||||
const faqs = toProductQuestionView(raw.faqs ?? []);
|
||||
|
||||
const documents = (raw.documents ?? [])
|
||||
.filter(isObject<ProductsProductDocument>)
|
||||
.map((item) => item.product_documents_id)
|
||||
.filter(isObject<ProductDocument>)
|
||||
.map((item) => toProductDocumentView(item));
|
||||
const documents = toProductDocumentView(raw.documents ?? []);
|
||||
|
||||
return {
|
||||
id: raw.id.toString(),
|
||||
product_type: type,
|
||||
status: status,
|
||||
name: trans?.name ?? '',
|
||||
summary: trans?.summary ?? '',
|
||||
images: images,
|
||||
@ -151,5 +239,5 @@ export function toProductView(raw: Product): ProductView {
|
||||
specs: specs,
|
||||
faqs: faqs,
|
||||
documents: documents,
|
||||
};
|
||||
} satisfies ProductView;
|
||||
}
|
||||
|
||||
@ -1,38 +1,44 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { toProductQuestionView, toQuestionListView } from './questionMapper';
|
||||
import { toQuestionListView, toQuestionTypeView } from './questionMapper';
|
||||
|
||||
/**
|
||||
* 单元测试: toProductQuestionView
|
||||
* 单元测试: toQuestionTypeView
|
||||
*/
|
||||
describe('toProductQuestionView', () => {
|
||||
const baseData: Question = {
|
||||
describe('toQuestionTypeView', () => {
|
||||
const baseData: QuestionType = {
|
||||
id: 1,
|
||||
translations: [
|
||||
{ id: 1, title: 'Question Title', content: 'Question Answer' },
|
||||
],
|
||||
translations: [{ id: 1, name: 'Type Name' }],
|
||||
};
|
||||
test('convert raw data to ProductQuestionView correctly', () => {
|
||||
const rawData: Question = {
|
||||
|
||||
test('convert raw data to QuestionTypeView correctly', () => {
|
||||
const rawData: QuestionType = {
|
||||
...baseData,
|
||||
};
|
||||
|
||||
expect(toProductQuestionView(rawData)).toEqual({
|
||||
expect(toQuestionTypeView(rawData)).toEqual({
|
||||
id: '1',
|
||||
title: 'Question Title',
|
||||
content: 'Question Answer',
|
||||
name: 'Type Name',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert raw data with missing translations', () => {
|
||||
const rawData: Question = {
|
||||
const rawData: QuestionType = {
|
||||
...baseData,
|
||||
translations: [],
|
||||
};
|
||||
|
||||
expect(toProductQuestionView(rawData)).toEqual({
|
||||
expect(toQuestionTypeView(rawData)).toEqual({
|
||||
id: '1',
|
||||
title: '',
|
||||
content: '',
|
||||
name: '',
|
||||
});
|
||||
});
|
||||
|
||||
test('convert null input to default QuestionTypeView', () => {
|
||||
const rawData: QuestionType | null = null;
|
||||
|
||||
expect(toQuestionTypeView(rawData)).toEqual({
|
||||
id: '-1',
|
||||
name: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -43,6 +49,10 @@ describe('toProductQuestionView', () => {
|
||||
describe('toQuestionListView', () => {
|
||||
const baseData: Question = {
|
||||
id: 1,
|
||||
type: {
|
||||
id: 1,
|
||||
translations: [{ id: 1, name: 'Type Name' }],
|
||||
},
|
||||
translations: [
|
||||
{ id: 1, title: 'Question Title', content: 'Question Answer' },
|
||||
],
|
||||
@ -68,6 +78,10 @@ describe('toQuestionListView', () => {
|
||||
|
||||
expect(toQuestionListView(rawData)).toEqual({
|
||||
id: '1',
|
||||
type: {
|
||||
id: '1',
|
||||
name: 'Type Name',
|
||||
},
|
||||
title: 'Question Title',
|
||||
content: 'Question Answer',
|
||||
products: [
|
||||
@ -104,6 +118,10 @@ describe('toQuestionListView', () => {
|
||||
|
||||
expect(toQuestionListView(rawData)).toEqual({
|
||||
id: '1',
|
||||
type: {
|
||||
id: '1',
|
||||
name: 'Type Name',
|
||||
},
|
||||
title: '',
|
||||
content: '',
|
||||
products: [
|
||||
|
||||
@ -1,21 +1,28 @@
|
||||
import { isObject } from '../../server/utils/object';
|
||||
|
||||
/**
|
||||
* 将 Directus 返回的 Question 数据转换为 ProductQuestionView 视图模型
|
||||
* 将 Directus 返回的 QuestionType 类型转换为 QuestionTypeView 视图模型
|
||||
*
|
||||
* @param raw: 原始的 Question 数据
|
||||
* @returns 转换后的 ProductQuestionView 对象
|
||||
* @param raw: 原始的 QuestionType 数据
|
||||
* @returns 转换后的 QuestionTypeView 对象
|
||||
*
|
||||
* @example
|
||||
* const view = toProductQuestionView(rawQuestion);
|
||||
* const view = toQuestionTypeView(rawQuestionType);
|
||||
*/
|
||||
export function toProductQuestionView(raw: Question): ProductQuestionView {
|
||||
export function toQuestionTypeView(
|
||||
raw: QuestionType | string | null
|
||||
): QuestionTypeView {
|
||||
if (typeof raw === 'string' || raw === null) {
|
||||
return {
|
||||
id: '-1',
|
||||
name: '',
|
||||
} satisfies QuestionTypeView;
|
||||
}
|
||||
const trans = raw.translations?.[0];
|
||||
|
||||
return {
|
||||
id: raw.id.toString(),
|
||||
title: trans?.title ?? '',
|
||||
content: trans?.content ?? '',
|
||||
name: trans?.name ?? '',
|
||||
};
|
||||
}
|
||||
|
||||
@ -31,6 +38,8 @@ export function toProductQuestionView(raw: Question): ProductQuestionView {
|
||||
export function toQuestionListView(raw: Question): QuestionListView {
|
||||
const trans = raw.translations?.[0];
|
||||
|
||||
const type = toQuestionTypeView(raw.type ?? null);
|
||||
|
||||
const related_products: QuestionListProduct[] = (raw.products ?? [])
|
||||
.filter(isObject<ProductsQuestion>)
|
||||
.map((item) => item.products_id)
|
||||
@ -57,6 +66,7 @@ export function toQuestionListView(raw: Question): QuestionListView {
|
||||
|
||||
return {
|
||||
id: raw.id.toString(),
|
||||
type: type,
|
||||
title: trans?.title ?? '',
|
||||
content: trans?.content ?? '',
|
||||
products: related_products,
|
||||
|
||||
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 { toSolutionListView, 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: '',
|
||||
});
|
||||
});
|
||||
});
|
||||
import { toSolutionView } from './solutionMapper';
|
||||
|
||||
/**
|
||||
* 单元测试: 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 视图模型
|
||||
*
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import {
|
||||
toProductView,
|
||||
toProductListView,
|
||||
} from '~~/server/mappers/productMapper';
|
||||
import { toProductView } from '~~/server/mappers/productMapper';
|
||||
import { toProductListView } from '~~/server/mappers/productListMapper';
|
||||
|
||||
export const productService = {
|
||||
async getProductList(locale: string) {
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
import {
|
||||
toSolutionView,
|
||||
toSolutionListView,
|
||||
} from '~~/server/mappers/solutionMapper';
|
||||
import { toSolutionView } from '~~/server/mappers/solutionMapper';
|
||||
import { toSolutionListView } from '~~/server/mappers/solutionListMapper';
|
||||
|
||||
export const solutionService = {
|
||||
async getSolutionList(locale: string) {
|
||||
|
||||
@ -12,13 +12,16 @@ describe('converters', () => {
|
||||
summary: 'High efficiency',
|
||||
description: 'Detailed description',
|
||||
type: 'pump',
|
||||
cover: 'rand-om__-uuid-1234',
|
||||
};
|
||||
const result = converters.products(item);
|
||||
expect(result).toEqual({
|
||||
id: 1,
|
||||
type: 'product',
|
||||
sectionType: 'product',
|
||||
title: 'Hydraulic Pump',
|
||||
summary: 'High efficiency',
|
||||
type: 'pump',
|
||||
thumbnail: '/api/assets/rand-om__-uuid-1234',
|
||||
});
|
||||
});
|
||||
|
||||
@ -29,13 +32,16 @@ describe('converters', () => {
|
||||
summary: 'Effective solution',
|
||||
content: 'Detailed content',
|
||||
type: 'Type A',
|
||||
cover: 'rand-om__-uuid-5678',
|
||||
};
|
||||
const result = converters.solutions(item);
|
||||
expect(result).toEqual({
|
||||
id: 1,
|
||||
type: 'solution',
|
||||
sectionType: 'solution',
|
||||
title: 'Solution A',
|
||||
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.',
|
||||
products: ['Product A'],
|
||||
product_types: ['Type A'],
|
||||
type: 'Question Type',
|
||||
};
|
||||
const result = converters.questions(item);
|
||||
expect(result).toEqual({
|
||||
id: 1,
|
||||
title: 'How to use product?',
|
||||
summary: '',
|
||||
type: 'question',
|
||||
summary: undefined,
|
||||
type: 'Question Type',
|
||||
sectionType: 'question',
|
||||
});
|
||||
});
|
||||
|
||||
@ -64,13 +72,15 @@ describe('converters', () => {
|
||||
products: ['Product A'],
|
||||
product_types: ['Type A'],
|
||||
fileUUID: 'TEST-UUID',
|
||||
type: 'manual',
|
||||
};
|
||||
const result = converters.product_documents(item);
|
||||
expect(result).toEqual({
|
||||
id: 'TEST-UUID',
|
||||
title: 'User Manual',
|
||||
summary: '',
|
||||
type: 'document',
|
||||
summary: undefined,
|
||||
sectionType: 'document',
|
||||
type: 'manual',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -6,31 +6,35 @@ export const converters: {
|
||||
} = {
|
||||
products: (item: MeiliIndexMap['products']): SearchItemView => ({
|
||||
id: item.id,
|
||||
type: 'product',
|
||||
sectionType: 'product',
|
||||
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 => ({
|
||||
id: item.id,
|
||||
type: 'solution',
|
||||
sectionType: 'solution',
|
||||
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 => ({
|
||||
id: item.id,
|
||||
type: 'question',
|
||||
sectionType: 'question',
|
||||
title: item.title,
|
||||
summary: '',
|
||||
type: item?.type,
|
||||
}),
|
||||
|
||||
product_documents: (
|
||||
item: MeiliIndexMap['product_documents']
|
||||
): SearchItemView => ({
|
||||
id: item.fileUUID || item.id,
|
||||
type: 'document',
|
||||
sectionType: 'document',
|
||||
title: item.title,
|
||||
summary: '',
|
||||
type: item?.type,
|
||||
}),
|
||||
};
|
||||
|
||||
@ -1,3 +1,19 @@
|
||||
export interface AiPrompt {
|
||||
/** @primaryKey */
|
||||
id: string;
|
||||
sort?: number | null;
|
||||
date_created?: string | null;
|
||||
user_created?: DirectusUser | string | null;
|
||||
date_updated?: string | null;
|
||||
user_updated?: DirectusUser | string | null;
|
||||
/** @required */
|
||||
name: string;
|
||||
status?: 'published' | 'draft' | 'archived' | null;
|
||||
description?: string | null;
|
||||
system_prompt?: string | null;
|
||||
messages?: Array<{ role: 'user' | 'assistant'; text: string }> | null;
|
||||
}
|
||||
|
||||
export interface CompanyProfile {
|
||||
/** @primaryKey */
|
||||
id: number;
|
||||
@ -26,6 +42,20 @@ export interface ContactInfoTranslation {
|
||||
content?: string | null;
|
||||
}
|
||||
|
||||
export interface DocumentType {
|
||||
/** @primaryKey */
|
||||
id: number;
|
||||
translations?: DocumentTypesTranslation[] | null;
|
||||
}
|
||||
|
||||
export interface DocumentTypesTranslation {
|
||||
/** @primaryKey */
|
||||
id: number;
|
||||
document_types_id?: DocumentType | string | null;
|
||||
languages_code?: Language | string | null;
|
||||
name?: string | null;
|
||||
}
|
||||
|
||||
export interface Homepage {
|
||||
/** @primaryKey */
|
||||
id: number;
|
||||
@ -75,8 +105,9 @@ export interface ProductDocument {
|
||||
id: number;
|
||||
status?: 'published' | 'draft' | 'archived';
|
||||
file?: DirectusFile | string | null;
|
||||
products?: ProductsProductDocument[] | string[];
|
||||
type?: DocumentType | string | null;
|
||||
translations?: ProductDocumentsTranslation[] | null;
|
||||
products?: ProductsProductDocument[] | string[];
|
||||
}
|
||||
|
||||
export interface ProductDocumentsTranslation {
|
||||
@ -209,10 +240,25 @@ export interface ProductsTranslation {
|
||||
description?: string | null;
|
||||
}
|
||||
|
||||
export interface QuestionType {
|
||||
/** @primaryKey */
|
||||
id: number;
|
||||
translations?: QuestionTypesTranslation[] | null;
|
||||
}
|
||||
|
||||
export interface QuestionTypesTranslation {
|
||||
/** @primaryKey */
|
||||
id: number;
|
||||
question_types_id?: QuestionType | string | null;
|
||||
languages_code?: Language | string | null;
|
||||
name?: string | null;
|
||||
}
|
||||
|
||||
export interface Question {
|
||||
/** @primaryKey */
|
||||
id: number;
|
||||
status?: 'published' | 'draft' | 'archived';
|
||||
type?: QuestionType | string | null;
|
||||
/** @description i18n字段 */
|
||||
translations?: QuestionsTranslation[] | null;
|
||||
products?: ProductsQuestion[] | string[];
|
||||
@ -741,10 +787,13 @@ export interface DirectusExtension {
|
||||
}
|
||||
|
||||
export interface Schema {
|
||||
ai_prompts: AiPrompt[];
|
||||
company_profile: CompanyProfile;
|
||||
company_profile_translations: CompanyProfileTranslation[];
|
||||
contact_info: ContactInfo;
|
||||
contact_info_translations: ContactInfoTranslation[];
|
||||
document_types: DocumentType[];
|
||||
document_types_translations: DocumentTypesTranslation[];
|
||||
homepage: Homepage;
|
||||
homepage_files: HomepageFile[];
|
||||
languages: Language[];
|
||||
@ -765,6 +814,8 @@ export interface Schema {
|
||||
products_product_images: ProductsProductImage[];
|
||||
products_questions: ProductsQuestion[];
|
||||
products_translations: ProductsTranslation[];
|
||||
question_types: QuestionType[];
|
||||
question_types_translations: QuestionTypesTranslation[];
|
||||
questions: Question[];
|
||||
questions_translations: QuestionsTranslation[];
|
||||
solution_types: SolutionType[];
|
||||
@ -801,10 +852,13 @@ export interface Schema {
|
||||
}
|
||||
|
||||
export enum CollectionNames {
|
||||
ai_prompts = 'ai_prompts',
|
||||
company_profile = 'company_profile',
|
||||
company_profile_translations = 'company_profile_translations',
|
||||
contact_info = 'contact_info',
|
||||
contact_info_translations = 'contact_info_translations',
|
||||
document_types = 'document_types',
|
||||
document_types_translations = 'document_types_translations',
|
||||
homepage = 'homepage',
|
||||
homepage_files = 'homepage_files',
|
||||
languages = 'languages',
|
||||
@ -825,6 +879,8 @@ export enum CollectionNames {
|
||||
products_product_images = 'products_product_images',
|
||||
products_questions = 'products_questions',
|
||||
products_translations = 'products_translations',
|
||||
question_types = 'question_types',
|
||||
question_types_translations = 'question_types_translations',
|
||||
questions = 'questions',
|
||||
questions_translations = 'questions_translations',
|
||||
solution_types = 'solution_types',
|
||||
|
||||
@ -9,13 +9,16 @@ export interface MeiliProductIndex {
|
||||
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;
|
||||
|
||||
/** 解决方案摘要 **/
|
||||
summary: string;
|
||||
summary?: string;
|
||||
|
||||
/** 解决方案内容 **/
|
||||
content: string;
|
||||
content?: string;
|
||||
|
||||
/** 解决方案类型 **/
|
||||
type: string;
|
||||
type?: string;
|
||||
|
||||
/** 解决方案缩略图 **/
|
||||
cover?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,7 +55,10 @@ export interface MeiliQuestionIndex {
|
||||
title: string;
|
||||
|
||||
/** 问题内容 **/
|
||||
content: string;
|
||||
content?: string;
|
||||
|
||||
/** 问题类型 **/
|
||||
type?: string;
|
||||
|
||||
/** 相关产品 **/
|
||||
products: string[];
|
||||
@ -68,6 +77,9 @@ export interface MeiliProductDocumentIndex {
|
||||
/** 文档标题 **/
|
||||
title: string;
|
||||
|
||||
/** 文档类型 **/
|
||||
type?: string;
|
||||
|
||||
/** 相关产品 **/
|
||||
products: string[];
|
||||
|
||||
|
||||
@ -1,3 +1,14 @@
|
||||
/**
|
||||
* 文档类型视图模型
|
||||
* 用于在文档库中提供类型筛选功能
|
||||
*/
|
||||
export interface DocumentTypeView {
|
||||
/** 唯一标识符 **/
|
||||
id: string;
|
||||
/** 类型名 **/
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档关联产品类型模型
|
||||
* 用于在文档库中提供产品筛选功能
|
||||
@ -40,6 +51,9 @@ export interface DocumentListView {
|
||||
/** 文档链接 **/
|
||||
url: string;
|
||||
|
||||
/** 文档类型 **/
|
||||
type: DocumentTypeView;
|
||||
|
||||
/** 相关产品 **/
|
||||
products: DocumentListProduct[];
|
||||
}
|
||||
|
||||
@ -2,9 +2,6 @@ export * from './solution-view';
|
||||
export * from './solution-list-view';
|
||||
export * from './product-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 './question-list-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 { ProductQuestionView } from './product-question-view';
|
||||
import type { ProductDocumentView } from './product-document-view';
|
||||
import type { DocumentTypeView } from './document-list-view';
|
||||
import type { Product } from '../directus/my-schema.ts';
|
||||
|
||||
interface ImageView {
|
||||
type ProductStatus = Product['status'];
|
||||
|
||||
/**
|
||||
* 产品图片视图模型
|
||||
* 用于产品详情页(/products/[slug])中的产品图片数据结构
|
||||
*/
|
||||
export interface ProductImageView {
|
||||
id: string;
|
||||
image: 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])渲染的数据结构
|
||||
@ -16,17 +93,17 @@ export interface ProductView {
|
||||
/** 唯一标识符 **/
|
||||
id: string;
|
||||
|
||||
/** 产品状态 **/
|
||||
status: ProductStatus;
|
||||
|
||||
/** 产品名称 **/
|
||||
name: string;
|
||||
|
||||
/** 产品简介 **/
|
||||
summary: string;
|
||||
|
||||
/** 产品类型 **/
|
||||
product_type: string;
|
||||
|
||||
/** 产品图片 **/
|
||||
images: ImageView[];
|
||||
images: ProductImageView[];
|
||||
|
||||
/** 产品详情 **/
|
||||
description: string;
|
||||
|
||||
@ -7,6 +7,18 @@ export interface QuestionListProductType {
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 问题类型
|
||||
* 用于在常见问题列表中提供产品筛选功能
|
||||
*/
|
||||
export interface QuestionTypeView {
|
||||
/** 唯一标识符 **/
|
||||
id: string;
|
||||
|
||||
/** 类型名 **/
|
||||
name: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 问题关联产品模型
|
||||
* 用于在常见问题列表中提供产品筛选功能
|
||||
@ -25,6 +37,9 @@ export interface QuestionListView {
|
||||
/** 唯一标识符 **/
|
||||
id: string;
|
||||
|
||||
/** 问题类型 **/
|
||||
type: QuestionTypeView;
|
||||
|
||||
/** 问题标题 **/
|
||||
title: string;
|
||||
|
||||
|
||||
@ -3,11 +3,17 @@ export interface SearchItemView {
|
||||
id: number | string;
|
||||
|
||||
/** 条目类型 **/
|
||||
type: 'product' | 'solution' | 'question' | 'document';
|
||||
sectionType: 'product' | 'solution' | 'question' | 'document';
|
||||
|
||||
/** 条目标题 **/
|
||||
title: string;
|
||||
|
||||
/** 条目摘要 **/
|
||||
summary: string;
|
||||
summary?: string;
|
||||
|
||||
/** 条目分类 **/
|
||||
type?: string;
|
||||
|
||||
/** 条目预览图 **/
|
||||
thumbnail?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user