|
@@ -11,19 +11,22 @@ export interface DynamicFormRef {
|
|
interface DynamicFormProps {
|
|
interface DynamicFormProps {
|
|
formItems?: API.TmplItem[]
|
|
formItems?: API.TmplItem[]
|
|
formData?: Record<string, any>
|
|
formData?: Record<string, any>
|
|
|
|
+ formRule?: any
|
|
disabled?: boolean
|
|
disabled?: boolean
|
|
setFormData: (data: Record<string, any>) => void
|
|
setFormData: (data: Record<string, any>) => void
|
|
}
|
|
}
|
|
|
|
|
|
const DynamicForm = memo(
|
|
const DynamicForm = memo(
|
|
forwardRef<DynamicFormRef, DynamicFormProps>(
|
|
forwardRef<DynamicFormRef, DynamicFormProps>(
|
|
- ({ formItems = [], formData = {}, disabled = false, setFormData }, ref) => {
|
|
|
|
|
|
+ ({ formItems = [], formData = {}, formRule = {}, disabled = false, setFormData }, ref) => {
|
|
useImperativeHandle(ref, () => {
|
|
useImperativeHandle(ref, () => {
|
|
return {
|
|
return {
|
|
onSubmit
|
|
onSubmit
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+ console.log(formRule)
|
|
|
|
+
|
|
const { dictArray: inputUnitTypeOptions, dictRequestFn: getInputUnitTypeOptions } =
|
|
const { dictArray: inputUnitTypeOptions, dictRequestFn: getInputUnitTypeOptions } =
|
|
useNoAuthDict('input_unit_type')
|
|
useNoAuthDict('input_unit_type')
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -39,11 +42,6 @@ const DynamicForm = memo(
|
|
}
|
|
}
|
|
const onFinish = (values: any) => {
|
|
const onFinish = (values: any) => {
|
|
console.log('Finish:', values)
|
|
console.log('Finish:', values)
|
|
- for (const key in values) {
|
|
|
|
- if (values[key]) {
|
|
|
|
- console.log(values[key].format('YYYY-MM-DD'))
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
const onFinishFailed = (errorInfo: any) => {
|
|
const onFinishFailed = (errorInfo: any) => {
|
|
console.log('Failed:', errorInfo)
|
|
console.log('Failed:', errorInfo)
|
|
@@ -52,6 +50,7 @@ const DynamicForm = memo(
|
|
console.log(formItems)
|
|
console.log(formItems)
|
|
console.log(setFormData)
|
|
console.log(setFormData)
|
|
|
|
|
|
|
|
+ // 表单项生成器
|
|
const FieldWrapper = (props: { children: React.ReactNode }) => {
|
|
const FieldWrapper = (props: { children: React.ReactNode }) => {
|
|
return (
|
|
return (
|
|
<div className='px-[20px] py-[16px] mb-[16px] rounded-[10px] bg-[#ecf5ff]'>
|
|
<div className='px-[20px] py-[16px] mb-[16px] rounded-[10px] bg-[#ecf5ff]'>
|
|
@@ -61,9 +60,8 @@ const DynamicForm = memo(
|
|
}
|
|
}
|
|
const renderField = (field: API.TmplItem) => {
|
|
const renderField = (field: API.TmplItem) => {
|
|
const options = field.itemStruct
|
|
const options = field.itemStruct
|
|
- const { type, label, desc, placeholder, visible, valid, expand, widgetId } = options!
|
|
|
|
|
|
+ const { type, label, desc, placeholder, visible, expand, widgetId } = options!
|
|
if (!visible) return null // 条件渲染
|
|
if (!visible) return null // 条件渲染
|
|
- console.log(valid)
|
|
|
|
|
|
|
|
const labelContent = (
|
|
const labelContent = (
|
|
<div>
|
|
<div>
|
|
@@ -81,10 +79,15 @@ const DynamicForm = memo(
|
|
|
|
|
|
return (
|
|
return (
|
|
<FieldWrapper key={widgetId}>
|
|
<FieldWrapper key={widgetId}>
|
|
- <Form.Item name={widgetId} label={labelContent} style={{ marginBottom: 0 }}>
|
|
|
|
|
|
+ {JSON.stringify(formRule[widgetId!])}
|
|
|
|
+ <Form.Item
|
|
|
|
+ name={widgetId}
|
|
|
|
+ label={labelContent}
|
|
|
|
+ rules={formRule[widgetId!]}
|
|
|
|
+ hasFeedback
|
|
|
|
+ style={{ marginBottom: 0 }}>
|
|
<Input
|
|
<Input
|
|
placeholder={placeholder}
|
|
placeholder={placeholder}
|
|
- maxLength={parseInt(expandVal.maxChars)}
|
|
|
|
prefix={expandVal.prefix}
|
|
prefix={expandVal.prefix}
|
|
suffix={expandVal.suffix}
|
|
suffix={expandVal.suffix}
|
|
showCount
|
|
showCount
|
|
@@ -102,6 +105,8 @@ const DynamicForm = memo(
|
|
|
|
|
|
return (
|
|
return (
|
|
<FieldWrapper key={widgetId}>
|
|
<FieldWrapper key={widgetId}>
|
|
|
|
+ {JSON.stringify(formRule[widgetId!])}
|
|
|
|
+ {widgetId}
|
|
<Form.Item name={widgetId} label={labelContent} style={{ marginBottom: 0 }}>
|
|
<Form.Item name={widgetId} label={labelContent} style={{ marginBottom: 0 }}>
|
|
<InputNumber
|
|
<InputNumber
|
|
className='!w-full'
|
|
className='!w-full'
|
|
@@ -133,6 +138,7 @@ const DynamicForm = memo(
|
|
|
|
|
|
return (
|
|
return (
|
|
<FieldWrapper key={widgetId}>
|
|
<FieldWrapper key={widgetId}>
|
|
|
|
+ {JSON.stringify(formRule[widgetId!])}
|
|
<Form.Item name={widgetId} label={labelContent} style={{ marginBottom: 0 }}>
|
|
<Form.Item name={widgetId} label={labelContent} style={{ marginBottom: 0 }}>
|
|
<InputNumber
|
|
<InputNumber
|
|
className='!w-full'
|
|
className='!w-full'
|
|
@@ -160,6 +166,7 @@ const DynamicForm = memo(
|
|
|
|
|
|
return (
|
|
return (
|
|
<FieldWrapper key={widgetId}>
|
|
<FieldWrapper key={widgetId}>
|
|
|
|
+ {JSON.stringify(formRule[widgetId!])}
|
|
<Form.Item name={widgetId} label={labelContent} style={{ marginBottom: 0 }}>
|
|
<Form.Item name={widgetId} label={labelContent} style={{ marginBottom: 0 }}>
|
|
<Select
|
|
<Select
|
|
mode={expandVal.multiple ? 'multiple' : undefined}
|
|
mode={expandVal.multiple ? 'multiple' : undefined}
|