refactor(form-builder): 优化操作按钮显示逻辑
- 修改查找最后一个可显示按钮项的方法,排除特殊项和嵌套 FormList - 简化判断逻辑,移除对下一个项的复杂条件判断 - 删除多余的 isShow 函数及其相关调用 - 在最后一个普通可见表单项后添加操作按钮 - 清理部分依赖相关属性,减少不必要的更新机制2.0
parent
74a9de2e31
commit
e8505334d3
|
|
@ -542,31 +542,19 @@ const FormItemsRenderer = ({
|
|||
if (listOption.render === FORM_ITEM_RENDER_ENUM.FORM_LIST)
|
||||
return renderFormList(params);
|
||||
|
||||
// 判断一个项是否需要显示按钮(不是 onlyForLabel 且不是隐藏的)
|
||||
const isShow = (opt) => {
|
||||
return !getHidden(opt.hidden) && !opt.onlyForLabel;
|
||||
};
|
||||
|
||||
// 从后往前找,找到第一个需要显示按钮的项的索引
|
||||
const findLastShowIndex = () => {
|
||||
// 从后往前查找最后一个普通可见表单项,特殊项不允许承载操作按钮。
|
||||
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 (isShow(opt))
|
||||
if (!getHidden(opt.hidden) && !opt.onlyForLabel && opt.render !== FORM_ITEM_RENDER_ENUM.FORM_LIST) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
// 判断下一个是否是嵌套的 FormList,或者是 onlyForLabel/hidden 项
|
||||
const nextOption = listOptions[listIndex + 1];
|
||||
const isNextNestedFormList = nextOption && nextOption.render === FORM_ITEM_RENDER_ENUM.FORM_LIST;
|
||||
const isNextNoShow = nextOption && !isShow(nextOption);
|
||||
|
||||
// 如果是最后一个需要显示按钮的项,或者下一个是嵌套的 FormList,或者下一个不需要按钮,则在其后添加操作按钮
|
||||
const lastShowIndex = findLastShowIndex();
|
||||
if (listIndex === lastShowIndex || isNextNestedFormList || isNextNoShow) {
|
||||
const lastButtonIndex = findLastButtonIndex();
|
||||
if (listIndex === lastButtonIndex) {
|
||||
delete formItemProps.dependencies;
|
||||
delete formItemProps.shouldUpdate;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue