fix: 修复crud2按钮列表管理编辑bug

This commit is contained in:
zhangtao07 2024-04-28 10:41:07 +08:00
parent f468044072
commit dd2eb4348b
2 changed files with 17 additions and 13 deletions

View File

@ -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);
}
};
}

View File

@ -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);