refactor: 优化搜索相关组件和逻辑

1. 重构搜索历史数据结构,从Set改为Array类型
2. 优化MineSurvey组件,限制显示3条问卷项
3. 修复搜索框清空时未重置banner的问题
4. 添加关键词变化时自动触发搜索
5. 优化搜索结果页面的布局和样式
6. 添加useSearch hook文件
This commit is contained in:
Huangzhe
2025-05-19 16:51:23 +08:00
parent 3b0c71989b
commit ee887dadb4
6 changed files with 71 additions and 16 deletions

View File

@@ -0,0 +1,39 @@
import { fetchHistory as fetchHistoryApi } from '@/api/history';
import { hotSearch } from '@/api/home';
import type { HotSearch } from '@/api/types/hotSearch';
import { ref } from 'vue';
// function useFetchKeywordResult(keyword: string) {
// // 历史列表
// const history = ref<Set<string>>(new Set());
// // 从服务器接受的列表内容
// const list = ref<HotSearch[]>([]);
// const { data } = await hotSearch();
// list.value = data.data;
// return { list };
// }
// 初始化历史
function fetchHistory() {
const history = ref<string[]>([]);
// 屏蔽从storage获取记录的方式
// const historyStr = localStorage.getItem('history')
// if (historyStr) {
// history.value = new Set(JSON.parse(historyStr))
// } else {
// history.value = new Set()
// }
fetchHistoryApi().then(({ data }) => {
data.data.forEach((item: { id: number; keyword: string }) => {
history.value.push(item.keyword);
});
});
return { history };
}
export { fetchHistory };