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