fix: 修复搜索显示异常的问题
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { fetchHistory as fetchHistoryApi } from '@/api/history';
|
import { fetchHistory as fetchHistoryApi } from '@/api/history';
|
||||||
import { hotSearch } from '@/api/home';
|
import { getSearchInfo } from '@/api/home/search';
|
||||||
import type { HotSearch } from '@/api/types/hotSearch';
|
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
// function useFetchKeywordResult(keyword: string) {
|
// function useFetchKeywordResult(keyword: string) {
|
||||||
@@ -36,4 +35,25 @@ function fetchHistory() {
|
|||||||
return { history };
|
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);
|
const dirty = ref(true);
|
||||||
// loading 状态
|
// loading 状态
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
// 模板列表
|
// 模板列表0
|
||||||
const templates = ref();
|
const templates = ref();
|
||||||
// banners
|
// banners
|
||||||
const banners = ref();
|
const banners = ref();
|
||||||
@@ -26,15 +26,15 @@ const banners = ref();
|
|||||||
async function handleSearch() {
|
async function handleSearch() {
|
||||||
// loading 状态开启
|
// loading 状态开启
|
||||||
// loading.value = true;
|
// loading.value = true;
|
||||||
const params = {
|
// const params = {
|
||||||
page: index.value,
|
// page: index.value,
|
||||||
per_page: pageCount.value,
|
// per_page: pageCount.value,
|
||||||
group_id: 0,
|
// group_id: 0,
|
||||||
project_name: keyword.value
|
// project_name: keyword.value
|
||||||
};
|
// };
|
||||||
const res = await getSurveysPage(params);
|
// const res = await getSurveysPage(params);
|
||||||
// 排除返回出错的异常
|
// 排除返回出错的异常
|
||||||
if (res.data.code !== 0) return;
|
// if (res.data.code !== 0) return;
|
||||||
|
|
||||||
// 处理模板搜索和banner的信息
|
// 处理模板搜索和banner的信息
|
||||||
const info = await getSearchInfo(keyword.value as string);
|
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 = 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;
|
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;
|
loading.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param value
|
|
||||||
*/
|
|
||||||
function updatePageCount(value: number) {
|
|
||||||
pageCount.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当 keyword 变动的时候,标记脏数据
|
// 当 keyword 变动的时候,标记脏数据
|
||||||
watch(keyword, async () => {
|
watch(keyword, async () => {
|
||||||
dirty.value = true;
|
dirty.value = true;
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ onUnmounted(() => {
|
|||||||
</div>
|
</div>
|
||||||
<!-- 广告区域 -->
|
<!-- 广告区域 -->
|
||||||
<div class="banner">
|
<div class="banner">
|
||||||
<layout title="推送内容">
|
<layout title="推送内容" v-if="banners?.length > 0 && keyword">
|
||||||
<template #title>
|
<template #title>
|
||||||
<span class="title">推送内容</span>
|
<span class="title">推送内容</span>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
Reference in New Issue
Block a user