Skip to content

Commit

Permalink
perf(components): Optimize internationalized menu search code
Browse files Browse the repository at this point in the history
  • Loading branch information
yanbowe committed Oct 18, 2023
1 parent 04d3330 commit 8c1ef4b
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/layouts/common/global-search/components/search-modal.vue
Expand Up @@ -84,14 +84,9 @@ watch(show, async val => {
/** 查询 */
function search() {
resultOptions.value = routeStore.searchMenus.filter(menu => {
return (
(keyword.value &&
menu.meta?.i18nTitle &&
$t(menu.meta?.i18nTitle)
.toLocaleLowerCase()
.includes(keyword.value.toLocaleLowerCase().trim())) ||
menu.meta?.title.toLocaleLowerCase().includes(keyword.value.toLocaleLowerCase().trim())
);
const trimKeyword = keyword.value.toLocaleLowerCase().trim();
const title = (menu.meta.i18nTitle ? $t(menu.meta.i18nTitle) : menu.meta.title).toLocaleLowerCase();
return trimKeyword && title.includes(trimKeyword);
});
if (resultOptions.value?.length > 0) {
activePath.value = resultOptions.value[0].path;
Expand Down

0 comments on commit 8c1ef4b

Please sign in to comment.