import { Form } from 'antd'; import React, { useState } from 'react'; import { ArrowUpOutlined, ArrowDownOutlined, DeleteOutlined } from '@ant-design/icons'; function FormContent(props) { const { list, onChange, onSelect } = props; const [currentItem, setCurrentItem] = useState(null); const handleDelete = index => { let _list = [...list]; _list.splice(index, 1); onChange(_list); }; const handleUp = index => { let _list = [...list]; // 跟上一位置换位置 const temp = _list[index - 1]; _list[index - 1] = _list[index]; _list[index] = temp; onChange(_list); }; const handleDown = index => { let _list = [...list]; const temp = _list[index + 1]; _list[index + 1] = _list[index]; _list[index] = temp; onChange(_list); }; const handleSelect = index => { setCurrentItem(index); onSelect(index); }; return (
{list.map((item, index) => { const btns = ( <> {index != 0 && ( handleUp(index)} /> )} {index != list.length - 1 && ( handleDown(index)} /> )} handleDelete(index)} /> ); return ( handleSelect(index)} item={item} btns={btns} /> ); })}
); } function FormItem(props) { const { item, btns, active, onClick } = props; const { label, placeholder, required } = item.props; return (
{required && *} {label}
{btns}
{placeholder}
); } export default FormContent;