From e61a504e4546e86e5e94f295ec1a2ec50dba4477 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 29 二月 2024 15:19:53 +0800
Subject: [PATCH] #

---
 zy-asrs-flow/src/pages/home/index.jsx |  180 ++++++++++++++++++++++++++++-------------------------------
 1 files changed, 85 insertions(+), 95 deletions(-)

diff --git a/zy-asrs-flow/src/pages/home/index.jsx b/zy-asrs-flow/src/pages/home/index.jsx
index 6372cd8..92634cc 100644
--- a/zy-asrs-flow/src/pages/home/index.jsx
+++ b/zy-asrs-flow/src/pages/home/index.jsx
@@ -1,101 +1,91 @@
-import React, { useState } from 'react'
-import { XFlow, XFlowCanvas } from '@antv/xflow'
-/** 鍥剧殑鍚勭鎵╁睍浜や簰缁勪欢 */
-import { CanvasMiniMap, CanvasScaleToolbar, CanvasSnapline } from '@antv/xflow'
-/** 鍥剧殑閰嶇疆椤� */
-import { useGraphConfig } from './config-graph'
-import { message } from 'antd'
+import React, { useEffect, useState } from 'react';
+import ReactDOM from 'react-dom';
+import { data } from './data';
+import G6 from '@antv/g6';
+import "./index.css"
 
-import './index.css'
+export default function() {
+  const ref = React.useRef(null);
+  let graph = null;
 
-const Demo = () => {
-    /** 鐢诲竷閰嶇疆 */
-    const graphConfig = useGraphConfig()
-
-    /** 鐢诲竷娓叉煋鏁版嵁 */
-    const [graphData, setGraphData] = useState()
-
-    /** XFlow鍒濆鍖栧畬鎴愮殑鍥炶皟 */
-    const onLoad = async app => {
-        const node = [
-            { id: 'root1', width: 150, height: 40, renderKey: 'NODE1', info: { text: 'root1' } },
-            { id: 'down1', width: 150, height: 40, renderKey: 'NODE2', info: { text: 'down1' } },
-            { id: 'down2', width: 150, height: 40, renderKey: 'NODE2', info: { text: 'down2' } },
-            { id: 'down3', width: 150, height: 40, renderKey: 'NODE2', info: { text: 'down3' } },
-        ]
-        const edges = [
-            {
-                id: 'root1-down1',
-                source: 'root1',
-                target: 'down1',
-                renderKey: 'EDGE1',
-                edgeContentWidth: 60,
-                edgeContentHeight: 30,
-                info: { line: 'root1-down1' },
+  useEffect(() => {
+    if (!graph) {
+      graph = new G6.Graph({
+        container: ReactDOM.findDOMNode(ref.current),
+        width: document.documentElement.clientWidth,
+        height: document.documentElement.clientHeight,
+        modes: {
+          default: [
+            'drag-canvas', 
+            'zoom-canvas',
+            'drag-node',
+          ],
+          edit: ['click-select']
+        },
+        layout: {
+          type: 'dagre',
+          direction: 'LR',
+        },
+        defaultNode: {
+          shape: 'node',
+          type: 'rect',
+          labelCfg: {
+            style: {
+              fill: '#000000A6',
+              fontSize: 14,
             },
-            {
-                id: 'root1-down2',
-                source: 'root1',
-                target: 'down2',
-                renderKey: 'EDGE2',
-                edgeContentWidth: 60,
-                edgeContentHeight: 30,
-                info: { line: 'root1-down2' },
-            },
-            {
-                id: 'root1-down3',
-                source: 'root1',
-                target: 'down3',
-                label: '1:N(绾枃鏈�)',
-                info: { line: 'root1-down3' },
-            },
-        ]
-        const newGraphData = { nodes, edges }
-        setGraphData(newGraphData)
-
-        const graph = await app.getGraphInstance()
-        graph.on('node:click', ({ node }) => {
-            const nodeData = node.getData()
-            message.success(`${nodeData.id}鑺傜偣琚偣鍑讳簡`)
-        })
-        graph.on('edge:click', ({ edge }) => {
-            edge.toFront()
-            const edgeData = edge.getData()
-            message.success(`${edgeData.id}杩炵嚎琚偣鍑讳簡`)
-        })
+          },
+          style: {
+            // 浠呭湪 keyShape 涓婄敓鏁�
+            fill: 'lightblue',
+            stroke: '#888',
+            lineWidth: 1,
+            radius: 7,
+          },
+          linkPoints: {
+            top: true,
+            bottom: true,
+            left: true,
+            right: true,
+            // ... 鍥涗釜鍦嗙殑鏍峰紡鍙互鍦ㄨ繖閲屾寚瀹�
+          },
+        },
+        defaultEdge: {
+          shape: 'polyline',
+        },
+        nodeStateStyles: {
+          // 鍚勭姸鎬佷笅鐨勬牱寮忥紝骞抽摵鐨勯厤缃」浠呭湪 keyShape 涓婄敓鏁堛�傞渶瑕佸湪鍏朵粬 shape 鏍峰紡涓婂搷搴旂姸鎬佸彉鍖栧垯鍐欐硶涓嶅悓锛屽弬瑙佷笂鏂囨彁鍒扮殑 閰嶇疆鐘舵�佹牱寮� 閾炬帴
+          hover: {
+            fillOpacity: 0.1,
+            lineWidth: 1,
+          },
+        },
+      });
     }
+    graph.data(data);
+    graph.render();
+    
+    // 鐩戝惉榧犳爣杩涘叆鑺傜偣浜嬩欢
+    graph.on('node:mouseenter', (evt) => {
+      const node = evt.item;
+      // 婵�娲昏鑺傜偣鐨� hover 鐘舵��
+      graph.setItemState(node, 'hover', true);
+    });
 
-    return (
-        <XFlow
-            className="xflow-user-container"
-            graphData={graphData}
-            graphLayout={{
-                layoutType: 'dagre',
-                layoutOptions: {
-                    type: 'dagre',
-                    rankdir: 'TB',
-                    nodesep: 60,
-                    ranksep: 40,
-                },
-            }}
-            onLoad={onLoad}
-            isAutoCenter={true}
-        >
-            <XFlowCanvas config={graphConfig}>
-                <CanvasScaleToolbar position={{ top: 12, left: 12 }} />
-                <CanvasMiniMap
-                    miniMapClz="xflow-custom-minimap"
-                    nodeFillColor="#ccc"
-                    minimapOptions={{
-                        width: 200,
-                        height: 120,
-                    }}
-                    position={{ top: 12, right: 12 }}
-                />
-                <CanvasSnapline color="#1890ff" />
-            </XFlowCanvas>
-        </XFlow>
-    )
-}
+    // 鐩戝惉榧犳爣绂诲紑鑺傜偣浜嬩欢
+    graph.on('node:mouseleave', (evt) => {
+      const node = evt.item;
+      // 鍏抽棴璇ヨ妭鐐圭殑 hover 鐘舵��
+      graph.setItemState(node, 'hover', false);
+    });
 
-export default Demo
\ No newline at end of file
+    graph.on('node:click', (evt) => {
+      const node = evt.item;
+      const model = node.getModel();
+      // 鍦ㄨ繖閲屾墦寮�妯℃�佹鎴栬�呯紪杈戣〃鏍硷紝浼犲叆model浠ヤ究鐢ㄤ簬鍒濆鍖栫紪杈戝唴瀹�
+      showModal(model);
+    });
+  }, []);
+
+  return <div ref={ref}></div>;
+}
\ No newline at end of file

--
Gitblit v1.9.1