diff --git a/packages/amis/src/renderers/CRUD.tsx b/packages/amis/src/renderers/CRUD.tsx index 891a58002..a62dbfd83 100644 --- a/packages/amis/src/renderers/CRUD.tsx +++ b/packages/amis/src/renderers/CRUD.tsx @@ -2762,7 +2762,8 @@ export default class CRUD extends React.Component { headerToolbarRender: this.renderHeaderToolbar, footerToolbarRender: this.renderFooterToolbar, data: store.mergedData, - loading: store.loading + loading: store.loading, + host: this } )} {render( diff --git a/packages/amis/src/renderers/CRUD2.tsx b/packages/amis/src/renderers/CRUD2.tsx index 78c521d42..bb56f972a 100644 --- a/packages/amis/src/renderers/CRUD2.tsx +++ b/packages/amis/src/renderers/CRUD2.tsx @@ -1381,7 +1381,8 @@ export default class CRUD2 extends React.Component { onSort: this.handleQuerySearch, onSelect: this.handleSelect, data: store.mergedData, - loading: store.loading + loading: store.loading, + host: this } )} {/* spinner可以交给孩子处理 */} diff --git a/packages/amis/src/renderers/Cards.tsx b/packages/amis/src/renderers/Cards.tsx index 2b771f07b..917fa9a7a 100644 --- a/packages/amis/src/renderers/Cards.tsx +++ b/packages/amis/src/renderers/Cards.tsx @@ -1123,11 +1123,9 @@ export class CardsRenderer extends Cards { * 因为Cards在scope上注册,导致getComponentByName查询组件时会优先找到Cards,和CRUD联动的动作都会失效 * 这里先做兼容处理,把动作交给上层的CRUD处理 */ - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给Cards,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.receive?.(values, subPath); + if (this.props?.host) { + // CRUD会把自己透传给Cards,这样可以保证找到CRUD + return this.props.host.receive?.(values, subPath); } if (subPath) { @@ -1151,13 +1149,10 @@ export class CardsRenderer extends Cards { } const scoped = this.context as IScopedContext; - const parents = scoped?.parent?.getComponents(); - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给Cards,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.reload?.(subPath, query, ctx); + if (this.props?.host) { + // CRUD会把自己透传给Cards,这样可以保证找到CRUD + return this.props.host.reload?.(subPath, query, ctx); } if (subPath) { diff --git a/packages/amis/src/renderers/List.tsx b/packages/amis/src/renderers/List.tsx index ad3be5e71..94bcd15df 100644 --- a/packages/amis/src/renderers/List.tsx +++ b/packages/amis/src/renderers/List.tsx @@ -1112,17 +1112,14 @@ export class ListRenderer extends List { receive(values: any, subPath?: string) { const scoped = this.context as IScopedContext; - const parents = scoped?.parent?.getComponents(); /** * 因为List在scope上注册,导致getComponentByName查询组件时会优先找到List,和CRUD联动的动作都会失效 * 这里先做兼容处理,把动作交给上层的CRUD处理 */ - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给List,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.receive?.(values, subPath); + if (this.props?.host) { + // CRUD会把自己透传给List,这样可以保证找到CRUD + return this.props.host.receive?.(values, subPath); } if (subPath) { @@ -1146,13 +1143,10 @@ export class ListRenderer extends List { } const scoped = this.context as IScopedContext; - const parents = scoped?.parent?.getComponents(); - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给List,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.reload?.(subPath, query, ctx); + if (this.props?.host) { + // CRUD会把自己透传给List,这样可以保证找到CRUD + return this.props?.host.reload?.(subPath, query, ctx); } if (subPath) { diff --git a/packages/amis/src/renderers/Table/index.tsx b/packages/amis/src/renderers/Table/index.tsx index 460865372..55a8c54ac 100644 --- a/packages/amis/src/renderers/Table/index.tsx +++ b/packages/amis/src/renderers/Table/index.tsx @@ -2842,17 +2842,14 @@ export default class Table extends React.Component { export class TableRenderer extends Table { receive(values: any, subPath?: string) { const scoped = this.context as IScopedContext; - const parents = scoped?.parent?.getComponents(); /** * 因为Table在scope上注册,导致getComponentByName查询组件时会优先找到Table,和CRUD联动的动作都会失效 * 这里先做兼容处理,把动作交给上层的CRUD处理 */ - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给Table,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.receive?.(values, subPath); + if (this.props?.host) { + // CRUD会把自己透传给Table,这样可以保证找到CRUD + return this.props.host.receive?.(values, subPath); } if (subPath) { @@ -2904,13 +2901,10 @@ export class TableRenderer extends Table { } const scoped = this.context as IScopedContext; - const parents = scoped?.parent?.getComponents(); - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给Table,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.reload?.(subPath, query, ctx); + if (this.props?.host) { + // CRUD会把自己透传给Table,这样可以保证找到CRUD + return this.props.host.reload?.(subPath, query, ctx); } if (subPath) { diff --git a/packages/amis/src/renderers/Table2/index.tsx b/packages/amis/src/renderers/Table2/index.tsx index 879fb7950..9b0c7063d 100644 --- a/packages/amis/src/renderers/Table2/index.tsx +++ b/packages/amis/src/renderers/Table2/index.tsx @@ -2131,17 +2131,14 @@ export default class Table2 extends React.Component { export class TableRenderer extends Table2 { receive(values: any, subPath?: string) { const scoped = this.context as IScopedContext; - const parents = scoped?.parent?.getComponents(); /** * 因为Table在scope上注册,导致getComponentByName查询组件时会优先找到Table,和CRUD联动的动作都会失效 * 这里先做兼容处理,把动作交给上层的CRUD处理 */ - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给Table,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.receive?.(values, subPath); + if (this.props?.host) { + // CRUD会把自己透传给Table,这样可以保证找到CRUD + return this.props.host.receive?.(values, subPath); } if (subPath) { @@ -2153,11 +2150,9 @@ export class TableRenderer extends Table2 { const scoped = this.context as IScopedContext; const parents = scoped?.parent?.getComponents(); - if (Array.isArray(parents) && parents.length) { - // CRUD的name会透传给Table,这样可以保证找到CRUD - const crud = parents.find(cmpt => cmpt?.props?.name === this.props?.name); - - return crud?.reload?.(subPath, query, ctx); + if (this.props?.host) { + // CRUD会把自己透传给Table,这样可以保证找到CRUD + return this.props.host.reload?.(subPath, query, ctx); } if (subPath) {