refactor: 优化搜索相关组件和逻辑
1. 重构搜索历史数据结构,从Set改为Array类型 2. 优化MineSurvey组件,限制显示3条问卷项 3. 修复搜索框清空时未重置banner的问题 4. 添加关键词变化时自动触发搜索 5. 优化搜索结果页面的布局和样式 6. 添加useSearch hook文件
This commit is contained in:
39
src/hooks/request/useSearch.ts
Normal file
39
src/hooks/request/useSearch.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user