refactor: 重构搜索页
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m56s

- 提取页面部分为SearchHeader与SearchTabs组件
This commit is contained in:
2025-10-29 17:49:20 +08:00
parent 667413dd12
commit 84b99deef6
3 changed files with 129 additions and 146 deletions

View File

@ -0,0 +1,49 @@
<template>
<el-tabs v-model="activeTab">
<el-tab-pane
v-for="tab in tabs"
:key="tab.name"
:label="`${tab.label}(${resultCount[tab.name] || 0})`"
:name="tab.name"
>
<SearchResults
v-model:current-page="currentPage"
:search-items="searchItems"
:category="tab.name === 'all' ? undefined : tab.name"
/>
</el-tab-pane>
</el-tabs>
</template>
<script setup lang="ts">
const props = defineProps<{
// resultCount: Record<string, number>;
searchItems: SearchItemView[];
}>();
const tabs = [
{ name: 'all', label: '全部' },
{ name: 'product', label: '产品' },
{ name: 'solution', label: '解决方案' },
{ name: 'question', label: '相关问题' },
{ name: 'document', label: '文档资料' },
];
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;
}
return map;
});
// 分类控制
const activeTab = ref('all');
// 分页控制
const currentPage = ref(1);
watch(activeTab, () => {
currentPage.value = 1; // 重置页码
});
</script>