refactor: 重构搜索页
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m56s
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m56s
- 提取页面部分为SearchHeader与SearchTabs组件
This commit is contained in:
49
app/components/pages/search/SearchTabs.vue
Normal file
49
app/components/pages/search/SearchTabs.vue
Normal 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>
|
||||
Reference in New Issue
Block a user