0 ? 0 : 8 }}>
{!props.hideAdd && displayList.length < max && (
-
)}
{Array.isArray(props.buttons)
? props.buttons.map((item, idx) => {
diff --git a/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/SimpleList.js b/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/SimpleList.js
index 60d14556e..2738ac4a0 100644
--- a/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/SimpleList.js
+++ b/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/SimpleList.js
@@ -6,6 +6,7 @@ import {
} from '@ant-design/icons';
import { Button, Popconfirm } from 'antd';
import React from 'react';
+import { useTools } from '../../../hooks';
import Core from '../../index';
const SimpleList = ({
@@ -21,6 +22,11 @@ const SimpleList = ({
getFieldsProps,
}) => {
const { props = {}, itemProps, min = 0, max = 99999 } = schema;
+ const { widgets } = useTools();
+
+ const CustomAddBtn = widgets[schema['add-widget']];
+
+ const AddWidget = CustomAddBtn || Button;
let addBtnProps = {
type: 'dashed',
@@ -37,6 +43,8 @@ const SimpleList = ({
addBtnProps = { ...addBtnProps, ...props.addBtnProps };
}
+ addBtnProps.onClick = addItem;
+
if (props.delConfirmProps && typeof props.delConfirmProps === 'object') {
delConfirmProps = { ...delConfirmProps, ...props.delConfirmProps };
}
@@ -85,7 +93,7 @@ const SimpleList = ({
})}
0 ? 0 : 8 }}>
{!props.hideAdd && displayList.length < max && (
-
+
)}
{Array.isArray(props.buttons)
? props.buttons.map((item, idx) => {
diff --git a/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/index.js b/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/index.js
index 02355a0f8..d19e32d88 100644
--- a/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/index.js
+++ b/packages/form-render/src/form-render-core/src/core/RenderChildren/RenderList/index.js
@@ -1,5 +1,5 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
-import { get } from 'lodash-es';
+import { get, isFunction } from 'lodash-es';
import React from 'react';
import { useStore, useTools } from '../../../hooks';
import {
@@ -128,7 +128,7 @@ const RenderList = ({
};
};
- const displayProps = {
+ let displayProps = {
displayList,
changeList,
schema,
@@ -147,6 +147,18 @@ const RenderList = ({
getFieldsProps,
};
+ // 外部定义:添加按钮事件
+ const onAdd = methods[props.onAdd];
+ if (isFunction(onAdd)) {
+ displayProps.addItem = () => onAdd(addItem, { schema });
+ }
+
+ // 外部定义:删除按钮事件
+ const onRemove = methods[props.onRemove];
+ if (isFunction(onRemove)) {
+ displayProps.deleteItem = (idx) => onRemove(() => deleteItem(idx), { schema })
+ }
+
if (layoutWidgets && layoutWidgets[renderWidget]) {
const Component = layoutWidgets[renderWidget];
return
;
diff --git a/packages/form-render/src/form-render-core/src/core/RenderField/index.js b/packages/form-render/src/form-render-core/src/core/RenderField/index.js
index d15ed3764..1c7ceada5 100644
--- a/packages/form-render/src/form-render-core/src/core/RenderField/index.js
+++ b/packages/form-render/src/form-render-core/src/core/RenderField/index.js
@@ -111,7 +111,7 @@ const RenderField = props => {
}
// 先不暴露给外部,这个api
if (typeof onValuesChange === 'function') {
- onValuesChange({ [dataPath]: value }, formDataRef.current);
+ onValuesChange({ dataPath, value, dataIndex }, formDataRef.current);
}
validateField({
diff --git a/packages/form-render/src/form-render-core/src/index.js b/packages/form-render/src/form-render-core/src/index.js
index 8fa3a4ea6..e2cb2a01d 100644
--- a/packages/form-render/src/form-render-core/src/index.js
+++ b/packages/form-render/src/form-render-core/src/index.js
@@ -53,7 +53,7 @@ function App({
allCollapsed = false,
onValuesChange,
column,
- removeHiddenData = false,
+ removeHiddenData = true,
globalProps = {},
methods = {},
renderTitle,
diff --git a/packages/form-render/src/form-render-core/src/utils.js b/packages/form-render/src/form-render-core/src/utils.js
index eea06eeb4..eac2dcda0 100644
--- a/packages/form-render/src/form-render-core/src/utils.js
+++ b/packages/form-render/src/form-render-core/src/utils.js
@@ -1063,7 +1063,6 @@ export const getHiddenData = (data, flatten) => {
hidden = parseSingleExpression(hidden, result, key);
}
if (hidden) {
- debugger;
hiddenData[key] = result[key];
}
}
diff --git a/packages/form-render/src/index.d.ts b/packages/form-render/src/index.d.ts
index a40d32aa7..0ba3eae78 100644
--- a/packages/form-render/src/index.d.ts
+++ b/packages/form-render/src/index.d.ts
@@ -62,6 +62,8 @@ export interface SchemaBase {
enumNames: Array
| string;
rules: RuleItem | RuleItem[];
props: Record;
+ /**扩展字段 */
+ 'add-widget'?: string;
}
export type Schema = Partial;
@@ -223,11 +225,20 @@ export interface FRProps {
/** 表单提交后钩子 */
onFinish?: (formData: any, error: Error[]) => void;
/** 时时与外部更新同步的钩子 */
- onValuesChange?: (changedValues: any, formData: any) => void;
+ onValuesChange?: (
+ changedValues: {
+ dataPath: string;
+ value: any;
+ dataIndex: number[] | unknown;
+ },
+ formData: any
+ ) => void;
/** 隐藏的数据是否去掉,默认不去掉(false) */
removeHiddenData?: boolean;
/** 配置自定义layout组件 */
layoutWidgets?: any;
+ /** 扩展方法 */
+ methods?: Record;
}
declare const FR: React.FC;