import { Input, Cell, DateSelect, Radio, Select, Checkbox } from 'zarm'; import styles from './baseForm.less'; import React, { ReactText, useState } from 'react'; import { baseFormDateTpl, baseFormMyRadioTpl, baseFormMyCheckboxTpl, baseFormMySelectTpl, baseFormNumberTpl, baseFormTextAreaTpl, baseFormTextTpl, baseFormTextTipTpl, baseFormUnionType, } from '@/components/PanelComponents/FormEditor/types'; import { formatTime } from '@/utils/tool'; // 维护表单控件, 提高form渲染性能 type TBaseForm = { [key in baseFormUnionType]: any; }; const BaseForm: TBaseForm = { Text: (props: baseFormTextTpl & { onChange: (v: string | undefined) => void }) => { const { label, placeholder, onChange } = props; return ( ); }, Textarea: (props: baseFormTextAreaTpl & { onChange: (v: string | undefined) => void }) => { const { label, placeholder, onChange } = props; return ( ); }, Number: (props: baseFormNumberTpl & { onChange: (v: string | undefined | number) => void }) => { const { label, placeholder, onChange } = props; return ( ); }, MyRadio: (props: baseFormMyRadioTpl & { onChange: (v: string | undefined | number) => void }) => { const { label, options, onChange } = props; return (
{label}
{options.map((item, i) => { return ( {item.label} ); })}
); }, MyCheckbox: ( props: baseFormMyCheckboxTpl & { onChange: (v: Array | undefined) => void }, ) => { const { label, options, onChange } = props; return (
{label}
{options.map((item, i) => { return ( {item.label} ); })}
); }, Date: (props: baseFormDateTpl & { onChange: (v: Date) => void }) => { const { label, placeholder, onChange } = props; const [value, setValue] = useState(''); const handleChange = (v: any) => { setValue(v); onChange && onChange(formatTime('yyyy-MM-dd', v)); }; return ( ); }, MySelect: ( props: baseFormMySelectTpl & { onChange: ((v: Record) => void) | undefined }, ) => { const { label, options, onChange } = props; return (