Files
jinshen-website/app/pages/support/documents.vue
R2m1liA 63cdff9c41
All checks were successful
deploy to server / build-and-deploy (push) Successful in 3m10s
feat: 为文档库添加文档类型显示功能
- 功能添加:在文档列表中,当未指定文档类型时,在标题右侧显示文档类型
- 查询更改:产品查询添加文档类型查询方法
- mapper更改:productDocumentView添加文档类型
2025-12-05 17:18:48 +08:00

232 lines
5.4 KiB
Vue

<template>
<div class="page-container">
<div v-if="pending">
<el-skeleton :rows="5" animated />
</div>
<div v-else>
<support-tabs model-value="documents" />
<div class="page-header">
<h1 class="page-title">{{ $t('navigation.documents') }}</h1>
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
</div>
<div class="page-content">
<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"
/>
</div>
</div>
</div>
</template>
<script setup lang="ts">
const localePath = useLocalePath();
const breadcrumbItems = [
{ label: $t('navigation.home'), to: localePath('/') },
{ label: $t('navigation.support'), to: localePath('/support') },
{ label: $t('navigation.documents') },
];
const filters = reactive({
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) => {
doc.products?.forEach((product: DocumentListProduct) => {
const productType = product.type;
if (!types.some((item) => item.id === productType.id)) {
types.push(productType);
}
});
});
return types;
});
const productOptions = computed(() => {
if (!filters.selectedProductType) return [];
const products: DocumentListProduct[] = [];
documents.value.forEach((doc: DocumentListView) => {
doc.products?.forEach((product: DocumentListProduct) => {
if (
product.type.id === filters.selectedProductType &&
!products.some((item) => item.id === product.id)
) {
products.push(product);
}
});
});
return products;
});
const filteredDocuments = computed(() => {
const fuzzyMatchedDocuments = fuzzyMatch(documents.value, {
keyword: filters.keyword,
keys: ['title'],
threshold: 0.6,
});
return fuzzyMatchedDocuments.filter((doc: DocumentListView) => {
const matchProduct = filters.selectedProduct
? doc.products?.some(
(product: DocumentListProduct) =>
product.id === filters.selectedProduct
)
: filters.selectedProductType
? doc.products?.some(
(product: DocumentListProduct) =>
product.type?.id === filters.selectedProductType
)
: true;
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.selectedProductType,
() => {
filters.selectedProduct = null;
}
);
watch(error, (value) => {
if (value) {
logger.error('数据获取失败: ', value);
}
});
const pageTitle = $t('page-title.documents');
usePageSeo({
title: pageTitle,
});
</script>
<style scoped>
.page-container {
max-width: 1200px;
margin: 0 auto;
}
.page-header {
display: flex;
padding: 2rem 2rem 0rem;
}
.page-title {
font-size: 2rem;
font-weight: bold;
color: var(--el-color-primary);
margin-bottom: 1rem;
}
.breadcrumb {
margin-left: auto;
}
.page-content {
padding: 1rem 2rem 2rem;
}
.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;
}
.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>