fix: 修正搜索页部分错误 #44
@ -86,7 +86,8 @@
|
|||||||
const indexLabels = computed<Record<string, string>>(() => ({
|
const indexLabels = computed<Record<string, string>>(() => ({
|
||||||
product: t('search.sections.product'),
|
product: t('search.sections.product'),
|
||||||
solution: t('search.sections.solution'),
|
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'),
|
default: t('search.sections.default'),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|||||||
@ -103,12 +103,12 @@
|
|||||||
// 搜索相关
|
// 搜索相关
|
||||||
const { search } = useMeilisearch();
|
const { search } = useMeilisearch();
|
||||||
const keyword = ref('');
|
const keyword = ref('');
|
||||||
const activeRequestId = ref(0);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: sections,
|
data: sections,
|
||||||
pending: loading,
|
pending: loading,
|
||||||
error,
|
error,
|
||||||
|
refresh,
|
||||||
} = await useAsyncData(
|
} = await useAsyncData(
|
||||||
() => `search-${directusLocale}-${route.query.query ?? ''}`,
|
() => `search-${directusLocale}-${route.query.query ?? ''}`,
|
||||||
async () => {
|
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 = () => {
|
const handleClear = () => {
|
||||||
keyword.value = '';
|
keyword.value = '';
|
||||||
sections.value = [];
|
sections.value = [];
|
||||||
@ -214,9 +187,7 @@
|
|||||||
async (newQuery) => {
|
async (newQuery) => {
|
||||||
if (typeof newQuery === 'string' && newQuery.trim()) {
|
if (typeof newQuery === 'string' && newQuery.trim()) {
|
||||||
keyword.value = newQuery;
|
keyword.value = newQuery;
|
||||||
await performSearch(newQuery);
|
await refresh();
|
||||||
} else {
|
|
||||||
loading.value = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@ -14,7 +14,8 @@
|
|||||||
"sections": {
|
"sections": {
|
||||||
"product": "Products",
|
"product": "Products",
|
||||||
"solution": "Solutions",
|
"solution": "Solutions",
|
||||||
"support": "Support",
|
"faq": "Faqs",
|
||||||
|
"document": "Documents",
|
||||||
"default": "Other"
|
"default": "Other"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -14,7 +14,8 @@
|
|||||||
"sections": {
|
"sections": {
|
||||||
"product": "产品",
|
"product": "产品",
|
||||||
"solution": "解决方案",
|
"solution": "解决方案",
|
||||||
"support": "服务支持",
|
"faq": "相关问题",
|
||||||
|
"document": "文档资料",
|
||||||
"default": "其他内容"
|
"default": "其他内容"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user