Merge pull request #286 from yanbowe/main

perf(components): Optimize internationalized menu search code
This commit is contained in:
Soybean 2023-10-18 22:42:35 +08:00 committed by GitHub
commit ecbb96f3a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,20 +84,11 @@ watch(show, async val => {
/** 查询 */ /** 查询 */
function search() { function search() {
resultOptions.value = routeStore.searchMenus.filter(menu => { resultOptions.value = routeStore.searchMenus.filter(menu => {
return ( const trimKeyword = keyword.value.toLocaleLowerCase().trim();
(keyword.value && const title = (menu.meta.i18nTitle ? $t(menu.meta.i18nTitle) : menu.meta.title).toLocaleLowerCase();
menu.meta?.i18nTitle && return trimKeyword && title.includes(trimKeyword);
$t(menu.meta?.i18nTitle)
.toLocaleLowerCase()
.includes(keyword.value.toLocaleLowerCase().trim())) ||
menu.meta?.title.toLocaleLowerCase().includes(keyword.value.toLocaleLowerCase().trim())
);
}); });
if (resultOptions.value?.length > 0) { activePath.value = resultOptions.value[0]?.path ?? '';
activePath.value = resultOptions.value[0].path;
} else {
activePath.value = '';
}
} }
function handleClose() { function handleClose() {