优化FormItemsRenderer

master
LiuJiaNan 2025-11-10 16:39:38 +08:00
parent a875bda0d7
commit d92cbe0b9e
2 changed files with 16 additions and 0 deletions

View File

@ -79,6 +79,8 @@ export interface FormOption {
shouldUpdate?: boolean | ((prevValues: FormValues, nextValues: FormValues, info: { source?: string }) => boolean); shouldUpdate?: boolean | ((prevValues: FormValues, nextValues: FormValues, info: { source?: string }) => boolean);
/** 依赖字段(用于表单联动) */ /** 依赖字段(用于表单联动) */
dependencies?: NamePath[]; dependencies?: NamePath[];
/** 是否仅用于保存标签,不渲染到页面上,只在表单中保存数据,默认 false */
onlyForLabel?: boolean;
} }
/** /**

View File

@ -272,6 +272,20 @@ const FormItemsRenderer = ({
return ( return (
<> <>
{options.map((option, index) => { {options.map((option, index) => {
// 如果是 onlyForLabel 类型不渲染任何UI只在表单中保存数据
if (option.onlyForLabel) {
return (
<Form.Item
key={getKey(option) || index}
name={option.name}
noStyle
preserve={false}
>
<input type="hidden" />
</Form.Item>
);
}
// 列数 // 列数
const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : option.span ?? span; const itemSpan = option.render === FORM_ITEM_RENDER_ENUM.DIVIDER ? 24 : option.span ?? span;
const itemLabelCol = option.labelCol ?? (itemSpan === 24 ? { span: labelCol.span / 2 } : labelCol); const itemLabelCol = option.labelCol ?? (itemSpan === 24 ? { span: labelCol.span / 2 } : labelCol);