@@ -32,6 +32,7 @@ import FlowProps from './types';
3232import { isTruthy , uuid , uuid4 } from './utils' ;
3333import autoLayoutNodes from './utils/autoLayoutNodes' ;
3434
35+ import { message } from 'antd' ;
3536import { shallow } from 'zustand/shallow' ;
3637import NodeEditor from './components/NodeEditor' ;
3738import NodeLogPanel from './components/NodeLogPanel' ;
@@ -87,6 +88,7 @@ const XFlow: FC<FlowProps> = memo(props => {
8788 const [ openPanel , setOpenPanel ] = useState < boolean > ( true ) ;
8889 const [ openLogPanel , setOpenLogPanel ] = useState < boolean > ( true ) ;
8990 const { onNodeClick } = props ;
91+ const nodeEditorRef = useRef ( null ) ;
9092
9193 useEffect ( ( ) => {
9294 zoomTo ( 0.8 ) ;
@@ -226,7 +228,14 @@ const XFlow: FC<FlowProps> = memo(props => {
226228 type = { _nodeType }
227229 layout = { layout }
228230 status = { _status }
229- onClick = { e => {
231+ onClick = { async e => {
232+ if ( nodeEditorRef ?. current ?. validateForm ) {
233+ const result = await nodeEditorRef ?. current ?. validateForm ( ) ;
234+ if ( ! result ) {
235+ message . error ( '请检查必填项!' ) ;
236+ return ;
237+ }
238+ }
230239 setActiveNode ( {
231240 id,
232241 _nodeType,
@@ -249,6 +258,7 @@ const XFlow: FC<FlowProps> = memo(props => {
249258 onChange = { handleNodeValueChange }
250259 nodeType = { activeNode ?. _nodeType }
251260 id = { activeNode ?. id }
261+ ref = { nodeEditorRef }
252262 />
253263 ) ;
254264 } , [ activeNode ?. id ] ) ;
@@ -286,7 +296,6 @@ const XFlow: FC<FlowProps> = memo(props => {
286296 } ) ;
287297 return result ;
288298 } ;
289- console . log ( '121212' , nodes , getNodesJ ( nodes ) , edges ) ;
290299
291300 return (
292301 < div id = "xflow-container" ref = { workflowContainerRef } >
@@ -362,8 +371,14 @@ const XFlow: FC<FlowProps> = memo(props => {
362371 < PanelContainer
363372 id = { activeNode ?. id }
364373 nodeType = { activeNode ?. _nodeType }
365- onClose = { ( ) => {
374+ onClose = { async ( ) => {
375+ // 面板关闭校验表单
376+ const result = await nodeEditorRef ?. current ?. validateForm ( ) ;
377+ if ( ! result ) {
378+ return ;
379+ }
366380 setOpenPanel ( false ) ;
381+
367382 // 如果日志面板关闭
368383 if ( ! isTruthy ( activeNode ?. _status ) || ! openLogPanel ) {
369384 setActiveNode ( null ) ;
0 commit comments