fix: 修正搜索页部分错误
All checks were successful
deploy to server / build-and-deploy (push) Successful in 2m59s

- 对于搜索页中的‘相关问题’与‘文档资料’,修正条目标签显示
- 调整页面刷新逻辑: 将用户刷新有PerformSearch改为useAsyncData的Refresh机制
This commit is contained in:
2025-10-25 13:54:34 +08:00
parent 088eee07bf
commit 772c25a41b
4 changed files with 8 additions and 34 deletions

View File

@ -86,7 +86,8 @@
const indexLabels = computed<Record<string, string>>(() => ({
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'),
}));

View File

@ -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();
}
}
);