import React, { memo, useState, useEffect } from 'react'; import { Input, Button, Popconfirm } from 'antd'; import { MinusCircleOutlined } from '@ant-design/icons'; import styles from './index.less'; import { TabConfigType } from '../../DynamicEngine/schema'; type MultiTextProps = { onChange?: (v: TabConfigType['tabs']) => void; value?: TabConfigType['tabs']; }; export default memo(function MutiText(props: MultiTextProps) { const { value, onChange } = props; const [valueList, setValueList] = useState(value || []); const handleAdd = () => { setValueList(prev => { return [...prev, '新增项']; }); }; const handleDel = (index: number) => { setValueList(prev => { let newList = prev.filter((_item, i) => i !== index); onChange && onChange(newList); return newList; }); }; const handleChange = (index: number, e: React.ChangeEvent) => { const { value } = e.target; setValueList(prev => { let newList = prev.map((item, i) => (i === index ? value : item)); onChange && onChange(newList); return newList; }); }; useEffect(() => { window['currentCates'] = valueList; return () => { window['currentCates'] = null; }; }, [valueList]); return (
{valueList.length ? ( valueList.map((item, i) => { return (
handleChange(i, e)} /> handleDel(i)} placement="leftTop" okText="确定" cancelText="取消" >
); }) ) : (
)} {valueList.length < 3 && (
)}
); });