import React, { memo, useState, useEffect } from 'react'; import { Form, Select, InputNumber, Input, Switch, Radio, Button } from 'antd'; import Upload from '../Upload'; import DataList from '../DataList'; import MutiText from '../MutiText'; import Color from '../Color'; import CardPicker from '../CardPicker'; import { Store } from 'antd/lib/form/interface'; import { UnionData, BasicRangeType, IconSchema } from '../DynamicEngine/schema'; // import styles from './index.less'; const normFile = (e: any) => { console.log('Upload event:', e); if (Array.isArray(e)) { //待修改 return e; } return e && e.fileList; }; const { Option } = Select; const formItemLayout = { labelCol: { span: 6 }, wrapperCol: { span: 16 }, }; interface FormEditorProps { uid: string; onSave: Function; onDel: Function; defaultValue: { [key: string]: any }; config: Array; } const FormEditor = (props: FormEditorProps) => { const { config, defaultValue, onSave, onDel, uid } = props; console.log(config, defaultValue, uid); const onFinish = (values: Store) => { onSave && onSave(values); }; const handleDel = () => { onDel && onDel(uid); }; const [form] = Form.useForm(); useEffect(() => { return () => { form.resetFields(); }; }, [defaultValue]); return (
{config.map((item, i) => { return ( {item.type === 'Number' && ( )} {item.type === 'Text' && ( )} {item.type === 'DataList' && ( )} {item.type === 'Color' && ( )} {item.type === 'MutiText' && ( )} {item.type === 'Select' && ( )} {item.type === 'Radio' && ( {item.range.map((v: BasicRangeType, i: number) => { return ( {v.text} ); })} )} {item.type === 'Switch' && ( )} {item.type === 'Upload' && ( )} {item.type === 'CardPicker' && ( )} ); })}
); }; export default memo(FormEditor);