refactor: 重构faq与document页
- 将筛选器提取为单独的组件ProductFilters
This commit is contained in:
@ -9,50 +9,12 @@
|
||||
<h1 class="page-title">{{ $t('navigation.documents') }}</h1>
|
||||
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
|
||||
</div>
|
||||
<div class="document-category">
|
||||
<el-row :gutter="12">
|
||||
<el-col :span="8">
|
||||
<span class="select-label">产品分类</span>
|
||||
<el-select
|
||||
v-model="selectedType"
|
||||
placeholder="选择产品类型"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="type in productTypeOptions"
|
||||
:key="type.id"
|
||||
:label="type.name"
|
||||
:value="type.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<span class="select-label">产品系列</span>
|
||||
<el-select
|
||||
v-model="selectedProduct"
|
||||
placeholder="选择系列产品"
|
||||
clearable
|
||||
>
|
||||
<el-option
|
||||
v-for="product in productOptions"
|
||||
:key="product.id"
|
||||
:label="product.name"
|
||||
:value="product.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<span class="select-label">关键词</span>
|
||||
<el-input
|
||||
v-model="keyword"
|
||||
placeholder="输入关键词..."
|
||||
clearable
|
||||
:prefix-icon="Search"
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
<div class="page-content">
|
||||
<product-filter
|
||||
v-model="filters"
|
||||
:product-type-options="productTypeOptions"
|
||||
:product-options="productOptions"
|
||||
/>
|
||||
<document-list :documents="filteredDocuments" />
|
||||
</div>
|
||||
</div>
|
||||
@ -60,8 +22,6 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { Search } from '@element-plus/icons-vue';
|
||||
|
||||
const localePath = useLocalePath();
|
||||
const breadcrumbItems = [
|
||||
{ label: $t('navigation.home'), to: localePath('/') },
|
||||
@ -69,17 +29,18 @@
|
||||
{ label: $t('navigation.documents') },
|
||||
];
|
||||
|
||||
const filters = reactive({
|
||||
selectedType: null as number | null,
|
||||
selectedProduct: null as number | null,
|
||||
keyword: '',
|
||||
});
|
||||
|
||||
const { data, pending, error } = await useDocumentList();
|
||||
|
||||
const documents = computed(
|
||||
() => data?.value.map((item) => toDocumentListView(item)) ?? []
|
||||
);
|
||||
|
||||
const keyword = ref('');
|
||||
|
||||
const selectedType = ref<number | null>(null);
|
||||
const selectedProduct = ref<number | null>(null);
|
||||
|
||||
const productTypeOptions = computed(() => {
|
||||
const types: DocumentListProductType[] = [];
|
||||
documents.value.forEach((doc: DocumentListView) => {
|
||||
@ -95,13 +56,13 @@
|
||||
});
|
||||
|
||||
const productOptions = computed(() => {
|
||||
if (!selectedType.value) return [];
|
||||
if (!filters.selectedType) return [];
|
||||
const products: DocumentListProduct[] = [];
|
||||
|
||||
documents.value.forEach((doc: DocumentListView) => {
|
||||
doc.products?.forEach((product: DocumentListProduct) => {
|
||||
if (
|
||||
product.type.id === selectedType.value &&
|
||||
product.type.id === filters.selectedType &&
|
||||
!products.some((item) => item.id === product.id)
|
||||
) {
|
||||
products.push(product);
|
||||
@ -114,29 +75,32 @@
|
||||
|
||||
const filteredDocuments = computed(() =>
|
||||
documents.value.filter((doc: DocumentListView) => {
|
||||
const matchProduct = selectedProduct.value
|
||||
const matchProduct = filters.selectedProduct
|
||||
? doc.products?.some(
|
||||
(product: DocumentListProduct) =>
|
||||
product.id === selectedProduct.value
|
||||
product.id === filters.selectedProduct
|
||||
)
|
||||
: selectedType.value
|
||||
: filters.selectedType
|
||||
? doc.products?.some(
|
||||
(product: DocumentListProduct) =>
|
||||
product.type?.id === selectedType.value
|
||||
product.type?.id === filters.selectedType
|
||||
)
|
||||
: true;
|
||||
|
||||
const matchKeyword = keyword.value
|
||||
? doc.title && doc.title.includes(keyword.value)
|
||||
const matchKeyword = filters.keyword
|
||||
? doc.title && doc.title.includes(filters.keyword)
|
||||
: true;
|
||||
|
||||
return matchProduct && matchKeyword;
|
||||
})
|
||||
);
|
||||
|
||||
watch(selectedType, () => {
|
||||
selectedProduct.value = null;
|
||||
});
|
||||
watch(
|
||||
() => filters.selectedType,
|
||||
() => {
|
||||
filters.selectedProduct = null;
|
||||
}
|
||||
);
|
||||
|
||||
watch(documents, (value) => {
|
||||
console.log(value);
|
||||
|
||||
Reference in New Issue
Block a user