/* eslint-disable @typescript-eslint/no-unused-vars */ import React from 'react'; import { Form, Input, Select, Button, Field, Message } from '@alifd/next'; import './index.scss'; const FormItem = Form.Item; interface RelationTreeProps { opertors: Array>; field: any; conditionFields: any[]; convertToNestedArray: (data: Record) => any[]; convertToFlatObject: (data: any) => any[]; } const RelationTree = (props: RelationTreeProps) => { const { opertors = [], field, conditionFields = [], convertToNestedArray, convertToFlatObject, } = props; // 添加组内项目 const addItem = (groupIndex: number, itemIndex: number) => { const val: any = field.getValues(); const { groups, ...rest } = val; const newGroups = convertToNestedArray(rest); if (newGroups[groupIndex].children) { newGroups[groupIndex].children.splice(itemIndex + 1, 0, { key: '', operator: '', value: '' }); } else { newGroups[groupIndex].children = [{ key: '', operator: '', value: '' }]; } const newValues = convertToFlatObject(newGroups); field.setValues({ groups: newGroups, ...newValues, }); }; // 删除组内项目 const removeItem = (groupIndex: number, itemIndex: number) => { const val: any = field.getValues(); const { groups, ...rest } = val; const newGroups = convertToNestedArray(rest); newGroups[groupIndex].children.splice(itemIndex, 1); const newValues = convertToFlatObject(newGroups); field.setValues({ groups: newGroups, ...newValues, }); }; const groups: any = field.getValue('groups') || []; if (!field) return null; return (
{groups?.map((group: any, groupIndex: number) => (
1 ? 'flex' : 'none' }} >
target?.parentNode as HTMLElement} /> target?.parentNode as HTMLElement} />
))} {!group.children || group.children?.length < 1 ? ( ) : null}
))}
); }; export default RelationTree;