fix: 修复搜索显示异常的问题
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -18,7 +18,7 @@ const pageCount = ref<number>(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;
|
||||
|
||||
@@ -53,7 +53,7 @@ onUnmounted(() => {
|
||||
</div>
|
||||
<!-- 广告区域 -->
|
||||
<div class="banner">
|
||||
<layout title="推送内容">
|
||||
<layout title="推送内容" v-if="banners?.length > 0 && keyword">
|
||||
<template #title>
|
||||
<span class="title">推送内容</span>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user