refactor: 重构faq与document页

- 将筛选器提取为单独的组件ProductFilters
This commit is contained in:
2025-10-29 16:42:48 +08:00
parent c4e797500f
commit 5f78c888a2
3 changed files with 137 additions and 140 deletions

View File

@ -10,50 +10,13 @@
<app-breadcrumb class="breadcrumb" :items="breadcrumbItems" />
</div>
<div class="question-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"
/>
<question-list :questions="filteredQuestions" />
</div>
</div>
@ -61,10 +24,14 @@
</template>
<script setup lang="ts">
import { Search } from '@element-plus/icons-vue';
const localePath = useLocalePath();
const filters = reactive({
selectedType: null as number | null,
selectedProduct: null as number | null,
keyword: '',
});
const breadcrumbItems = [
{ label: $t('navigation.home'), to: localePath('/') },
{ label: $t('navigation.support'), to: localePath('/support') },
@ -77,11 +44,6 @@
() => data.value.map((item) => toQuestionListView(item)) ?? null
);
const keyword = ref('');
const selectedType = ref<number | null>(null);
const selectedProduct = ref<number | null>(null);
const productTypeOptions = computed(() => {
const types: QuestionListProductType[] = [];
questions.value.forEach((q: QuestionListView) => {
@ -96,12 +58,12 @@
});
const productOptions = computed(() => {
if (!selectedType.value) return [];
if (!filters.selectedType) return [];
const products: QuestionListProduct[] = [];
questions.value.forEach((q: QuestionListView) => {
q.products.forEach((product: QuestionListProduct) => {
if (
product.type.id === selectedType.value &&
product.type.id === filters.selectedType &&
!products.some((p) => p.id === product.id)
) {
products.push(product);
@ -113,30 +75,33 @@
const filteredQuestions = computed(() => {
return questions.value.filter((question: QuestionListView) => {
const matchProduct = selectedProduct.value
const matchProduct = filters.selectedProduct
? question.products?.some(
(product: QuestionListProduct) =>
product.id === selectedProduct.value
product.id === filters.selectedProduct
)
: selectedType.value
: filters.selectedType
? question.products?.some(
(product: QuestionListProduct) =>
product.type.id === selectedType.value
product.type.id === filters.selectedType
)
: true;
const matchKeyword = keyword.value
? (question.title && question.title.includes(keyword.value)) ||
(question.content && question.content.includes(keyword.value))
const matchKeyword = filters.keyword
? (question.title && question.title.includes(filters.keyword)) ||
(question.content && question.content.includes(filters.keyword))
: true;
return matchProduct && matchKeyword;
});
});
watch(selectedType, () => {
selectedProduct.value = null;
});
watch(
() => filters.selectedType,
() => {
filters.selectedProduct = null;
}
);
watch(data, (newVal) => {
console.log('useAsyncData updated:', newVal);
@ -171,24 +136,7 @@
margin-left: auto;
}
.question-category {
padding: 0rem 2rem;
gap: 4px;
margin-bottom: 0.5rem;
}
.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;
}
</style>