File tree Expand file tree Collapse file tree
src/components/flow/nodes/utils Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,8 +139,28 @@ export function saveNodeAsTemplate(
139139 * 删除节点(通用工具函数)
140140 * @param nodeId 节点ID
141141 */
142- export function deleteNode ( nodeId : string ) : void {
142+ export async function deleteNode ( nodeId : string ) : Promise < void > {
143143 const flowStore = useFlowStore . getState ( ) ;
144+ const { instance, edges } = flowStore ;
145+
146+ if ( instance ) {
147+ const nodeToDelete = flowStore . nodes . find ( ( n ) => n . id === nodeId ) ;
148+ if ( nodeToDelete ) {
149+ await instance . deleteElements ( { nodes : [ nodeToDelete ] } ) ;
150+ return ;
151+ }
152+ }
153+
154+ const connectedEdgeIds = edges
155+ . filter ( ( edge ) => edge . source === nodeId || edge . target === nodeId )
156+ . map ( ( edge ) => edge . id ) ;
157+
158+ if ( connectedEdgeIds . length > 0 ) {
159+ flowStore . updateEdges (
160+ connectedEdgeIds . map ( ( id ) => ( { id, type : "remove" as const } ) ) ,
161+ ) ;
162+ }
163+
144164 flowStore . updateNodes ( [ { type : "remove" , id : nodeId } ] ) ;
145165}
146166
You can’t perform that action at this time.
0 commit comments