From 4dec008c86c3e3607824d46e415a208d92b3599b Mon Sep 17 00:00:00 2001 From: liaoxuezhi <2betop.cn@gmail.com> Date: Wed, 17 May 2023 17:32:37 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=B0=83=E6=95=B4=E8=A1=A8=E6=A0=BC?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=B8=8A=E4=B8=8B=E6=96=87=20(#6906)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: 调整表格数据上下文 * cards 也加一下 --- packages/amis-core/src/store/list.ts | 9 +++++++-- packages/amis-core/src/store/table.ts | 7 ++++++- packages/amis/src/renderers/Table/index.tsx | 8 +------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/amis-core/src/store/list.ts b/packages/amis-core/src/store/list.ts index 6fe0a60ab..696434c22 100644 --- a/packages/amis-core/src/store/list.ts +++ b/packages/amis-core/src/store/list.ts @@ -39,9 +39,14 @@ export const Item = types }, get locals(): any { + const listStore = getParent(self, 2) as IListStore; return createObject( - extendObject((getParent(self, 2) as IListStore).data, { - index: self.index + extendObject(listStore.data, { + index: self.index, + + // 只有table时,也可以获取选中行 + selectedItems: listStore.selectedItems.map(item => item.data), + unSelectedItems: listStore.unSelectedItems.map(item => item.data) }), self.data ); diff --git a/packages/amis-core/src/store/table.ts b/packages/amis-core/src/store/table.ts index e89620d12..83d59c33f 100644 --- a/packages/amis-core/src/store/table.ts +++ b/packages/amis-core/src/store/table.ts @@ -174,12 +174,17 @@ export const Row = types children = self.children.map(item => item.locals); } + const table = getParent(self, self.depth * 2) as ITableStore; const parent = getParent(self, 2) as ITableStore; return createObject( extendObject((getParent(self, self.depth * 2) as ITableStore).data, { index: self.index, // todo 以后再支持多层,目前先一层 - parent: parent.storeType === Row.name ? parent.data : undefined + parent: parent.storeType === Row.name ? parent.data : undefined, + + // 只有table时,也可以获取选中行 + selectedItems: table.selectedRows.map(item => item.data), + unSelectedItems: table.unSelectedRows.map(item => item.data) }), children ? { diff --git a/packages/amis/src/renderers/Table/index.tsx b/packages/amis/src/renderers/Table/index.tsx index 7fcb9bcbc..219177bfe 100644 --- a/packages/amis/src/renderers/Table/index.tsx +++ b/packages/amis/src/renderers/Table/index.tsx @@ -2277,13 +2277,7 @@ export default class Table extends React.Component { // 操作列不下发loading,否则会导致操作栏里面的所有按钮都出现loading loading: column.type === 'operation' ? false : props.loading, btnDisabled: store.dragging, - data: this.props.selectable - ? extendObject(item.locals, { - // 只有table时,也可以获取选中行 - selectedItems: store.selectedRows.map(item => item.data), - unSelectedItems: store.unSelectedRows.map(item => item.data) - }) - : item.locals, + data: item.locals, value: column.name ? resolveVariable( column.name,