From 919044f4bb117e52bbaa8a02c1399ff55173c590 Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Wed, 27 Mar 2024 17:26:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20defaultData=20?= =?UTF-8?q?=E4=B8=AD=E9=85=8D=E7=BD=AE=20schema,=20=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=98=A0=E5=B0=84=E5=86=B2=E7=AA=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20Close:=20#8972=20(#9891)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-core/src/SchemaRenderer.tsx | 3 +- packages/amis-core/src/WithStore.tsx | 37 ++++++++++++++++++++--- packages/amis/src/renderers/GridNav.tsx | 2 +- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/packages/amis-core/src/SchemaRenderer.tsx b/packages/amis-core/src/SchemaRenderer.tsx index b99e9b888..557a99b6a 100644 --- a/packages/amis-core/src/SchemaRenderer.tsx +++ b/packages/amis-core/src/SchemaRenderer.tsx @@ -67,7 +67,8 @@ export const RENDERER_TRANSMISSION_OMIT_PROPS = [ 'renderLabel', 'trackExpression', 'editorSetting', - 'updatePristineAfterStoreDataReInit' + 'updatePristineAfterStoreDataReInit', + 'source' ]; const componentCache: SimpleMap = new SimpleMap(); diff --git a/packages/amis-core/src/WithStore.tsx b/packages/amis-core/src/WithStore.tsx index 3175b1ac3..27ed23fe5 100644 --- a/packages/amis-core/src/WithStore.tsx +++ b/packages/amis-core/src/WithStore.tsx @@ -20,6 +20,19 @@ import { import {dataMapping, tokenize} from './utils/tpl-builtin'; import {RootStoreContext} from './WithRootStore'; +/** + * 忽略静态数据中的 schema 属性 + * + * 比如 https://github.com/baidu/amis/issues/8972 中的用法 + */ +function ignoreSchemaProps(key: string, value: any) { + if (['clickAction'].includes(key) && typeof value !== 'string') { + return true; + } + + return false; +} + export function HocStoreFactory(renderer: { storeType: string; extendsData?: boolean | ((props: any) => boolean); @@ -86,7 +99,11 @@ export function HocStoreFactory(renderer: { : null, { ...this.formatData( - dataMapping(this.props.defaultData, this.props.data) + dataMapping( + this.props.defaultData, + this.props.data, + ignoreSchemaProps + ) ), ...this.formatData(this.props.data) } @@ -100,7 +117,11 @@ export function HocStoreFactory(renderer: { store.initData( createObject(this.props.store.data, { ...this.formatData( - dataMapping(this.props.defaultData, this.props.data) + dataMapping( + this.props.defaultData, + this.props.data, + ignoreSchemaProps + ) ) }) ); @@ -110,7 +131,11 @@ export function HocStoreFactory(renderer: { (this.props.data as any).__super || this.props.scope, { ...this.formatData( - dataMapping(this.props.defaultData, this.props.data) + dataMapping( + this.props.defaultData, + this.props.data, + ignoreSchemaProps + ) ), ...this.formatData(this.props.data) } @@ -120,7 +145,11 @@ export function HocStoreFactory(renderer: { } else { store.initData({ ...this.formatData( - dataMapping(this.props.defaultData, this.props.data) + dataMapping( + this.props.defaultData, + this.props.data, + ignoreSchemaProps + ) ), ...this.formatData(this.props.data) }); diff --git a/packages/amis/src/renderers/GridNav.tsx b/packages/amis/src/renderers/GridNav.tsx index 17b569fe6..5ec498bc0 100644 --- a/packages/amis/src/renderers/GridNav.tsx +++ b/packages/amis/src/renderers/GridNav.tsx @@ -154,7 +154,7 @@ export default class List extends React.Component { } else { action = item.clickAction!; } - handleAction(e, action as ActionSchema, this.props); + handleAction(e, action as ActionSchema, this.props, item); }; }