- {/* 添加一个拖拽区域覆盖整个画布 - 只在拖拽时激活 */}
-
{
- e.preventDefault();
- setIsDraggingOver(true);
- }}
- onDragLeave={(e) => {
- e.preventDefault();
- // 只有当真正离开容器时才设置 false
- if (!e.currentTarget.contains(e.relatedTarget as Node)) {
- setIsDraggingOver(false);
- }
- }}
- onDragOver={(e) => {
- e.preventDefault();
- // 检查是否允许 move 操作,否则使用 copy
- if (e.dataTransfer.effectAllowed.includes('move')) {
- e.dataTransfer.dropEffect = 'move';
- } else {
- e.dataTransfer.dropEffect = 'copy';
- }
- console.log('Overlay dragover event triggered');
- }}
- onDrop={(e) => {
- e.preventDefault();
- e.stopPropagation();
- setIsDraggingOver(false);
- console.log('Overlay drop event triggered');
-
- const data = e.dataTransfer.getData('application/json');
- console.log('Overlay drop data:', data);
-
- if (data) {
- try {
- const parsedData = JSON.parse(data);
- console.log('Overlay parsed data:', parsedData);
- if (parsedData.type === 'test-step') {
- const { step } = parsedData;
- // 获取 React Flow 容器的边界并计算相对位置
- const reactFlowBounds = reactFlowWrapper.current?.getBoundingClientRect();
- const position = project({
- x: e.clientX - (reactFlowBounds?.left || 0),
- y: e.clientY - (reactFlowBounds?.top || 0),
- });
-
- // 检查是否可以添加此类型的节点
- if (!canAddNodeType(step.stepType)) {
- console.log('Cannot add node: type limit reached');
- return;
- }
-
- const newNode = {
- id: `node-${Date.now()}`,
- type: 'testStep',
- position,
- data: {
- stepId: step.id,
- stepName: step.stepName,
- stepType: step.stepType,
- stepTypeName: step.stepTypeName,
- description: step.description,
- icon: step.icon,
- },
- };
-
- console.log('Adding node via overlay drop:', newNode);
- setNodes((nds) => nds.concat(newNode));
- }
- } catch (error) {
- console.error('Error in overlay drop handler:', error);
- }
- }
- }}
- />
{showControls && }
- {showMiniMap && }
缩放: {Math.round(currentZoom * 100)}%
@@ -678,6 +669,12 @@ function ReactFlowDesignerInner({
+
+
+
节点: {nodes.length}
+
连线: {edges.length}
+
+
diff --git a/src/X1.WebUI/src/pages/testcases/ReactFlowTest.tsx b/src/X1.WebUI/src/pages/testcases/ReactFlowTest.tsx
new file mode 100644
index 0000000..daf84ef
--- /dev/null
+++ b/src/X1.WebUI/src/pages/testcases/ReactFlowTest.tsx
@@ -0,0 +1,117 @@
+import React, { useState, useCallback } from 'react';
+import ReactFlow, {
+ Node,
+ Edge,
+ addEdge,
+ Connection,
+ useNodesState,
+ useEdgesState,
+ Handle,
+ Position,
+ ReactFlowProvider,
+} from 'reactflow';
+import 'reactflow/dist/style.css';
+
+// 简单的测试节点
+const TestNode = ({ data }: { data: any }) => {
+ return (
+
+
+
+ {data.emoji}
+
+
+
{data.label}
+
{data.type}
+
+
+
+
+
+
+ );
+};
+
+const nodeTypes = {
+ testNode: TestNode,
+};
+
+const initialNodes: Node[] = [
+ {
+ id: '1',
+ type: 'testNode',
+ position: { x: 250, y: 100 },
+ data: { label: '开始', type: '开始节点', emoji: '🚀' },
+ },
+ {
+ id: '2',
+ type: 'testNode',
+ position: { x: 250, y: 300 },
+ data: { label: '处理', type: '处理节点', emoji: '⚙️' },
+ },
+ {
+ id: '3',
+ type: 'testNode',
+ position: { x: 250, y: 500 },
+ data: { label: '结束', type: '结束节点', emoji: '🏁' },
+ },
+];
+
+function ReactFlowTestInner() {
+ const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes);
+ const [edges, setEdges, onEdgesChange] = useEdgesState([]);
+
+ const onConnect = useCallback(
+ (params: Connection) => {
+ console.log('连接参数:', params);
+ if (params.source && params.target) {
+ const newEdge = {
+ ...params,
+ id: `edge-${Date.now()}`,
+ type: 'smoothstep',
+ animated: false,
+ style: { stroke: '#3b82f6', strokeWidth: 2 },
+ };
+ console.log('创建新连线:', newEdge);
+ setEdges((eds) => {
+ const updatedEdges = addEdge(newEdge, eds);
+ console.log('当前所有连线:', updatedEdges);
+ return updatedEdges;
+ });
+ }
+ },
+ [setEdges]
+ );
+
+ return (
+
+
+
+ );
+}
+
+export default function ReactFlowTest() {
+ return (
+
+
+
+ );
+}