From e9d670685d08727496f4a4e8627a1a83b8b2a957 Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Fri, 24 Apr 2026 17:25:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(form):=20=E4=BF=AE=E5=A4=8D=E8=A1=A8?= =?UTF-8?q?=E5=8D=95=E9=A1=B9=E6=B8=B2=E6=9F=93=E4=B8=AD=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E9=A1=B9=E7=9A=84=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加了对隐藏项的判断和过滤,避免隐藏项被渲染 - 实现了按钮显示的精确控制逻辑 - 添加了查找最后一个需要显示按钮项的功能 - 优化了表单列表项的操作按钮显示条件 - 移动了 dependencies 和 shouldUpdate 属性的删除逻辑到正确位置 --- .../FormBuilder/FormItemsRenderer.js | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/FormBuilder/FormItemsRenderer.js b/src/components/FormBuilder/FormItemsRenderer.js index c7b0f64..2740a77 100644 --- a/src/components/FormBuilder/FormItemsRenderer.js +++ b/src/components/FormBuilder/FormItemsRenderer.js @@ -506,10 +506,11 @@ const FormItemsRenderer = ({ return ( {listOptions.map((listOption, listIndex) => { + if (getHidden(listOption.hidden)) + return null; + const col = getCol(listOption); const formItemProps = getFormItemProps(listOption); - delete formItemProps.dependencies; - delete formItemProps.shouldUpdate; const params = { option: listOption, @@ -524,12 +525,33 @@ const FormItemsRenderer = ({ if (listOption.render === FORM_ITEM_RENDER_ENUM.FORM_LIST) return renderFormList(params); - // 判断下一个是否是嵌套的 FormList,如果是则在当前项后添加按钮 + // 判断一个项是否需要显示按钮(不是 onlyForLabel 且不是隐藏的) + const isShowButton = (opt) => { + return !getHidden(opt.hidden) && !opt.onlyForLabel; + }; + + // 从后往前找,找到第一个需要显示按钮的项的索引 + const findLastButtonIndex = () => { + for (let i = listOptions.length - 1; i >= 0; i--) { + const opt = listOptions[i]; + if (opt.render === FORM_ITEM_RENDER_ENUM.FORM_LIST) + return i; + if (isShowButton(opt)) + return i; + } + return -1; + }; + + // 判断下一个是否是嵌套的 FormList,或者是 onlyForLabel/hidden 项 const nextOption = listOptions[listIndex + 1]; const isNextNestedFormList = nextOption && nextOption.render === FORM_ITEM_RENDER_ENUM.FORM_LIST; + const isNextNoButton = nextOption && !isShowButton(nextOption); - // 如果是最后一个表单项,或者下一个是嵌套的 FormList,则在其后添加操作按钮 - if (listIndex === listOptions.length - 1 || isNextNestedFormList) { + // 如果是最后一个需要显示按钮的项,或者下一个是嵌套的 FormList,或者下一个不需要按钮,则在其后添加操作按钮 + const lastButtonIndex = findLastButtonIndex(); + if (listIndex === lastButtonIndex || isNextNestedFormList || isNextNoButton) { + delete formItemProps.dependencies; + delete formItemProps.shouldUpdate; return (