From 4e6f70280c2cac1d95aa7da1a137c6cfe1c27b65 Mon Sep 17 00:00:00 2001 From: ray_wuhao <443547225@qq.com> Date: Tue, 20 Jun 2023 14:10:35 +0800 Subject: [PATCH] =?UTF-8?q?v3.3.6=E4=B8=80=E4=BA=9B=E5=B0=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ src/layout/components/Menu/index.tsx | 14 +++++++++++++- .../SiderBar/Components/GlobalSeach/index.tsx | 16 +++++++++++++++- src/locales/helper.ts | 15 +++++++++++++-- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88af7502..852a6886 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ - 修复了鉴权方法的 bug - 更新了 router permission 方法(路由守卫) - 补充了一些模块文档 +- 搜索支持以菜单模块的 icon 进行渲染,如果为空则以 icon table 默认填充 + +### Fixes + +- 修复选中所搜结果后,菜单不能默认展开 bug ### 补充 diff --git a/src/layout/components/Menu/index.tsx b/src/layout/components/Menu/index.tsx index 32c3f5a8..20e655c1 100644 --- a/src/layout/components/Menu/index.tsx +++ b/src/layout/components/Menu/index.tsx @@ -7,15 +7,25 @@ import { useMenu } from '@/store' import { MENU_COLLAPSED_CONFIG, MENU_ACCORDION } from '@/appConfig/appConfig' import { useVueRouter } from '@/router/helper/useVueRouter' +import type { MenuInst } from 'naive-ui' + const LayoutMenu = defineComponent({ name: 'LayoutMenu', setup() { + const menuRef = ref(null) + const menuStore = useMenu() const { router } = useVueRouter() const { menuModelValueChange, collapsedMenu } = menuStore const modelMenuKey = computed({ - get: () => menuStore.menuKey, + get: () => { + nextTick().then(() => { + menuRef.value?.showOption?.(menuStore.menuKey as string) + }) + + return menuStore.menuKey + }, // eslint-disable-next-line @typescript-eslint/no-empty-function set: () => {}, }) @@ -41,6 +51,7 @@ const LayoutMenu = defineComponent({ collapsedMenu, sideBarLogo, handleSideBarLogoClick, + menuRef, } }, render() { @@ -79,6 +90,7 @@ const LayoutMenu = defineComponent({ '' )} { + const { icon } = meta + + if (typeof icon === 'string') { + return + } else if (typeof icon === 'function') { + return () => icon + } else { + return + } + } + onMounted(() => { on(window, 'keydown', registerKeyboard) }) @@ -134,6 +147,7 @@ const GlobalSeach = defineComponent({ tiptextOptions, handleSearchMenuOptions: debounce(handleSearchMenuOptions, 300), handleSearchItemClick, + RenderPreIcon, } }, render() { @@ -167,7 +181,7 @@ const GlobalSeach = defineComponent({ }} >
- + {this.RenderPreIcon(curr.meta)}
{curr.breadcrumbLabel} diff --git a/src/locales/helper.ts b/src/locales/helper.ts index 45f07435..c644917d 100644 --- a/src/locales/helper.ts +++ b/src/locales/helper.ts @@ -16,7 +16,6 @@ * - getAppLocales: 获取所有语言 */ -/* eslint-disable @typescript-eslint/no-explicit-any */ import { set } from 'lodash-es' import { zhCN, dateZhCN } from 'naive-ui' // 导入 `naive ui` 中文包 import { getCache } from '@use-utils/cache' @@ -25,7 +24,19 @@ import { APP_CATCH_KEY } from '@/appConfig/appConfig' import type { Recordable } from '@/types/type-utils' -export const mergeMessage = (langs: Record, prefix = 'lang') => { +/** + * + * @param langs 语言包 + * @param prefix 语言包前缀 + * + * @remark 合并处理语言包内容, prefix 必填 + */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const mergeMessage = (langs: Record, prefix: string) => { + if (!prefix) { + throw new Error('Expected prefix to be string, got undefined instead') + } + const langsGather: Recordable = {} Object.keys(langs).forEach((key) => {