优化FormItemsRenderer
parent
72ec102c30
commit
10083fa9f8
|
|
@ -412,6 +412,10 @@ const FormItemsRenderer = ({
|
|||
|
||||
// 渲染普通表单项
|
||||
const renderFormItem = ({ option, style, col, index }) => {
|
||||
const formItemProps = getFormItemProps(option);
|
||||
delete formItemProps.dependencies;
|
||||
delete formItemProps.shouldUpdate;
|
||||
|
||||
if (getHidden(option.hidden))
|
||||
return null;
|
||||
|
||||
|
|
@ -424,7 +428,7 @@ const FormItemsRenderer = ({
|
|||
labelCol={col.labelCol}
|
||||
wrapperCol={col.wrapperCol}
|
||||
preserve={false}
|
||||
{...getFormItemProps(option)}
|
||||
{...formItemProps}
|
||||
>
|
||||
{renderFormControl(option)}
|
||||
</Form.Item>
|
||||
|
|
@ -475,6 +479,9 @@ const FormItemsRenderer = ({
|
|||
const renderFormList = (option, index, col, style) => {
|
||||
const formListUniqueProps = getFormListUniqueProps(option);
|
||||
const componentProps = getComponentProps(option);
|
||||
const formItemProps = getFormItemProps(option);
|
||||
delete formItemProps.dependencies;
|
||||
delete formItemProps.shouldUpdate;
|
||||
|
||||
return (
|
||||
<Col key={getKey(option) || index} span={col.span} style={style}>
|
||||
|
|
@ -482,7 +489,7 @@ const FormItemsRenderer = ({
|
|||
{(fields, { add, remove, move }) => (
|
||||
<>
|
||||
{fields.map((field, fieldIndex) => {
|
||||
const listOptions = getListOptions(option.formListUniqueProps.options, field, fieldIndex, add, remove, move);
|
||||
const listOptions = getListOptions(formListUniqueProps.options, field, fieldIndex, add, remove, move);
|
||||
return (
|
||||
<Row gutter={gutter} key={field.key}>
|
||||
{listOptions.map((listOption, listIndex) => {
|
||||
|
|
@ -509,7 +516,7 @@ const FormItemsRenderer = ({
|
|||
wrapperCol={col.wrapperCol}
|
||||
preserve={false}
|
||||
required={getRequired(listOption.required)}
|
||||
{...getFormItemProps(listOption)}
|
||||
{...formItemProps}
|
||||
>
|
||||
<div style={{ display: "flex", gap: 10, alignItems: "center", justifyContent: "space-between" }}>
|
||||
<div style={{ flex: 1 }}>
|
||||
|
|
@ -569,13 +576,15 @@ const FormItemsRenderer = ({
|
|||
|
||||
// 渲染需要动态更新的表单项
|
||||
const renderDynamicFormItem = (option, index, style, col) => {
|
||||
const formItemProps = getFormItemProps(option);
|
||||
|
||||
return (
|
||||
<Form.Item
|
||||
key={getKey(option) || index}
|
||||
noStyle
|
||||
preserve={false}
|
||||
shouldUpdate={option.shouldUpdate ?? option?.componentProps?.shouldUpdate}
|
||||
dependencies={option.dependencies ?? option?.componentProps?.dependencies}
|
||||
shouldUpdate={option.shouldUpdate ?? formItemProps.shouldUpdate}
|
||||
dependencies={option.dependencies ?? formItemProps.dependencies}
|
||||
>
|
||||
{() => {
|
||||
return renderFormItem({ option, style, col, index });
|
||||
|
|
@ -589,6 +598,7 @@ const FormItemsRenderer = ({
|
|||
{options.map((option, index) => {
|
||||
const col = getCol(option);
|
||||
const style = getStyle(index);
|
||||
const formItemProps = getFormItemProps(option);
|
||||
|
||||
// 处理特殊类型的表单项
|
||||
const otherTypeItem = renderOtherTypeItem({ option, style, col, index });
|
||||
|
|
@ -601,7 +611,7 @@ const FormItemsRenderer = ({
|
|||
}
|
||||
|
||||
// 如果配置了 shouldUpdate 或 dependencies,使用 Form.Item 的联动机制
|
||||
if ((option.shouldUpdate ?? option.dependencies) || (option?.componentProps?.shouldUpdate ?? option?.componentProps?.dependencies)) {
|
||||
if ((option.shouldUpdate ?? option.dependencies) || (formItemProps.shouldUpdate ?? formItemProps.dependencies)) {
|
||||
return renderDynamicFormItem(option, index, style, col);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue