From 2877e36155ca9be1ab6dd4442589e6adf6883f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9D=92=E6=9C=A8?= <31089228+StringKe@users.noreply.github.com> Date: Mon, 8 Aug 2022 22:02:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=94=AF=E4=B8=80=20?= =?UTF-8?q?id=20=E7=94=9F=E6=88=90=E5=8F=82=E6=95=B0=E7=9A=84=E8=A6=86?= =?UTF-8?q?=E7=9B=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/react/src/runtime/index.tsx | 8 +++++++- packages/vue-next/src/runtime/index.tsx | 10 ++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/react/src/runtime/index.tsx b/packages/react/src/runtime/index.tsx index 01687f362..6d4c09559 100644 --- a/packages/react/src/runtime/index.tsx +++ b/packages/react/src/runtime/index.tsx @@ -86,6 +86,9 @@ export interface IIconConfig { innerFillColor: string; }; }; + + // 唯一ID 生成函数 + guid?: () => string, } // 图标基础属性 @@ -232,7 +235,10 @@ export function IconWrapper(name: string, rtl: boolean, render: IconRender): Ico const ICON_CONFIGS = useContext(IconContext); - const id = useMemo(guid, []); + let id = guid(); + if (ICON_CONFIGS.guid && typeof ICON_CONFIGS.guid == 'function') { + id = ICON_CONFIGS.guid(); + } const svgProps = IconConverter(id, { size, diff --git a/packages/vue-next/src/runtime/index.tsx b/packages/vue-next/src/runtime/index.tsx index 59fcc47c0..13f27c4e3 100644 --- a/packages/vue-next/src/runtime/index.tsx +++ b/packages/vue-next/src/runtime/index.tsx @@ -85,6 +85,9 @@ export interface IIconConfig { innerFillColor: string; }; }; + + // 唯一ID 生成函数 + guid?: () => string, } // 图标基础属性 @@ -218,10 +221,13 @@ export function IconWrapper(name: string, rtl: boolean, render: IconRender): Ico props: ['size', 'strokeWidth', 'strokeLinecap', 'strokeLinejoin', 'theme', 'fill', 'spin'], setup: (props) => { - const id = guid(); - const ICON_CONFIGS = inject(IconContext, DEFAULT_ICON_CONFIGS); + let id = guid(); + if (ICON_CONFIGS.guid && typeof ICON_CONFIGS.guid == 'function') { + id = ICON_CONFIGS.guid(); + } + return () => { const {