From 772c25a41bbe758a4e30bf9895cf7f8e051098ca Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Sat, 25 Oct 2025 13:54:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=A1=B5=E9=83=A8=E5=88=86=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 对于搜索页中的‘相关问题’与‘文档资料’,修正条目标签显示 - 调整页面刷新逻辑: 将用户刷新有PerformSearch改为useAsyncData的Refresh机制 --- app/components/SearchResults.vue | 3 ++- app/pages/search.vue | 33 ++------------------------------ i18n/locales/en.json | 3 ++- i18n/locales/zh.json | 3 ++- 4 files changed, 8 insertions(+), 34 deletions(-) diff --git a/app/components/SearchResults.vue b/app/components/SearchResults.vue index 3bd57e3..f130410 100644 --- a/app/components/SearchResults.vue +++ b/app/components/SearchResults.vue @@ -86,7 +86,8 @@ const indexLabels = computed>(() => ({ product: t('search.sections.product'), solution: t('search.sections.solution'), - support: t('search.sections.support'), + question: t('search.sections.faq'), + document: t('search.sections.document'), default: t('search.sections.default'), })); diff --git a/app/pages/search.vue b/app/pages/search.vue index f1390b4..fc9404f 100644 --- a/app/pages/search.vue +++ b/app/pages/search.vue @@ -103,12 +103,12 @@ // 搜索相关 const { search } = useMeilisearch(); const keyword = ref(''); - const activeRequestId = ref(0); const { data: sections, pending: loading, error, + refresh, } = await useAsyncData( () => `search-${directusLocale}-${route.query.query ?? ''}`, async () => { @@ -172,33 +172,6 @@ }); }; - const performSearch = async (value: string) => { - activeRequestId.value += 1; - const requestId = activeRequestId.value; - const trimmed = value.trim(); - if (!trimmed) { - if (requestId === activeRequestId.value) { - sections.value = []; - loading.value = false; - } - return; - } - - try { - const results = await search(trimmed, { limit: 12 }, directusLocale); - if (requestId === activeRequestId.value) { - sections.value = results; - } - console.log('hits:', hits.value); - console.log(resultCount.value); - } catch (error) { - console.error('Failed to perform search', error); - if (requestId === activeRequestId.value) { - sections.value = []; - } - } - }; - const handleClear = () => { keyword.value = ''; sections.value = []; @@ -214,9 +187,7 @@ async (newQuery) => { if (typeof newQuery === 'string' && newQuery.trim()) { keyword.value = newQuery; - await performSearch(newQuery); - } else { - loading.value = false; + await refresh(); } } ); diff --git a/i18n/locales/en.json b/i18n/locales/en.json index 0aa249b..336a26f 100644 --- a/i18n/locales/en.json +++ b/i18n/locales/en.json @@ -14,7 +14,8 @@ "sections": { "product": "Products", "solution": "Solutions", - "support": "Support", + "faq": "Faqs", + "document": "Documents", "default": "Other" } }, diff --git a/i18n/locales/zh.json b/i18n/locales/zh.json index 4ab70e0..b7f1163 100644 --- a/i18n/locales/zh.json +++ b/i18n/locales/zh.json @@ -14,7 +14,8 @@ "sections": { "product": "产品", "solution": "解决方案", - "support": "服务支持", + "faq": "相关问题", + "document": "文档资料", "default": "其他内容" } },