import { Input, InputNumber, DatePicker, Switch, Select, Tooltip } from 'antd' import { LockOutlined } from '@ant-design/icons' import dayjs from 'dayjs' import type { DragComponent, OptionItem } from '../types' /** * 组件注册表:把 M8 的 compType 原子组件映射到 Ant Design 控件。 * 这是"前端通用渲染引擎"的最底层——新增/替换控件只需在此登记,业务页面零改动。 */ export function FieldControl({ comp, value, onChange, optionsMap, }: { comp: DragComponent value: any onChange: (v: any) => void optionsMap: Record }) { const fb = comp.fieldBind || ({} as any) const placeholder = fb.placeholder || `请输入${fb.formLabel || ''}` // M1 类型兜底:当 M8 用通用文本控件、但领域类型是数值/布尔/时间时,据 M1 fieldType 升级控件。 // 于是"改 M1 的 type" 也会改变渲染出的控件(兑现 Help 步骤 3)。 const ft = fb.fieldType const generic = comp.compType === 'input' || comp.compType === 'text_area' if (generic && (ft === 'int' || ft === 'decimal')) { return } if (generic && ft === 'boolean') return if (generic && ft === 'datetime') { return ( onChange(d ? d.format('YYYY-MM-DDTHH:mm:ss') : null)} /> ) } switch (comp.compType) { case 'number_input': return case 'date_picker': return ( onChange(d ? d.format('YYYY-MM-DDTHH:mm:ss') : null)} /> ) case 'switch': return case 'select': { if (fb.optionsSource) { const opts = optionsMap[fb.optionsSource.aggregateId] || [] return ( onChange(arr[arr.length - 1] ?? null)} /> ) } case 'text_area': return onChange(e.target.value)} placeholder={placeholder} /> case 'input': default: return ( onChange(e.target.value)} placeholder={placeholder} suffix={fb.masked ? ( ) : } /> ) } }