Skip to content

Commit

Permalink
fix(projects): 修复搜索菜单时title可能为空的情况
Browse files Browse the repository at this point in the history
  • Loading branch information
yanbowe authored and buqiyuan committed Jan 3, 2022
1 parent ddedca2 commit 377a416
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/layout/header/components/search/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@
inputRef.value?.focus();
}
});
const getTitle = (title) => {
return typeof title === 'string' ? title : title?.['zh_CN'];
};
/** 查询 */
function search() {
resultOptions.value = menusList.value.filter((menu) => {
const title = menu.meta?.title as string;
const title = getTitle(menu.meta?.title);
return (
keyword.value &&
title.toLocaleLowerCase().includes(keyword.value.toLocaleLowerCase().trim())
title?.toLocaleLowerCase().includes(keyword.value.toLocaleLowerCase().trim())
);
});
if (resultOptions.value?.length > 0) {
Expand All @@ -90,6 +95,7 @@
activePath.value = '';
}
}
/** 将路由转换成菜单列表 */
function transformRouteToList(routes: RouteRecordRaw[], treeMap: RouteRecordRaw[] = []) {
if (routes && routes.length === 0) return [];
Expand Down
1 change: 1 addition & 0 deletions src/router/staticModules/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const errorRoute: RouteRecordRaw = {
meta: {
title: '404',
icon: 'UserOutlined',
hideInMenu: true,
},
component: () => import(/* webpackChunkName: "404" */ '@/views/shared/error/404.vue'),
},
Expand Down

0 comments on commit 377a416

Please sign in to comment.