From dd2eb4348bf0a5a1f07e96349c55c004aa9ea9b2 Mon Sep 17 00:00:00 2001 From: zhangtao07 Date: Sun, 28 Apr 2024 10:41:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dcrud2=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=88=97=E8=A1=A8=E7=AE=A1=E7=90=86=E7=BC=96=E8=BE=91?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../amis-editor/src/plugin/TableCell2.tsx | 9 ++++---- .../src/renderer/FeatureControl.tsx | 21 +++++++++++-------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/amis-editor/src/plugin/TableCell2.tsx b/packages/amis-editor/src/plugin/TableCell2.tsx index 49f24ec1c..dbd80d2b8 100644 --- a/packages/amis-editor/src/plugin/TableCell2.tsx +++ b/packages/amis-editor/src/plugin/TableCell2.tsx @@ -1,8 +1,8 @@ -import React from 'react'; +import React, {StrictMode} from 'react'; import get from 'lodash/get'; import flattenDeep from 'lodash/flattenDeep'; import {Button, Icon} from 'amis'; -import {getVariable, isObject} from 'amis-core'; +import {dataMapping, getVariable, isObject} from 'amis-core'; import { BasePlugin, BasicRendererInfo, @@ -610,6 +610,7 @@ export class TableCell2Plugin extends BasePlugin { body: [ { type: 'ae-feature-control', + strictMode: false, // 注意需要添加这个才能及时获取表单data变更 label: false, manager, addable: true, @@ -652,8 +653,8 @@ export class TableCell2Plugin extends BasePlugin { schema.buttons.push({ label: '新增按钮', level: 'link' - }), - onBulkChange(schema); + }); + onBulkChange(schema); } }; } diff --git a/packages/amis-editor/src/renderer/FeatureControl.tsx b/packages/amis-editor/src/renderer/FeatureControl.tsx index c37fdf3e7..c934b0fb9 100644 --- a/packages/amis-editor/src/renderer/FeatureControl.tsx +++ b/packages/amis-editor/src/renderer/FeatureControl.tsx @@ -6,7 +6,7 @@ import React from 'react'; import {findDOMNode} from 'react-dom'; import Sortable from 'sortablejs'; import cx from 'classnames'; -import clone from 'lodash/clone'; +import cloneDeep from 'lodash/cloneDeep'; import remove from 'lodash/remove'; import isPlainObject from 'lodash/isPlainObject'; import {FormItem, Button, Icon, FormControlProps, autobind} from 'amis'; @@ -106,21 +106,23 @@ export default class FeatureControl extends React.Component< @autobind handleRemove(item: FeatureOption, index: number) { const {removeFeature, data, onBulkChange} = this.props; + const schema = cloneDeep(data); const {inUseFeat, unUseFeat} = this.state; - item.remove?.(data); - removeFeature?.(item, data); - onBulkChange?.(data); + item.remove?.(schema); + removeFeature?.(item, schema); remove(inUseFeat, item); item.add && unUseFeat.push(item); + onBulkChange?.(schema); this.setState({inUseFeat, unUseFeat}); } handleSort(e: any) { const {data, onBulkChange, onSort} = this.props; - onSort?.(data, e); - onBulkChange?.(data); + let schema = cloneDeep(data); + onSort?.(schema, e); + onBulkChange?.(schema); } @autobind @@ -131,7 +133,7 @@ export default class FeatureControl extends React.Component< inUseFeat.push(item); remove(unUseFeat, item); - const schema = clone(data); + const schema = cloneDeep(data); item.add?.(schema); addFeature?.(item, schema); onBulkChange?.(schema); @@ -187,6 +189,7 @@ export default class FeatureControl extends React.Component< const value = this.state.inUseFeat.concat(); value[e.oldIndex] = value.splice(e.newIndex, 1, value[e.oldIndex])[0]; + this.setState({inUseFeat: value}, () => { this.handleSort({ oldIndex: e.oldIndex, @@ -208,7 +211,7 @@ export default class FeatureControl extends React.Component< @autobind handleCheck(res: boolean, index: number) { const {data, onBulkChange, onItemCheck} = this.props; - const schema = clone(data); + const schema = cloneDeep(data); onItemCheck?.(res, index, schema); onBulkChange?.(schema); } @@ -282,7 +285,7 @@ export default class FeatureControl extends React.Component< } if (customAction && typeof customAction === 'function') { - const schema = customAction({onBulkChange, schema: clone(data)}); + const schema = customAction({onBulkChange, schema: cloneDeep(data)}); if (isPlainObject(schema) && typeof schema.type === 'string') { return render('custom-action', schema);