From 54994b7fe86d22c4b167536c65ddfe43f1acf926 Mon Sep 17 00:00:00 2001 From: jile1997 <1154416769@qq.com> Date: Mon, 6 Jan 2025 14:33:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=87=AA=E5=AE=9A=E4=B9=89=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/NodesPopover/index.tsx | 24 ++++++++++++------- packages/x-flow/src/types.ts | 1 + packages/x-flow/src/withProvider.tsx | 2 ++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/x-flow/src/components/NodesPopover/index.tsx b/packages/x-flow/src/components/NodesPopover/index.tsx index d6032a392..575bfbf15 100644 --- a/packages/x-flow/src/components/NodesPopover/index.tsx +++ b/packages/x-flow/src/components/NodesPopover/index.tsx @@ -1,5 +1,6 @@ import { useClickAway } from 'ahooks'; import { Popover } from 'antd'; +import { isFunction } from 'lodash'; import React, { forwardRef, useCallback, @@ -24,7 +25,7 @@ export default forwardRef((props: any, popoverRef) => { const closeRef: any = useRef(null); const [open, setOpen] = useState(false); - const { settings, nodeSelector, antdVersion ,readOnly }: any = useContext(ConfigContext); + const { settings, nodeSelector, antdVersion ,readOnly ,clickAddNode }: any = useContext(ConfigContext); const { showSearch, popoverProps = { placement: 'top' } } = nodeSelector || {}; @@ -41,13 +42,20 @@ export default forwardRef((props: any, popoverRef) => { }, ref); const handCreateNode = useCallback(({ type }) => { - if (type === 'Switch') { - addNode({ _nodeType: type, list: [{ '_id':`${uuid()}`}] }); - } else if (type === 'Parallel') { - addNode({ _nodeType: type, list: [{ _id: `id_${uuid()}` }, { _id: `id_${uuid()}` }] }); - } else { - addNode({ _nodeType: type }); + if (isFunction(clickAddNode)) { + clickAddNode(type, ( data = {} )=>{ + addNode({ _nodeType: type, ...data }) + }); + }else{ + if (type === 'Switch') { + addNode({ _nodeType: type, list: [{ '_id':`${uuid()}`}] }); + } else if (type === 'Parallel') { + addNode({ _nodeType: type, list: [{ _id: `id_${uuid()}` }, { _id: `id_${uuid()}` }] }); + } else { + addNode({ _nodeType: type }); + } } + setOpen(false); onNodeSelectPopoverChange && onNodeSelectPopoverChange(false); }, []); @@ -56,7 +64,7 @@ export default forwardRef((props: any, popoverRef) => { setTimeout(() => { setIsAddingNode(true); closeRef.current = true; - if(!readOnly){ + if (!readOnly) { setOpen(true); } }, 50); diff --git a/packages/x-flow/src/types.ts b/packages/x-flow/src/types.ts index 427bd67bf..51469b876 100644 --- a/packages/x-flow/src/types.ts +++ b/packages/x-flow/src/types.ts @@ -125,6 +125,7 @@ export interface FlowProps { panel?:TPanel //表单配置面板 onNodeClick?: NodeMouseHandler; onMenuItemClick: (itemInfo: ItemInfo, defaultAction: () => void) => void; + clickAddNode:(type:string,addNode:(initData?:Record)=>void)=>void // 单点调试方法 } interface ItemInfo { diff --git a/packages/x-flow/src/withProvider.tsx b/packages/x-flow/src/withProvider.tsx index 3a740a867..3288e1a0c 100644 --- a/packages/x-flow/src/withProvider.tsx +++ b/packages/x-flow/src/withProvider.tsx @@ -32,6 +32,7 @@ export default function withProvider( onMenuItemClick, antdVersion ='V4', readOnly, + clickAddNode, ...restProps } = props; const settingMap = useMemo(() => { @@ -59,6 +60,7 @@ export default function withProvider( antdVersion, onMenuItemClick, readOnly, + clickAddNode, widgets: { ...defaultWidgets, ...widgets,