diff --git a/src/hooks/request/useSearch.ts b/src/hooks/request/useSearch.ts index e3e5f12..35856e2 100644 --- a/src/hooks/request/useSearch.ts +++ b/src/hooks/request/useSearch.ts @@ -1,6 +1,5 @@ import { fetchHistory as fetchHistoryApi } from '@/api/history'; -import { hotSearch } from '@/api/home'; -import type { HotSearch } from '@/api/types/hotSearch'; +import { getSearchInfo } from '@/api/home/search'; import { ref } from 'vue'; // function useFetchKeywordResult(keyword: string) { @@ -36,4 +35,25 @@ function fetchHistory() { return { history }; } -export { fetchHistory }; +// 获取搜索结果 +function fetchSearchResult(keyword: string) { + // 返回三个数据 + // banners my_surveys templates + const banners = ref([]); + const my_surveys = ref([]); + const templates = ref([]); + + getSearchInfo(keyword).then(({ data }) => { + banners.value = data.data.banners; + my_surveys.value = data.data.my_surveys; + templates.value = data.data.templates; + }); + + return { + banners, + my_surveys, + templates + }; +} + +export { fetchHistory, fetchSearchResult }; diff --git a/src/views/HomeSearch/Hooks/useSurveySearch.ts b/src/views/HomeSearch/Hooks/useSurveySearch.ts index beec7f5..a634093 100644 --- a/src/views/HomeSearch/Hooks/useSurveySearch.ts +++ b/src/views/HomeSearch/Hooks/useSurveySearch.ts @@ -18,7 +18,7 @@ const pageCount = ref(5); const dirty = ref(true); // loading 状态 const loading = ref(false); -// 模板列表 +// 模板列表0 const templates = ref(); // banners const banners = ref(); @@ -26,15 +26,15 @@ const banners = ref(); async function handleSearch() { // loading 状态开启 // loading.value = true; - const params = { - page: index.value, - per_page: pageCount.value, - group_id: 0, - project_name: keyword.value - }; - const res = await getSurveysPage(params); + // const params = { + // page: index.value, + // per_page: pageCount.value, + // group_id: 0, + // project_name: keyword.value + // }; + // const res = await getSurveysPage(params); // 排除返回出错的异常 - if (res.data.code !== 0) return; + // if (res.data.code !== 0) return; // 处理模板搜索和banner的信息 const info = await getSearchInfo(keyword.value as string); @@ -43,12 +43,13 @@ async function handleSearch() { // 更新问卷信息 // surveys.value = dirty ? res.data.data : surveys.value.concat(res.data.data); - surveys.value = surveys.value.concat(res.data.data); + surveys.value = info.data.data.my_surveys; + // 数据更新完成之后,脏数据标记清空 dirty.value = false; // 检查是否是最后一页 - lastIndex.value = res.data.meta.last_page === index.value; + // lastIndex.value = info.data.meta.last_page === index.value; } /** @@ -78,14 +79,6 @@ async function updateKeyword(key?: string) { loading.value = true; } -/** - * - * @param value - */ -function updatePageCount(value: number) { - pageCount.value = value; -} - // 当 keyword 变动的时候,标记脏数据 watch(keyword, async () => { dirty.value = true; diff --git a/src/views/HomeSearch/Index.vue b/src/views/HomeSearch/Index.vue index f86ff40..77e0f62 100644 --- a/src/views/HomeSearch/Index.vue +++ b/src/views/HomeSearch/Index.vue @@ -53,7 +53,7 @@ onUnmounted(() => {