From cbed0e4693f56d26b24978273d9a780b8e671ffb Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Tue, 16 Jan 2024 21:13:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dcrud2=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=85=B3=E9=97=AD=E6=97=B6=E6=90=9C=E7=B4=A2=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E4=BE=9D=E6=97=A7=E5=AD=98=E5=9C=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../crud2-control/CRUDFiltersControl.tsx | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/amis-editor/src/renderer/crud2-control/CRUDFiltersControl.tsx b/packages/amis-editor/src/renderer/crud2-control/CRUDFiltersControl.tsx index 5be37593e..22dde2519 100644 --- a/packages/amis-editor/src/renderer/crud2-control/CRUDFiltersControl.tsx +++ b/packages/amis-editor/src/renderer/crud2-control/CRUDFiltersControl.tsx @@ -28,7 +28,7 @@ import type { CRUDScaffoldConfig } from '../../builder'; import type {EditorNodeType} from 'amis-editor-core'; -import type {FormControlProps} from 'amis'; +import type {FormControlProps, PlainObject} from 'amis'; interface Option { label: string; @@ -235,6 +235,12 @@ export class CRUDFiltersControl extends React.Component< this.setState({loading: false}); } + setFilterVisible(schema: PlainObject) { + if (!('visibleOn' in schema) && schema.type) { + schema.visible = schema.body?.length > 0; + } + } + async updateSimpleQuery(enable: boolean) { const {manager, nodeId, builder} = this.props; const store = manager.store; @@ -269,7 +275,7 @@ export class CRUDFiltersControl extends React.Component< } })) ?? []; - const newFilterSchema = traverseSchemaDeep( + let newFilterSchema = traverseSchemaDeep( filterSchema, (key: string, value: any, host: any) => { /** 更新标识符 */ @@ -292,6 +298,7 @@ export class CRUDFiltersControl extends React.Component< return [key, value]; } ); + this.setFilterVisible(newFilterSchema); const targetNode = manager.store.getNodeById(filterSchema.$$id); @@ -299,7 +306,7 @@ export class CRUDFiltersControl extends React.Component< targetNode.updateSchema(newFilterSchema); } } else { - const newFilterSchema = traverseSchemaDeep( + let newFilterSchema = traverseSchemaDeep( filterSchema, (key: string, value: any, host: any) => { /** 更新标识符 */ @@ -330,6 +337,7 @@ export class CRUDFiltersControl extends React.Component< } ); + this.setFilterVisible(newFilterSchema); const targetNode = manager.store.getNodeById(filterSchema.$$id); if (targetNode) { @@ -402,7 +410,7 @@ export class CRUDFiltersControl extends React.Component< } }); - const newFilterSchema = traverseSchemaDeep( + let newFilterSchema = traverseSchemaDeep( filterSchema, (key: string, value: any, host: any) => { /** 更新标识符 */ @@ -425,6 +433,7 @@ export class CRUDFiltersControl extends React.Component< return [key, value]; } ); + this.setFilterVisible(newFilterSchema); const targetNode = manager.store.getNodeById(filterSchema.$$id); @@ -432,7 +441,7 @@ export class CRUDFiltersControl extends React.Component< targetNode.updateSchema(newFilterSchema); } } else { - const newFilterSchema = traverseSchemaDeep( + let newFilterSchema = traverseSchemaDeep( filterSchema, (key: string, value: any, host: any) => { /** 更新标识符 */ @@ -464,6 +473,7 @@ export class CRUDFiltersControl extends React.Component< return [key, value]; } ); + this.setFilterVisible(newFilterSchema); const targetNode = manager.store.getNodeById(filterSchema.$$id); From c50e2004a77a67b32b9c7b976c0a1fc3f2482722 Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Wed, 24 Jan 2024 19:05:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20table2=E6=94=AF=E6=8C=81=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E8=A1=8C=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis-editor/src/plugin/CRUD2/BaseCRUD.tsx | 14 +++++-- packages/amis-editor/src/plugin/Table2.tsx | 40 ++++++++++++++++--- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx b/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx index fb9151852..741f0f047 100644 --- a/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx +++ b/packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx @@ -1120,7 +1120,11 @@ export class BaseCRUDPlugin extends BasePlugin { } } - async buildDataSchemas(node: EditorNodeType, region?: EditorNodeType) { + async buildDataSchemas( + node: EditorNodeType, + region?: EditorNodeType, + trigger?: EditorNodeType + ) { const child: EditorNodeType = node.children.find( item => !!~['table2', 'cards', 'list'].indexOf(item.type) ); @@ -1129,7 +1133,12 @@ export class BaseCRUDPlugin extends BasePlugin { return; } - const tmpSchema = await child.info.plugin.buildDataSchemas?.(child, region); + const tmpSchema = await child.info.plugin.buildDataSchemas?.( + child, + region, + trigger, + node + ); const childDataSchema = { ...tmpSchema, @@ -1142,7 +1151,6 @@ export class BaseCRUDPlugin extends BasePlugin { $id: 'crud2', type: 'object', properties: { - ...items?.properties, items: { ...items, title: '全部数据' diff --git a/packages/amis-editor/src/plugin/Table2.tsx b/packages/amis-editor/src/plugin/Table2.tsx index f46861d4a..eddb81123 100644 --- a/packages/amis-editor/src/plugin/Table2.tsx +++ b/packages/amis-editor/src/plugin/Table2.tsx @@ -628,7 +628,8 @@ export class Table2Plugin extends BasePlugin { async buildDataSchemas( node: EditorNodeType, region?: EditorNodeType, - trigger?: EditorNodeType + trigger?: EditorNodeType, + parent?: EditorNodeType ) { const itemsSchema: any = { $id: 'tableRow', @@ -639,6 +640,32 @@ export class Table2Plugin extends BasePlugin { item => item.isRegion && item.region === 'columns' ); + const parentScopeId = `${parent?.id}-${parent?.type}${ + node.parent?.type === 'cell' ? '-currentRow' : '' + }`; + + // 追加当前行scope + let isColumnChild = false; + if (trigger) { + isColumnChild = someTree( + columns?.children, + item => item.id === trigger.id + ); + + if (isColumnChild) { + const scopeId = `${node.id}-${node.type}-currentRow`; + if (this.manager.dataSchema.getScope(scopeId)) { + this.manager.dataSchema.removeScope(scopeId); + } + if (this.manager.dataSchema.getScope(parentScopeId)) { + this.manager.dataSchema.switchTo(parentScopeId); + } + this.manager.dataSchema.addScope([], scopeId); + this.manager.dataSchema.current.tag = '当前行记录'; + this.manager.dataSchema.current.group = '组件上下文'; + } + } + if (columns) { for (let current of columns.children) { const schema = current.schema; @@ -657,21 +684,24 @@ export class Table2Plugin extends BasePlugin { } } - let cellProperties = {}; if (trigger) { const isColumnChild = someTree( columns?.children, item => item.id === trigger.id ); - isColumnChild && (cellProperties = itemsSchema.properties); + // 追加当前行数据 + if (isColumnChild) { + const scopeId = `${node.id}-${node.type}-currentRow`; + const scope = this.manager.dataSchema.getScope(scopeId); + scope?.addSchema(itemsSchema); + } } const result: any = { - $id: 'table2', + $id: `${node.id}-${node.type}`, type: 'object', properties: { - ...cellProperties, rows: { type: 'array', title: '数据列表', From 82bd6a3d751ee4939d0bdc842f77b2126e3caa48 Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Wed, 24 Jan 2024 20:15:10 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dcrud2=20=E5=88=97?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/amis-ui/src/components/table/Head.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/amis-ui/src/components/table/Head.tsx b/packages/amis-ui/src/components/table/Head.tsx index 03f1469f2..afa96bf4b 100644 --- a/packages/amis-ui/src/components/table/Head.tsx +++ b/packages/amis-ui/src/components/table/Head.tsx @@ -300,7 +300,7 @@ export default class Head extends React.PureComponent { colIndex === data.length - 1 })} depth={item.depth} - col={cIndex > -1 ? cIndex.toString() : undefined} + col={String(colIndex)} > {typeof item.title === 'function' ? item.title(children)