From 9d0f5dc006e2ab864a2148ea98e32f249828c6cd Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2698393+2betop@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:07:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E6=94=B9=E6=88=90=E5=BC=82=E6=AD=A5=E5=90=8E=E9=83=A8=E5=88=86?= =?UTF-8?q?=E9=9D=A2=E6=9D=BF=E5=8C=B9=E9=85=8D=E9=94=99=E8=AF=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#10962)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/factory.tsx | 28 ++++++++++++++++++++++++++-- packages/amis/src/minimal.ts | 17 ++++++++--------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/packages/amis-core/src/factory.tsx b/packages/amis-core/src/factory.tsx index 67ca2faf2..f1cb37c99 100644 --- a/packages/amis-core/src/factory.tsx +++ b/packages/amis-core/src/factory.tsx @@ -47,6 +47,7 @@ export interface RendererBasicConfig { type?: string; alias?: Array; // 别名, 可以绑定多个类型,命中其中一个即可。 name?: string; + origin?: RendererBasicConfig; storeType?: string; defaultProps?: (type: string, schema: any) => any; shouldSyncSuperStore?: ( @@ -222,6 +223,7 @@ export function registerRenderer(config: RendererConfig): RendererConfig { exists.component && exists.component !== Placeholder && config.component && + !exists.origin && !config.override ) { throw new Error( @@ -253,7 +255,24 @@ export function registerRenderer(config: RendererConfig): RendererConfig { renderer.component && renderer.component !== Placeholder ); renderer.type && (renderersTypeMap[renderer.type] = renderer); - (renderer.alias || []).forEach(alias => (renderersTypeMap[alias] = renderer)); + (renderer.alias || []).forEach(alias => { + const fork = { + ...renderer, + type: alias, + name: alias, + alias: undefined, + origin: renderer + }; + + const idx = renderers.findIndex(item => item.name === alias); + if (~idx) { + Object.assign(renderers[idx], fork); + } else { + renderers.push(fork); + } + renderersTypeMap[alias] = fork; + renderersMap[alias] = true; + }); return renderer; } @@ -266,7 +285,12 @@ export function unRegisterRenderer(config: RendererConfig | string) { delete renderersMap[name]; delete renderersTypeMap[renderer.type || '']; - renderer.alias?.forEach(alias => delete renderersTypeMap[alias]); + renderer.alias?.forEach(alias => { + const idx = renderers.findIndex(item => item.name === alias); + idx > -1 && renderers.splice(idx, 1); + delete renderersTypeMap[alias]; + delete renderersMap[alias]; + }); // 清空渲染器定位缓存 Object.keys(cache).forEach(key => { diff --git a/packages/amis/src/minimal.ts b/packages/amis/src/minimal.ts index adbc35715..6c01693d9 100644 --- a/packages/amis/src/minimal.ts +++ b/packages/amis/src/minimal.ts @@ -174,15 +174,14 @@ registerRenderer({ // import './renderers/Form/InputText'; registerRenderer({ type: 'input-text', - alias: ['input-password', 'native-date', 'native-time', 'native-number'], - getComponent: () => import('./renderers/Form/InputText') -}); -registerRenderer({ - type: 'input-email', - getComponent: () => import('./renderers/Form/InputText') -}); -registerRenderer({ - type: 'input-url', + alias: [ + 'input-password', + 'native-date', + 'native-time', + 'native-number', + 'input-email', + 'input-url' + ], getComponent: () => import('./renderers/Form/InputText') }); // import './renderers/Form/InputTag';