Compare commits

..

4 Commits

Author SHA1 Message Date
63cdff9c41 feat: 为文档库添加文档类型显示功能
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m10s
- 功能添加:在文档列表中,当未指定文档类型时,在标题右侧显示文档类型
- 查询更改:产品查询添加文档类型查询方法
- mapper更改:productDocumentView添加文档类型
2025-12-05 17:18:48 +08:00
f1398a5545 feat: 为搜索条目添加细分类型
- 类型细分:有原先的四大分类添加细分类型,例如产品(原纸分切机)
- 接口调整:原先的type分类改为sectionType并将type作为细分类型使用
2025-12-05 16:49:09 +08:00
36d24a4740 fix: 可选字段处理
- 为搜索条目中的可选字段进行判断并处理
2025-12-05 16:25:57 +08:00
c9b5b1fad9 feat: 为搜索页栏目添加图片缩略图功能
- 图片预览:产品与解决方案栏目添加缩略图功能
- 组件提取:在搜索结果页,将单个搜索结果单独提取为组件SearchResultCard
2025-12-05 14:56:24 +08:00
13 changed files with 221 additions and 42 deletions

View 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>

View File

@ -3,19 +3,13 @@
<div class="search-results"> <div class="search-results">
<NuxtLink <NuxtLink
v-for="hit in paginatedHits" v-for="hit in paginatedHits"
:key="`${hit.type}-${hit.id}`" :key="`${hit.sectionType}-${hit.id}`"
:to="localePath(resolveHitLink(hit))" :to="localePath(resolveHitLink(hit))"
> >
<el-card class="result-card"> <search-result-card
<h3 class="result-title">{{ hit.title }}</h3> :item="hit"
<p v-if="hit.summary" class="result-summary"> :type-label="getIndexLabel(hit.sectionType)"
{{ hit.summary }} />
</p>
<p v-if="hit.type" class="result-type">
<span>{{ $t('search.section') }}: </span>
<span class="result-type-name">{{ getIndexLabel(hit.type) }}</span>
</p>
</el-card>
</NuxtLink> </NuxtLink>
</div> </div>
@ -72,7 +66,7 @@
const items = props.searchItems; const items = props.searchItems;
const filteredHits = computed(() => { const filteredHits = computed(() => {
if (props.category) { if (props.category) {
return items.filter((item) => item.type === props.category); return items.filter((item) => item.sectionType === props.category);
} else { } else {
return items; return items;
} }
@ -116,19 +110,19 @@
const slug = String(slugCandidate); const slug = String(slugCandidate);
if (item.type === 'product') { if (item.sectionType === 'product') {
return localePath({ path: `/products/${slug}` }); return localePath({ path: `/products/${slug}` });
} }
if (item.type === 'solution') { if (item.sectionType === 'solution') {
return localePath({ path: `/solutions/${slug}` }); return localePath({ path: `/solutions/${slug}` });
} }
if (item.type === 'document') { if (item.sectionType === 'document') {
return localePath({ path: `/download/${slug}` }); return localePath({ path: `/download/${slug}` });
} }
if (item.type === 'question') { if (item.sectionType === 'question') {
return localePath({ path: `/support/faq`, query: { focus: slug } }); return localePath({ path: `/support/faq`, query: { focus: slug } });
} }

View File

@ -32,7 +32,7 @@
const resultCount = computed(() => { const resultCount = computed(() => {
const map: Record<string, number> = { all: props.searchItems.length }; const map: Record<string, number> = { all: props.searchItems.length };
for (const item of props.searchItems) { for (const item of props.searchItems) {
map[item.type] = (map[item.type] ?? 0) + 1; map[item.sectionType] = (map[item.sectionType] ?? 0) + 1;
} }
return map; return map;
}); });

View File

@ -7,7 +7,17 @@
@click="handleClick(doc.fileId)" @click="handleClick(doc.fileId)"
> >
<div class="document-info"> <div class="document-info">
<h3>{{ doc.title }}</h3> <div class="document-title">
<h3>
{{ doc.title }}
<span v-if="showCategory && doc.type" class="document-category">
|
</span>
<span v-if="showCategory && doc.type" class="document-category">
{{ doc.type.name }}
</span>
</h3>
</div>
<div class="document-content"> <div class="document-content">
<span v-if="doc.size" class="document-meta" <span v-if="doc.size" class="document-meta"
>{{ $t('document-meta.size') }}: {{ formatFileSize(doc.size) }} >{{ $t('document-meta.size') }}: {{ formatFileSize(doc.size) }}
@ -28,6 +38,10 @@
type: Array as () => Array<ProductDocumentView>, type: Array as () => Array<ProductDocumentView>,
default: () => [], default: () => [],
}, },
showCategory: {
type: Boolean,
default: true,
},
}); });
const localePath = useLocalePath(); const localePath = useLocalePath();
@ -63,6 +77,15 @@
color: var(--el-text-color-secondary); color: var(--el-text-color-secondary);
} }
.document-title {
margin-bottom: 0.5rem;
}
.document-category {
font-size: 0.75rem;
color: var(--el-text-color-secondary);
}
.download-button { .download-button {
margin-left: auto; margin-left: auto;
} }

View File

@ -17,7 +17,13 @@
:document-type-options="documentTypeOptions" :document-type-options="documentTypeOptions"
/> />
<document-list :documents="paginatedDocuments" /> <document-list
:documents="paginatedDocuments"
:show-category="
filters.selectedDocumentType === null ||
filters.selectedDocumentType === undefined
"
/>
<el-pagination <el-pagination
v-model:current-page="page" v-model:current-page="page"

View File

@ -51,6 +51,13 @@ query GetProduct($id: ID!, $locale: String!) {
id id
product_documents_id(filter: { status: { _eq: "published" } }) { product_documents_id(filter: { status: { _eq: "published" } }) {
id id
type {
id
translations(filter: { languages_code: { code: { _eq: $locale } } }) {
id
name
}
}
file { file {
id id
filesize filesize

View File

@ -347,6 +347,15 @@ describe('toProductDocumentView', () => {
filesize: 1000, filesize: 1000,
filename_download: 'doc1.pdf', filename_download: 'doc1.pdf',
}, },
type: {
id: 1,
translations: [
{
id: 1,
name: 'manual',
},
],
},
translations: [ translations: [
{ {
id: 1, id: 1,
@ -363,6 +372,10 @@ describe('toProductDocumentView', () => {
fileId: 'rand-om__-uuid-1234', fileId: 'rand-om__-uuid-1234',
filename: 'doc1.pdf', filename: 'doc1.pdf',
title: 'Document Title 1', title: 'Document Title 1',
type: {
id: '1',
name: 'manual',
},
size: 1000, size: 1000,
url: '/api/assets/rand-om__-uuid-1234', url: '/api/assets/rand-om__-uuid-1234',
}, },
@ -391,6 +404,10 @@ describe('toProductDocumentView', () => {
fileId: 'rand-om__-uuid-1234', fileId: 'rand-om__-uuid-1234',
filename: 'doc1.pdf', filename: 'doc1.pdf',
title: '', title: '',
type: {
id: '-1',
name: '',
},
size: 1000, size: 1000,
url: '/api/assets/rand-om__-uuid-1234', url: '/api/assets/rand-om__-uuid-1234',
}, },
@ -413,6 +430,10 @@ describe('toProductDocumentView', () => {
filename: '', filename: '',
title: '', title: '',
size: 0, size: 0,
type: {
id: '-1',
name: '',
},
url: '', url: '',
}, },
{ {
@ -421,6 +442,10 @@ describe('toProductDocumentView', () => {
filename: '', filename: '',
title: '', title: '',
size: 0, size: 0,
type: {
id: '-1',
name: '',
},
url: '', url: '',
}, },
]); ]);

View File

@ -1,4 +1,5 @@
import { isObject } from '../../server/utils/object'; import { isObject } from '../../server/utils/object';
import { toDocumentTypeView } from './documentMapper';
/** /**
* 将 Directus 返回的 ProductImage 数据转换为 ProductImageView 视图模型 * 将 Directus 返回的 ProductImage 数据转换为 ProductImageView 视图模型
@ -161,6 +162,10 @@ export function toProductDocumentView(
size: 0, size: 0,
title: '', title: '',
url: '', url: '',
type: {
id: '-1',
name: '',
},
} satisfies ProductDocumentView; } satisfies ProductDocumentView;
} }
@ -173,6 +178,10 @@ export function toProductDocumentView(
size: 0, size: 0,
title: '', title: '',
url: '', url: '',
type: {
id: '-1',
name: '',
},
} satisfies ProductDocumentView; } satisfies ProductDocumentView;
} }
@ -184,6 +193,8 @@ export function toProductDocumentView(
const trans = document.translations?.[0]; const trans = document.translations?.[0];
const typeView = toDocumentTypeView(document.type ?? null);
return { return {
id: item.id.toString(), id: item.id.toString(),
fileId: file?.id ?? '', fileId: file?.id ?? '',
@ -191,6 +202,7 @@ export function toProductDocumentView(
size: file?.filesize ?? 0, size: file?.filesize ?? 0,
title: trans?.title ?? '', title: trans?.title ?? '',
url: url, url: url,
type: typeView,
} satisfies ProductDocumentView; } satisfies ProductDocumentView;
}); });
} }

View File

@ -12,13 +12,16 @@ describe('converters', () => {
summary: 'High efficiency', summary: 'High efficiency',
description: 'Detailed description', description: 'Detailed description',
type: 'pump', type: 'pump',
cover: 'rand-om__-uuid-1234',
}; };
const result = converters.products(item); const result = converters.products(item);
expect(result).toEqual({ expect(result).toEqual({
id: 1, id: 1,
type: 'product', sectionType: 'product',
title: 'Hydraulic Pump', title: 'Hydraulic Pump',
summary: 'High efficiency', summary: 'High efficiency',
type: 'pump',
thumbnail: '/api/assets/rand-om__-uuid-1234',
}); });
}); });
@ -29,13 +32,16 @@ describe('converters', () => {
summary: 'Effective solution', summary: 'Effective solution',
content: 'Detailed content', content: 'Detailed content',
type: 'Type A', type: 'Type A',
cover: 'rand-om__-uuid-5678',
}; };
const result = converters.solutions(item); const result = converters.solutions(item);
expect(result).toEqual({ expect(result).toEqual({
id: 1, id: 1,
type: 'solution', sectionType: 'solution',
title: 'Solution A', title: 'Solution A',
summary: 'Effective solution', summary: 'Effective solution',
type: 'Type A',
thumbnail: '/api/assets/rand-om__-uuid-5678',
}); });
}); });
@ -47,13 +53,15 @@ describe('converters', () => {
'This is a detailed explanation of how to use the product effectively.', 'This is a detailed explanation of how to use the product effectively.',
products: ['Product A'], products: ['Product A'],
product_types: ['Type A'], product_types: ['Type A'],
type: 'Question Type',
}; };
const result = converters.questions(item); const result = converters.questions(item);
expect(result).toEqual({ expect(result).toEqual({
id: 1, id: 1,
title: 'How to use product?', title: 'How to use product?',
summary: '', summary: undefined,
type: 'question', type: 'Question Type',
sectionType: 'question',
}); });
}); });
@ -64,13 +72,15 @@ describe('converters', () => {
products: ['Product A'], products: ['Product A'],
product_types: ['Type A'], product_types: ['Type A'],
fileUUID: 'TEST-UUID', fileUUID: 'TEST-UUID',
type: 'manual',
}; };
const result = converters.product_documents(item); const result = converters.product_documents(item);
expect(result).toEqual({ expect(result).toEqual({
id: 'TEST-UUID', id: 'TEST-UUID',
title: 'User Manual', title: 'User Manual',
summary: '', summary: undefined,
type: 'document', sectionType: 'document',
type: 'manual',
}); });
}); });
}); });

View File

@ -6,31 +6,35 @@ export const converters: {
} = { } = {
products: (item: MeiliIndexMap['products']): SearchItemView => ({ products: (item: MeiliIndexMap['products']): SearchItemView => ({
id: item.id, id: item.id,
type: 'product', sectionType: 'product',
title: item.name, title: item.name,
summary: item.summary, summary: item?.summary,
type: item?.type,
thumbnail: item?.cover ? `/api/assets/${item.cover}` : undefined,
}), }),
solutions: (item: MeiliIndexMap['solutions']): SearchItemView => ({ solutions: (item: MeiliIndexMap['solutions']): SearchItemView => ({
id: item.id, id: item.id,
type: 'solution', sectionType: 'solution',
title: item.title, title: item.title,
summary: item.summary, summary: item?.summary,
type: item?.type,
thumbnail: item?.cover ? `/api/assets/${item.cover}` : undefined,
}), }),
questions: (item: MeiliIndexMap['questions']): SearchItemView => ({ questions: (item: MeiliIndexMap['questions']): SearchItemView => ({
id: item.id, id: item.id,
type: 'question', sectionType: 'question',
title: item.title, title: item.title,
summary: '', type: item?.type,
}), }),
product_documents: ( product_documents: (
item: MeiliIndexMap['product_documents'] item: MeiliIndexMap['product_documents']
): SearchItemView => ({ ): SearchItemView => ({
id: item.fileUUID || item.id, id: item.fileUUID || item.id,
type: 'document', sectionType: 'document',
title: item.title, title: item.title,
summary: '', type: item?.type,
}), }),
}; };

View File

@ -9,13 +9,16 @@ export interface MeiliProductIndex {
name: string; name: string;
/** 产品简介 **/ /** 产品简介 **/
summary: string; summary?: string;
/** 产品详情 **/ /** 产品详情 **/
description: string; description?: string;
/** 产品类型 **/ /** 产品类型 **/
type: string; type?: string;
/** 产品缩略图 **/
cover?: string;
} }
/** /**
@ -29,13 +32,16 @@ export interface MeiliSolutionIndex {
title: string; title: string;
/** 解决方案摘要 **/ /** 解决方案摘要 **/
summary: string; summary?: string;
/** 解决方案内容 **/ /** 解决方案内容 **/
content: string; content?: string;
/** 解决方案类型 **/ /** 解决方案类型 **/
type: string; type?: string;
/** 解决方案缩略图 **/
cover?: string;
} }
/** /**
@ -49,7 +55,10 @@ export interface MeiliQuestionIndex {
title: string; title: string;
/** 问题内容 **/ /** 问题内容 **/
content: string; content?: string;
/** 问题类型 **/
type?: string;
/** 相关产品 **/ /** 相关产品 **/
products: string[]; products: string[];
@ -68,6 +77,9 @@ export interface MeiliProductDocumentIndex {
/** 文档标题 **/ /** 文档标题 **/
title: string; title: string;
/** 文档类型 **/
type?: string;
/** 相关产品 **/ /** 相关产品 **/
products: string[]; products: string[];

View File

@ -1,3 +1,5 @@
import type { DocumentTypeView } from './document-list-view';
/** /**
* 产品图片视图模型 * 产品图片视图模型
* 用于产品详情页(/products/[slug])中的产品图片数据结构 * 用于产品详情页(/products/[slug])中的产品图片数据结构
@ -73,6 +75,9 @@ export interface ProductDocumentView {
/** 文档大小 **/ /** 文档大小 **/
size: number; size: number;
/** 文档类型 **/
type: DocumentTypeView;
/** 文档链接 **/ /** 文档链接 **/
url: string; url: string;
} }

View File

@ -3,11 +3,17 @@ export interface SearchItemView {
id: number | string; id: number | string;
/** 条目类型 **/ /** 条目类型 **/
type: 'product' | 'solution' | 'question' | 'document'; sectionType: 'product' | 'solution' | 'question' | 'document';
/** 条目标题 **/ /** 条目标题 **/
title: string; title: string;
/** 条目摘要 **/ /** 条目摘要 **/
summary: string; summary?: string;
/** 条目分类 **/
type?: string;
/** 条目预览图 **/
thumbnail?: string;
} }