FlowChartRt.jsx 41.8 KB
Newer Older
邓超's avatar
邓超 committed
1 2 3
/* eslint-disable global-require */
import React, { useState, useEffect, useRef } from 'react';
import { useHistory, Prompt } from 'react-router-dom';
4
import { Button, Modal, notification, Spin, Empty, Tooltip, message, TreeSelect } from 'antd';
邓超's avatar
邓超 committed
5 6 7 8 9 10 11 12 13
import lodash from 'lodash';
import {
  SaveNodeChange,
  GetFlowNode,
  FlowNodeSave,
  DeleteFlowNode,
  DeleteFlowNodes,
  SaveWorkFlowImage,
} from '@/services/workflow/workflow';
14
import { compress } from '@/utils/utils';
邓超's avatar
邓超 committed
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
import { ExclamationCircleOutlined, TrophyOutlined } from '@ant-design/icons';
import * as go from 'gojs';
import styles from './FlowBoard.less';
// import styles from '../workflow.less';
import NodeModal from './flowChartComponents/NodeModal';
import LineModal from './flowChartComponents/LineModal';
// import imgUrl from '@/assets/images/icons/closeBlue.png';
import nodeEnd from '@/assets/images/workFlow/nodeEnd.svg';
import nodeGeneral from '@/assets/images/workFlow/nodeGeneral.svg';
import nodeStart from '@/assets/images/workFlow/nodeStart.svg';
// import cc from '@/assets/images/workFlow/cc.png';
import gatewayCondition from '@/assets/images/workFlow/gatewayCondition.svg';
import gatewayParallel from '@/assets/images/workFlow/gatewayParallel.svg';
import gatewayJoin from '@/assets/images/workFlow/gatewayJoin.svg';

const { confirm } = Modal;
31
const { TreeNode } = TreeSelect;
邓超's avatar
邓超 committed
32 33 34 35 36 37 38 39
let diagram = null;
let myPaletteNode = null;
let myPaletteGateway = null;
let myPaletteSubprocess = null;
let myOverview = null;
const FlowChart = props => {
  const history = useHistory();

邓超's avatar
邓超 committed
40 41 42 43 44 45 46 47 48 49
  const {
    flowData,
    flowID,
    chartLoading,
    msg,
    treeVisible,
    activeKey,
    flowTree,
    scrollTop,
  } = props;
邓超's avatar
邓超 committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  const [visible, setVisible] = useState(false);
  const [lineVisible, setLineVisible] = useState(false);
  const [editMsg, setEditMsg] = useState({}); // 编辑节点的信息
  const [lineMsg, setLineMsg] = useState({});
  const [modalType, setModalType] = useState(''); // 存入弹窗是编辑还是新增
  const [LineKey, setLineKey] = useState(''); //  存入编辑线id
  const [nodeKey, setNodeKey] = useState(''); // 存入编辑节点的key
  const [DeleteNodes, setDeleteNodes] = useState([]); // 删除节点数组
  const [DeleteLines, setDeleteLines] = useState([]); // 删除线数组
  const [deleteLine, setDeleteLine] = useState(); // 删除的线id
  const [deleteNode, setDeleteNode] = useState(); // 删除的节点id
  const [AddNodes, setAddNodes] = useState([]); // 新增数组
  const [initFlowData, setInitFlowData] = useState({}); // 初始数据,用来比对是否有修改流程图
  const [currentFlowData, setCurrentFlowData] = useState({
    Nodes: [],
    Lines: [],
  }); // 组件内得流程图数据
  const [showLeaveTip, setShowLeaveTip] = useState(false); // 离开路由是否又提醒
  const [buttonLoading, setButtonLoading] = useState(); // 发布按钮保存loading
69
  const [selectValue, setSelectValue] = useState();
邓超's avatar
邓超 committed
70 71 72 73 74 75 76 77 78 79 80
  const [flag, setFlag] = useState(0);
  const currentNode = useRef();
  const afterNodes = useRef(new Map([])); // 当前节点后所有节点
  const limitFinshNodes = useRef([new Set([])]);
  const objGo = go.GraphObject.make;
  useEffect(() => {
    if (treeVisible) {
      setVisible(false);
    }
  }, [treeVisible]);

81 82 83 84 85 86 87 88 89 90 91
  // // 监听删除,给删除数组里添加删除id
  // useEffect(() => {
  //   if (deleteLine) {
  //     setDeleteLines([...DeleteLines, deleteLine]);
  //   }
  // }, [deleteLine]);
  // useEffect(() => {
  //   if (deleteNode) {
  //     setDeleteNodes([...DeleteNodes, deleteNode]);
  //   }
  // }, [deleteNode]);
邓超's avatar
邓超 committed
92 93 94 95 96 97 98
  // 初始化
  useEffect(() => {
    // 初始化流程图
    init();
    initPalette();
    myOverview = objGo(go.Overview, 'myOverviewDiv', { observed: diagram });
    // 监听节点或线的删除事件
99 100 101 102 103 104 105 106 107 108
    // diagram.addDiagramListener('SelectionDeleted', e => {
    //   let delNodes = [];
    //   let delLinks = [];
    //   e.subject.each(n => {
    //     if (n.data.LineId) {
    //       delLinks.push(n.data.LineId);
    //     }
    //     if (n.data.ActivityId) {
    //       delNodes.push(n.data.ActivityId);
    //     }
邓超's avatar
邓超 committed
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
    //     // 如果删除得节点不是新增得就给id放入到删除节点数组中
    //     if (n.data.NodeId && !AddNodes.some(item => item === n.data.NodeId)) {
    //       setTimeout(() => {
    //         setDeleteNode(n.data.NodeId);
    //       }, 0);
    //     }
    //     if (n.data.LineKey) {
    //       setTimeout(() => {
    //         setDeleteLine(n.data.LineId);
    //       }, 0);
    //     }
    //   });
    //   if (delNodes.length === 0) {
    //     return;
    //   }
    //   DeleteFlowNodes({ ActivityIds: delNodes, LineIds: delLinks }).then(res => {
    //     if (res.code === 0) {
    //       message.success('删除成功');
    //     } else {
    //       // message.error(res.msg);
    //       message.error({
    //         content: <div style={{ whiteSpace: 'pre-line', textAlign: 'justify' }}>{res.msg}</div>,
    //       });
    //     }
    //   });
    //   console.log(delNodes, delLinks, 'fffff');
    // });
    // 监听节点或线的删除前事件
    diagram.commandHandler.canDeleteSelection = () => {
      let delNodes = new Set();
      let delNodeIds = new Set();
      let delLinks = new Set();
      diagram.selection.toArray().forEach(item => {
        if (item.data.ActivityId) {
          delNodes.add(item.data.ActivityId);
          delNodeIds.add(item.data.NodeId);
          item.findLinksConnected().each(link => {
            if (link.data.LineId) {
              delLinks.add(link.data.LineId);
            }
          });
邓超's avatar
邓超 committed
151
        }
152 153
        if (item.data.LineId) {
          delLinks.add(item.data.LineId);
邓超's avatar
邓超 committed
154 155
        }
      });
156 157 158
      showDeleteConfirm([...delNodeIds], [...delNodes], [...delLinks]);
      return false;
    };
邓超's avatar
邓超 committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
    // 监听线,连接线的时候加上text属性
    diagram.addDiagramListener('LinkDrawn', e => {
      // e.subject.data.text = '';
      e.subject.data.lineDetail = JSON.stringify(e.subject.data);
      console.log(e, e.subject.data, 'fasdfasdgds');
      diagram.model.updateTargetBindings(e.subject.data);
      // leaveCallBack(true);
    });
    // 监听节点拖拽到画布事件
    diagram.addDiagramListener('externalobjectsdropped', e => {
      afterNodes.current = new Map([]);
      const list = JSON.parse(diagram.model.toJson()).nodeDataArray;
      console.log(list, 'list');
      let newNum;
      let newKey;

      if (list.length > 0) {
        // eslint-disable-next-line prefer-spread
        newNum = Math.max.apply(Math, list.map(item => item.SerialNo)) + 1;
        // eslint-disable-next-line prefer-spread
        newKey = Math.max.apply(Math, list.map(item => item.key)) + 1;
      } else {
        newKey = 1;
        newNum = 1;
      }
      console.log(e);
      e.subject.each(n => {
        // 得到从Palette拖过来的节点
        console.log(n.data.key);
        let nodeData = diagram.model.findNodeDataForKey(n.data.key);
        nodeData.NodeName = `${n.data.NodeName}${newKey}`;
        nodeData.NodeAliasName = nodeData.NodeName;
        nodeData.SerialNo = newNum;
        // nodeData.key = newKey;
        nodeData.NodeId = newKey;
        nodeData.nodeDetail = JSON.stringify(nodeData);
        console.log(nodeData);
        diagram.model.updateTargetBindings(nodeData);
        diagram.model.setDataProperty(nodeData, 'key', newKey);

        currentNode.current = nodeData;
        setNodeKey(nodeData.key);
        setEditMsg(nodeData);
        setModalType('edit');
        setVisible(true);
      });
      setAddNodes([...AddNodes, newKey]);

      leaveTip();
    });
    // diagram.addDiagramListener('SelectionDeleted', e => {

    // });
  }, []);
  useEffect(() => {
    if (flowData) {
      console.log(flowData, 'msgmsgmsg');
      // 每次切换时清空删除得id数组跟新增得id数组
      setDeleteNodes([]);
      setDeleteLines([]);
      setAddNodes([]);
      setDeleteNode('');
      setDeleteLine('');
      setEditMsg({});
      let dataList = lodash.cloneDeep(flowData);
      console.log(dataList, 'dataList');

      setCurrentFlowData(dataList);
      setShowLeaveTip(false);
      setVisible(false);
    }
  }, [flowData]);
  // 存入在树形流程中选择得流程数据
  useEffect(() => {
    let nodeDataArray = [];
    let linkDataArray = [];

    // 处理老数据,让老数据可以正常展示
    limitFinshNodes.current = new Set([]);
    nodeDataArray = currentFlowData.Nodes.map((item, index) => {
      if (item.FlowTimerList.length > 0) {
        item.FlowTimerList.forEach(ele => {
          limitFinshNodes.current.add(ele.EndNode);
        });
      }
      let obj;
      obj = item;
      obj.key = item.NodeId;
      if (!obj.NodeAliasName) {
        obj.NodeAliasName = obj.NodeName;
      }
      obj.nodeDetail = JSON.stringify(obj);
      obj.CarbonCopyPeopleList = obj.CarbonCopyPeopleList.map(ele => ({
        label: ele.userName,
        value: ele.userID,
      }));
      if (obj.points === '') {
        if (obj.NodeType === '1') {
          obj.points = `${(index * 200).toString()}" 100"`;
        } else {
          obj.points = `${(index * 200).toString()}" -22"`;
        }
      }
      return obj;
    });
    linkDataArray = currentFlowData.Lines.map(item => {
      let obj;
      obj = item;
      obj.LineKey = item.LineId;
      obj.lineDetail = JSON.stringify(obj);
      return obj;
    });

    // 保存初始数据
    setInitFlowData(
      JSON.parse(
        JSON.stringify({
          Nodes: nodeDataArray,
          Lines: linkDataArray,
        }),
      ),
    );
    diagram.model = go.Model.fromJson({
      linkFromPortIdProperty: 'fromPort', // 所需信息:
      linkToPortIdProperty: 'toPort', // 标识数据属性名称
      nodeDataArray,
      linkDataArray,
    });
    // 初次选中
    if (nodeDataArray?.length > 0) {
      currentNode.current = diagram.model.findNodeDataForKey(
        nodeDataArray[nodeDataArray.length - 1].NodeId,
      );
      setNodeKey(currentNode.current.key);
      setEditMsg(currentNode.current);
      setModalType('edit');
      setVisible(true);
    }

    // 修改复制后节点内容
    diagram.model.copyNodeDataFunction = (obj, model) => {
      let copyObj = lodash.cloneDeep(obj);
      console.log(copyObj, 'copyObj');
      copyObj.FlowTimerList.forEach(item => {
        item.key = item.ID;
        delete item.ID;
      });
      delete copyObj.ActivityId;
      delete copyObj.FlowNodeExtendId;
      return copyObj;
    };
    // 修改复制后线内容
    diagram.model.copyLinkDataFunction = (obj, model) => {
      let copyObj = lodash.cloneDeep(obj);
      delete copyObj.LineId;
      return copyObj;
    };

    diagram.model.linkKeyProperty = 'LineKey';

    diagram.model.makeUniqueLinkKeyFunction = (model, data) => {
      let i = model.linkDataArray.length * 2 + 2;
      while (model.findLinkDataForKey(i) !== null) i += 2;
      return i;
    };
  }, [currentFlowData]);
  // 删除提醒
326
  const showDeleteConfirm = (delNodeIds, delNodes, delLinks) => {
邓超's avatar
邓超 committed
327 328 329 330 331 332 333 334
    confirm({
      title: '确定要删除所选中的节点吗?',
      icon: <ExclamationCircleOutlined />,
      content: '',
      okText: '是',
      okType: 'danger',
      cancelText: '否',
      onOk() {
335
        delNode(delNodeIds, delNodes, delLinks);
邓超's avatar
邓超 committed
336 337 338 339 340
      },
      onCancel() {},
    });
  };
  // 删除节点
341
  const delNode = (delNodeIds, delNodes, delLinks) => {
邓超's avatar
邓超 committed
342
    setShowLeaveTip(true);
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
    if (delNodes.length === 0) {
      diagram.commandHandler.deleteSelection();
      return;
    }
    DeleteFlowNodes({ ActivityIds: delNodes, LineIds: delLinks }).then(res => {
      if (res.code === 0) {
        diagram.commandHandler.deleteSelection();
        setDeleteNodes([...DeleteNodes, ...delNodeIds]);
        setDeleteLines([...DeleteLines, ...delLinks]);
        message.success('删除成功');
      } else {
        // message.error(res.msg);
        message.error({
          content: <div style={{ whiteSpace: 'pre-line', textAlign: 'justify' }}>{res.msg}</div>,
        });
      }
    });
邓超's avatar
邓超 committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
  };

  const animateFadeDown = e => {
    let diagrams = e.diagram;
    let animation = new go.Animation();
    animation.isViewportUnconstrained = true; // 所以图表定位规则让动画在屏幕外开始
    animation.easing = go.Animation.EaseOutExpo;
    animation.duration = 900;
    // 淡入“向下”,换句话说,从上方淡入
    animation.add(diagrams, 'position', diagrams.position.copy().offset(0, 200), diagrams.position);
    animation.add(diagrams, 'opacity', 0, 1);
    animation.start();
  };
  // 初始化拖拽面板
  const initPalette = () => {
    const defaultField = {
      aheadHandle: 1,
      NodeHandling: 1,
      RuleList: [],
      roleList: [],
      CarbonCopyPeopleList: [],
      ExtendPageList: [],
      FlowTimerList: [],
      TurnOnCc: 0,
      NodeAliasName: '',
385

邓超's avatar
邓超 committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
      TableName: '',
      Fields: '',
      WebPage: '',
      FeedbackName: '',
      Transferable: 0,
      EventsInformation: 0,
      IsSendMessage: 1,
      IsSave: 0,
      AutoClose: '否',
      HalfwayClose: 0,
      RollbackNode: '(上一节点)',
      Rollbackable: false,
    };
    myPaletteNode = objGo(go.Palette, 'myPaletteNode', {
      // 代替默认动画,使用自定义淡入淡出
      'animationManager.initialAnimationStyle': go.AnimationManager.None,
      InitialAnimationStarting: animateFadeDown, // 相反,使用此功能制作动画
      // nodeTemplateMap: diagram.nodeTemplateMap, // 分享 myDiagram 使用的模板
      scale: '1',
      nodeSelectionAdornmentTemplate: objGo(
        go.Adornment,
        'Auto',
        objGo(go.Shape, 'Rectangle', { fill: 'white', stroke: null }),
      ), // 去掉节点点击时的边框颜色
      model: new go.GraphLinksModel([
        // 指定调色板的内容
        {
          category: 'nodeStart',
          NodeName: '开始节点',
          NodeType: '1',
          SerialNo: 0,
417
          Handover: '移交选择人',
邓超's avatar
邓超 committed
418 419 420 421 422 423 424
          ...defaultField,
        },
        {
          category: 'nodeGeneral',
          NodeName: '普通节点',
          NodeType: '0',
          SerialNo: 0,
425
          Handover: '移交选择人',
邓超's avatar
邓超 committed
426 427 428 429 430 431 432
          ...defaultField,
        },
        {
          category: 'nodeEnd',
          NodeName: '结束节点',
          NodeType: '2',
          SerialNo: 0,
433
          Handover: '自处理',
邓超's avatar
邓超 committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989
          ...defaultField,
        },
      ]),
    });
    myPaletteNode.nodeTemplate = objGo(
      go.Node,
      'Auto',
      new go.Binding('location', 'points', go.Point.parse).makeTwoWay(go.Point.stringify),
      // 节点样式配置
      objGo(
        go.Panel,
        { width: 108, height: 42 },
        objGo(
          go.Picture,
          { width: 108, height: 42 },
          new go.Binding('source', 'NodeType', v => {
            switch (v) {
              case '1':
                return require('../../../../../assets/images/workFlow/icon1.svg');
              case '2':
                return require('../../../../../assets/images/workFlow/icon3.svg');
              case '0':
                return require('../../../../../assets/images/workFlow/icon2.svg');

              default:
                return null;
            }
          }),
        ),
      ),
    );
    myPaletteGateway = objGo(go.Palette, 'myPaletteGateway', {
      // 代替默认动画,使用自定义淡入淡出
      'animationManager.initialAnimationStyle': go.AnimationManager.None,
      InitialAnimationStarting: animateFadeDown, // 相反,使用此功能制作动画
      // nodeTemplateMap: diagram.nodeTemplateMap, // 分享 myDiagram 使用的模板
      scale: '1',
      nodeSelectionAdornmentTemplate: objGo(
        go.Adornment,
        'Auto',
        objGo(go.Shape, 'Rectangle', { fill: 'white', stroke: null }),
      ), // 去掉节点点击时的边框颜色
      model: new go.GraphLinksModel([
        // 指定调色板的内容
        {
          category: 'gatewayCondition',
          NodeName: '条件网关',
          NodeType: '20',
          SerialNo: 0,
          ...defaultField,
        },
        {
          category: 'gatewayParallel',
          NodeName: '并行网关',
          NodeType: '22',
          SerialNo: 0,
          ...defaultField,
        },
        {
          category: 'gatewayJoin',
          NodeName: '汇合网关',
          NodeType: '21',
          SerialNo: 0,
          ...defaultField,
        },
      ]),
    });
    myPaletteGateway.nodeTemplate = objGo(
      go.Node,
      'Auto',
      new go.Binding('location', 'points', go.Point.parse).makeTwoWay(go.Point.stringify),
      // 节点样式配置
      objGo(
        go.Panel,
        { width: 108, height: 42 },
        objGo(
          go.Picture,
          { width: 108, height: 42 },
          new go.Binding('source', 'NodeType', v => {
            switch (v) {
              case '20':
                return require('../../../../../assets/images/workFlow/gateWayicon1.svg');
              case '21':
                return require('../../../../../assets/images/workFlow/gateWayicon3.svg');
              case '22':
                return require('../../../../../assets/images/workFlow/gateWayicon2.svg');
              default:
                return null;
            }
          }),
        ),
      ),
    );
    myPaletteSubprocess = objGo(go.Palette, 'myPaletteSubprocess', {
      // 代替默认动画,使用自定义淡入淡出
      'animationManager.initialAnimationStyle': go.AnimationManager.None,
      InitialAnimationStarting: animateFadeDown, // 相反,使用此功能制作动画
      // nodeTemplateMap: diagram.nodeTemplateMap, // 分享 myDiagram 使用的模板
      scale: '1',
      nodeSelectionAdornmentTemplate: objGo(
        go.Adornment,
        'Auto',
        objGo(go.Shape, 'Rectangle', { fill: 'white', stroke: null }),
      ), // 去掉节点点击时的边框颜色
      model: new go.GraphLinksModel([
        // 指定调色板的内容
        {
          category: 'gatewayCondition',
          NodeName: '子流程',
          NodeType: '30',
          SerialNo: 0,
          ...defaultField,
        },
      ]),
    });
    myPaletteSubprocess.nodeTemplate = objGo(
      go.Node,
      'Auto',
      new go.Binding('location', 'points', go.Point.parse).makeTwoWay(go.Point.stringify),
      // 节点样式配置
      objGo(
        go.Panel,
        { width: 108, height: 42 },
        objGo(
          go.Picture,
          { width: 108, height: 42 },
          new go.Binding('source', 'NodeType', v => {
            switch (v) {
              case '30':
                return require('../../../../../assets/images/workFlow/subprocessicon.svg');

              default:
                return null;
            }
          }),
        ),
      ),
    );
  };
  // 流程图初始化
  const init = () => {
    diagram = objGo(go.Diagram, 'myDiagramDiv', {
      'undoManager.isEnabled': true,
      allowDragOut: false,
      'dragSelectingTool.isEnabled': false, // 禁止多选
      // 'grid.visible': true,
      scrollMode: go.Diagram.InfiniteScroll, // 无限滚动
      allowCopy: true, // 禁止复制
      allowDrop: true,
      // nodeSelectionAdornmentTemplate: objGo(
      //   go.Adornment,
      //   'Auto',
      //   objGo(go.Shape, 'Rectangle', { fill: 'white', stroke: null }),
      // ), // 去掉节点点击时的边框颜色
      scale: '0.8',
    });
    diagram.grid.gridCellSize = new go.Size(10, 10);
    diagram.toolManager.draggingTool.isGridSnapEnabled = true;

    // 节点配置
    diagram.nodeTemplate = objGo(
      go.Node,
      'Auto',
      new go.Binding('location', 'points', go.Point.parse).makeTwoWay(go.Point.stringify),
      // 节点样式配置
      objGo(
        go.Panel,
        nodeBoxStyle('width'),
        nodeBoxStyle('height'),
        objGo(
          go.Picture,
          new go.Binding('source', 'NodeType', v => {
            switch (v) {
              case '1':
                return nodeStart;
              case '2':
                return nodeEnd;
              case '0':
                return nodeGeneral;
              // case '4':
              //   return cc;
              case '20':
                return gatewayCondition;
              case '21':
                return gatewayJoin;
              case '22':
                return gatewayParallel;
              case '30':
                return require('../../../../../assets/images/workFlow/nodesubprocess.svg');
              default:
                return null;
            }
          }),
          nodeBoxStyle('width'),
          nodeBoxStyle('height'),
        ),
        objGo(
          go.Panel,
          'Horizontal',
          nodeBoxStyle('height'),
          { alignment: go.Spot.Center },
          objGo(
            go.Panel,
            'Vertical', // 节点文案

            nodeBoxStyle('width'),
            objGo(
              go.TextBlock,
              {
                maxSize: new go.Size(120, NaN),
                maxLines: 1,
                alignment: go.Spot.Center,
                margin: new go.Margin(0, 15, 0, 15),
                overflow: go.TextBlock.OverflowEllipsis,
                font: 'normal 12pt Microsoft YaHei',
              },
              new go.Binding('visible', 'NodeType', v => {
                if (v.NodeType === '20' || v.NodeType === '21' || v.NodeType === '22') {
                  return false;
                }
                return true;
              }),
              new go.Binding('text', 'NodeAliasName'),
              nodeBoxStyle('stroke', 'nodeStyle'),
            ),
            objGo(
              go.TextBlock,

              {
                alignment: go.Spot.Center,
                maxLines: 2,
                overflow: go.TextBlock.OverflowEllipsis,
                font: 'normal 12pt Microsoft YaHei',
              },
              new go.Binding('spacingAbove', 'roleList', v => (v?.length > 0 ? 5 : 0)),
              new go.Binding('height', 'roleList', v => (v?.length > 0 ? 30 : 0)),
              new go.Binding('margin', 'roleList', v =>
                v?.length > 0 ? new go.Margin(10, 10, 0, 10) : 0,
              ),
              new go.Binding('text', 'nodeDetail', v => {
                const obj = JSON.parse(v);

                if (obj.NodeType === '20' || obj.NodeType === '21' || obj.NodeType === '22') {
                  return '';
                }
                if (obj.roleList?.length === 0) {
                  return '';
                }
                return obj.roleList.map(item => item.roleName).join(',');
              }),
              nodeBoxStyle('stroke', 'roleStyle'),
            ),
          ),
        ),
      ),

      // 我们的小命名端口,每侧一个:
      makePort('T', go.Spot.Top),
      makePort('L', go.Spot.Left),
      makePort('R', go.Spot.Right),
      makePort('B', go.Spot.Bottom),
      {
        // 节点之间线得连接
        linkValidation(fromnode, fromport, tonode, toport, thisLink) {
          // 并行网关不让连接汇合网关
          if (fromnode.data.NodeType === '22' && tonode.data.NodeType === '21') {
            return false;
          }
          // 条件网关不让连接条件网关
          if (fromnode.data.NodeType === '20' && tonode.data.NodeType === '20') {
            return false;
          }
          // 汇合网关不让连条件网关
          if (fromnode.data.NodeType === '21' && tonode.data.NodeType === '20') {
            return false;
          }
          return true;
        },
        // 处理鼠标进入/离开事件以显示/隐藏端口
        mouseEnter(e, node) {
          showSmallPorts(node, true);
        },
        mouseLeave(e, node) {
          showSmallPorts(node, false);
        },
        click(e, node) {
          handlerDC(e, node);
        },
        // 处理双击
        doubleClick(e, node) {
          // 双击事件
          // handlerDC(e, node); // 双击执行的方法
        },
        selectionChanged: node => {
          // console.log(node.data, 'nodenodenode');
        },
        toolTip: objGo(
          'ToolTip',
          objGo(
            go.TextBlock,
            { margin: 4 },
            new go.Binding('text', 'nodeDetail', v => {
              const obj = JSON.parse(v);
              return `节点名称:${obj.NodeName}\n${
                obj.roleList.length > 0 ? '承办:' : ''
              }${obj.roleList.map(item => item.roleName).join(',')}`;
            }),
          ),
        ),
      },
    );
    // 链接设置
    diagram.linkTemplate = objGo(
      go.Link,
      {
        routing: go.Link.Orthogonal,
        curve: go.Link.JumpOver,
        corner: 5,
        toShortLength: 4,
        selectionAdornmentTemplate: objGo(
          go.Adornment,
          objGo(go.Shape, { isPanelMain: true, stroke: '#faad14', strokeWidth: 2 }), // 修改线颜色和大小
          objGo(go.Shape, { toArrow: 'Standard', fill: '#faad14', stroke: '#faad14' }), // 修改线箭头的颜色和大小
        ),
      },
      new go.Binding('points').makeTwoWay(),
      objGo(
        go.Shape, // 链接路径形状
        {
          isPanelMain: true,
          strokeWidth: 2,
        },

        new go.Binding('stroke', 'from', v => lineStyle(v, 'stroke')),
        new go.Binding('strokeDashArray', 'from', v => lineStyle(v, 'strokeDashArray')),
      ),
      objGo(
        go.Shape, // 箭头
        { toArrow: 'Standard' },
        new go.Binding('stroke', 'from', v => lineStyle(v, 'stroke')),
        new go.Binding('fill', 'from', v => lineStyle(v, 'stroke')),
      ),
      objGo(
        go.Panel,
        'Auto',
        objGo(
          go.Shape, // 标签背景,在边缘变得透明
          // { fill: 'transparent' },
          new go.Binding('fill', 'lineDetail', v => lineTextStyle(v)),
          new go.Binding('stroke', 'lineDetail', v => lineTextStyle(v)),
        ),
        objGo(
          go.TextBlock,
          {
            textAlign: 'center',
            font: '10pt helvetica, arial, Microsoft YaHei',
            stroke: '#555555',
            margin: 4,
          },
          new go.Binding('text', 'lineDetail', v => lineText(v)),
        ),
      ),

      // {
      //   // 处理双击
      //   doubleClick(e, node) {
      //     addLineMsg(e, node);
      //   },
      // },
    );
    // 初始化流程的节点数组
    diagram.model = objGo(go.GraphLinksModel, {
      linkFromPortIdProperty: 'fromPort', // 所需信息:
      linkToPortIdProperty: 'toPort', // 标识数据属性名称
      nodeDataArray: currentFlowData.Nodes,
      linkDataArray: currentFlowData.Lines,
    });
  };

  // 线的样式
  const lineStyle = (v, styleName) => {
    const linemsg = diagram.model.findNodeDataForKey(v);
    switch (styleName) {
      case 'strokeDashArray':
        if (linemsg.NodeType === '20') {
          return [6, 3];
        }
        return null;
      case 'stroke':
        return '#1685FF';
      default:
        return null;
    }
  };
  // 线上文案样式
  const lineTextStyle = v => {
    let obj = JSON.parse(v);

    let nodeData = diagram.model.findNodeDataForKey(obj.from);
    if (nodeData.NodeType === '20' || nodeData.NodeType === '21') {
      // if(nodeData.)
      if (nodeData.RuleList.some(ele => ele.NextNodeId === obj.to)) {
        return '#EFF8FA';
      }
      return 'transparent';
    }
    return 'transparent';
  };
  // 线上的文案
  const lineText = v => {
    let obj = JSON.parse(v);
    let nodeData = diagram.model.findNodeDataForKey(obj.from);
    if (nodeData.NodeType === '20' || nodeData.NodeType === '21') {
      return nodeData.RuleList.find(ele => ele.NextNodeId === obj.to).RuleName;
    }
    return '';
  };
  // 是否显示端口
  const showSmallPorts = (node, show) => {
    node.ports.each(port => {
      if (port.portId !== '') {
        // 不要更改默认端口,这是大形状
        port.fill = show ? 'rgba(5,135,224,.3)' : null;
      }
    });
  };
  // 创建节点端口
  const makePort = (name, spot) =>
    // 端口基本上只是一个小的透明 方块
    objGo(
      go.Shape,
      'Circle',
      {
        fill: null, // 默认情况下不可见; 由 showSmallPorts 设置为半透明灰色,定义如下
        stroke: null,
        desiredSize: new go.Size(8, 8),
        alignment: spot, // 对齐主要形状上的端口
        alignmentFocus: spot, // 就在形状里面
        portId: name, // 将此对象声明为“端口”
        fromSpot: spot,
        toSpot: spot, // 声明链接可以在此端口连接的位置
        cursor: 'pointer', // 显示不同的光标以指示潜在的链接点
      },
      new go.Binding('fromLinkable', 'NodeType', v => v !== '2'), // 是否允许用户绘制的链接到这里
      new go.Binding('toLinkable', 'NodeType', v => v !== '1'), // 声明用户是否可以从这里绘制链接
    );
  //  节点盒子样式
  const nodeBoxStyle = (atr, classname) => {
    switch (atr) {
      case 'width':
        return new go.Binding('width', 'NodeType', v => {
          switch (v) {
            case '1':
              return 140;
            case '2':
              return 140;
            case '0':
              return 220;
            case '4':
              return 220;
            case '20':
              return 60;
            case '21':
              return 60;
            case '22':
              return 60;
            case '30':
              return 220;
            default:
              return null;
          }
        });
      case 'height':
        return new go.Binding('height', 'NodeType', v => {
          switch (v) {
            case '1':
              return 140;
            case '2':
              return 140;
            case '0':
              return 120;
            case '4':
              return 120;
            case '20':
              return 60;
            case '21':
              return 60;
            case '22':
              return 60;
            case '30':
              return 120;
            default:
              return null;
          }
        });
      case 'stroke':
        return new go.Binding('stroke', 'NodeType', v => {
          switch (v) {
            case '1':
              return classname === 'roleStyle' ? '#BCBCBC' : '#1685FF';
            case '2':
              return classname === 'roleStyle' ? '#BCBCBC' : '#51C21A';
            case '0':
              return classname === 'roleStyle' ? '#BCBCBC' : '#1685FF';
            case '30':
              return classname === 'roleStyle' ? '#BCBCBC' : '#9850F6';
            default:
              return null;
          }
        });
      default:
        return null;
    }
  };
  const findAfterNode = startNode => {
    // let nodeList = new Map([]);
    startNode.findNodesOutOf().each(node => {
      if (!afterNodes.current.has(node.data.NodeName)) {
        if (['1', '0', '2'].includes(node.data.NodeType)) {
          afterNodes.current.set(node.data.NodeName, node.data.TableName);
        }
        findAfterNode(node);
      }
    });
  };
  // 双击节点
  const handlerDC = (e, node) => {
    currentNode.current = node.data;

    // 找到节点后得除去网关跟子流程的所有节点
    afterNodes.current = new Map([]);
    findAfterNode(node);
    console.log(Object.fromEntries(afterNodes.current));
    setModalType('edit');
    setVisible(true);
    setNodeKey(node.part.data.key);
    setEditMsg(node.part.data);
  };
  // 双击线
  const addLineMsg = (e, node) => {
    setLineKey(node.part.data.LineKey);
    setLineMsg(node.part.data);
    setLineVisible(true);
  };

  const copyNode = e => {
    // diagram.commandHandler.canSelectAll();
    console.log(
      diagram.makeImageData({
        background: 'rgb(239, 248, 250)',
        maxSize: new go.Size(1260, 500),
      }),
      'fasdfsad',
    );
  };
  const nodeCallBack = () => {
990 991
    compress(
      diagram.makeImageData({
邓超's avatar
邓超 committed
992
        background: 'rgb(239, 248, 250)',
993 994
        // maxSize: new go.Size(1260, 500), // 固定区域
        scale: 1, // 有效区域
邓超's avatar
邓超 committed
995
      }),
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033
      1.2, // 压缩比例
      base64 => {
        console.log(base64);
        SaveWorkFlowImage({
          flowName: flowData.flowName,
          base64Data: base64,
        }).then(response => {
          if (response.code === 0) {
            FlowNodeSave({
              PreviewImage: response.data,
              CreateUser: sessionStorage.getItem('userName'),
              flowID,
              ...currentNode.current,
              CarbonCopyPeopleList: currentNode.current.CarbonCopyPeopleList.map(item =>
                Number(item.value),
              ),
            }).then(res => {
              if (res.code === 0) {
                diagram.model.setDataProperty(
                  currentNode.current,
                  'FlowTimerList',
                  res.data.FlowTimerList,
                );
                diagram.model.setDataProperty(
                  currentNode.current,
                  'ActivityId',
                  res.data.ActivityId,
                );
                diagram.model.setDataProperty(
                  currentNode.current,
                  'FlowNodeExtendId',
                  res.data.FlowNodeExtendId,
                );
                message.success('保存成功');
              } else {
                message.error(res.msg);
              }
            });
邓超's avatar
邓超 committed
1034 1035
          }
        });
1036 1037
      },
    );
邓超's avatar
邓超 committed
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
  };
  // 关闭时进行数据比对看数据是否改变
  const leaveTip = () => {
    let diagramObj = JSON.parse(diagram.model.toJson());
    let stageJson = {
      Nodes: diagramObj.nodeDataArray,
      Lines: diagramObj.linkDataArray,
    };
    if (JSON.stringify(stageJson.Nodes) === JSON.stringify(initFlowData.Nodes)) {
      setShowLeaveTip(false);
      // leaveCallBack(false);
    } else {
      // leaveCallBack(true);
      setShowLeaveTip(true);
    }
  };
  // 线配置回调函数
  const lineCallBack = obj => {
    let node = diagram.model.findLinkDataForKey(LineKey);
    node.text = obj.text;
    diagram.model.updateTargetBindings(node);

    // 关闭时进行数据比对看数据是否改变
    leaveTip();
    setLineVisible(false);
  };
  // 获取保存后的流程数据
  const getFlowData = () => {
    GetFlowNode({ flowID }).then(res => {
      if (res.code === 0) {
        // 保存后离开不用提醒要修改数据了
        setShowLeaveTip(false);
        // leaveCallBack(false);

        setCurrentFlowData(JSON.parse(JSON.stringify(res.data)));
      } else {
邓超's avatar
邓超 committed
1074
        message.error(res.msg);
邓超's avatar
邓超 committed
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
      }
    });
  };
  const isRepeat = (arr, key) => {
    let obj = {};
    for (let i = 0; i < arr.length; i++) {
      if (obj[arr[i][key]]) {
        return false;
      }
      obj[arr[i][key]] = arr[i];
    }
    return obj;
  };
  // 节点数据改边
  const nodeChage = (key, value) => {
    console.log(key, value);
    setShowLeaveTip(true);
    let obj = JSON.parse(JSON.stringify(currentNode.current));
    obj[key] = value;
    const nodeDetail = JSON.stringify(obj);

    diagram.model.setDataProperty(currentNode.current, key, value);
    if (key === 'roleList') {
      diagram.model.setDataProperty(currentNode.current, 'nodeDetail', nodeDetail);
    }
    if (key === 'FlowTimerList') {
      const list = value.map(item => item.EndNode);
      limitFinshNodes.current = new Set(list);
      setFlag(flag + 1);
      // limitFinshNodes;
    }
    if (key === 'TableName') {
      setFlag(flag + 1);
    }

    diagram.rebuildParts();
    // leaveCallBack(true);
  };
  // 保存流程
  const saveFlow = () => {
    let diagramObj = JSON.parse(diagram.model.toJson());
    // let list = isRepeat(diagramObj.nodeDataArray, 'SerialNo');

    // if (!list) {
    //   notification.error({
    //     message: '提示',
    //     duration: 3,
    //     description: '请检查序号是否重复',
    //   });
    //   return;
    // }
    let list = new Set([]);
1127
    let errorList = new Set();
邓超's avatar
邓超 committed
1128
    diagramObj.nodeDataArray.forEach(item => {
1129 1130 1131 1132 1133
      if (item.NodeType === '1' || item.NodeType === '0' || item.NodeType === '1') {
        if (!item.TableName || !item.Fields) {
          errorList.add(item.NodeName);
        }
      }
邓超's avatar
邓超 committed
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
      if ((item.NodeType === '20' || item.NodeType === '21') && item.RuleList) {
        item.RuleList.forEach(ele => {
          if (!ele.RuleName) {
            list.add(item.NodeName);

            return;
          }
          if (!ele.NextNodeId && ele.NextNodeId !== 0) {
            list.add(item.NodeName);

            return;
          }
          if (!ele.RuleContent) {
            list.add(item.NodeName);
          }
        });
      }
      const newListLength = new Set(item.RuleList.map(ele => ele.NextNodeId)).size;
      if (item.RuleList.length > newListLength) {
        list.add(item.NodeName);
        return;
      }
      item.CarbonCopyPeopleList = item.CarbonCopyPeopleList.map(ele => Number(ele.value));
    });
1158 1159 1160 1161 1162 1163
    if ([...errorList].length > 0) {
      errorList.forEach(item => {
        message.error(`请检查${item}节点存在未配置项`);
      });
      return;
    }
邓超's avatar
邓超 committed
1164 1165 1166 1167 1168 1169 1170
    if ([...list].length > 0) {
      list.forEach(item => {
        message.error(`请检查${item}规则配置`);
      });
      return;
    }
    setButtonLoading(true);
1171 1172
    compress(
      diagram.makeImageData({
邓超's avatar
邓超 committed
1173
        background: 'rgb(239, 248, 250)',
1174 1175
        // maxSize: new go.Size(1260, 500), // 固定区域
        scale: 1, // 有效区域
邓超's avatar
邓超 committed
1176
      }),
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
      1.2, // 压缩比例
      base64 => {
        console.log(base64);
        SaveWorkFlowImage({
          flowName: flowData.flowName,
          base64Data: base64,
        }).then(val => {
          if (val.code === 0) {
            SaveNodeChange({
              FlowId: flowID,
              // DeleteNodes,
              CreateUser: sessionStorage.getItem('userName'),
              PreviewImage: val.data,
              DeleteLines,
              Lines: diagramObj.linkDataArray,
              Nodes: diagramObj.nodeDataArray,
            })
              .then(res => {
                setButtonLoading(false);
                if (res.code === 0) {
                  setDeleteNodes([]);
                  setDeleteLines([]);
                  setAddNodes([]);
                  setDeleteNode('');
                  setDeleteLine('');
                  getFlowData();
                  message.success('保存成功');
                } else {
                  message.error(res.msg);
                }
              })
              .catch(() => {
                setButtonLoading(false);
                message.error('网络异常请稍后重试');
              });
          }
        });
      },
    );
邓超's avatar
邓超 committed
1216
  };
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
  const treeChange = newValue => {
    setSelectValue(newValue);
  };
  const mapAppTree = org => {
    const haveChildren = Array.isArray(org.children) && org.children.length > 0;
    let value;
    let text;
    if (org.name) {
      value = org.name;
      text = org.name;
    }
    if (org.Code) {
      value = org.Code;
      text = org.FlowName;
    }
邓超's avatar
邓超 committed
1232

1233 1234 1235 1236 1237 1238
    return (
      <TreeNode value={value} title={text} key={value} disabled={org.name}>
        {haveChildren ? org.children.map(item => mapAppTree(item)) : null}
      </TreeNode>
    );
  };
邓超's avatar
邓超 committed
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
  return (
    <>
      <Prompt message="编辑的内容还未保存,确定要离开该页面吗?" when={showLeaveTip} />
      <div className={styles.control}>
        <div className={styles.nodeList}>
          <div id="myPaletteNode" className={styles.myPaletteDiv} />
          {/* <div className={styles.lineBox} /> */}
          <div id="myPaletteGateway" className={styles.myPaletteDiv} />
          <div id="myPaletteSubprocess" className={styles.myPaletteSubprocess} />
        </div>
        <div className={styles.buttonList}>
          {/* <Button
            type="link"
            onClick={() => {
              window.open(
                'https://www.yuque.com/docs/share/da224db9-b8d1-49d2-838f-a23fcd15f0da?#%20%E3%80%8A%E6%B5%81%E7%A8%8B%E8%AE%BE%E8%AE%A1%E3%80%8B',
              );
            }}
          >
            说明文档
          </Button> */}
          {/* <Button type="link" onClick={() => copyNode()}>
            复制
          </Button> */}
1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
          {/* <Button type="link" onClick={() => copyNode()}>
            <TreeSelect
              value={selectValue}
              showSearch
              style={{ width: '200px' }}
              treeNodeFilterProp="title"
              dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
              placeholder="请选择流程"
              treeDefaultExpandAll
              onChange={treeChange}
              treeIcon
            >
              {flowTree ? (
                flowTree.map(item => mapAppTree(item))
              ) : (
                <Empty image={Empty.PRESENTED_IMAGE_SIMPLE} />
              )}
            </TreeSelect>
          </Button> */}
邓超's avatar
邓超 committed
1282 1283 1284 1285 1286 1287
          <Button
            onClick={() =>
              history.push({
                pathname: '/biz/workflow/center',
                state: {
                  activeKey,
邓超's avatar
邓超 committed
1288
                  scrollTop,
邓超's avatar
邓超 committed
1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335
                },
              })
            }
          >
            返回
          </Button>
          <Button type="primary" onClick={() => saveFlow()} loading={buttonLoading}>
            发布
          </Button>
        </div>
      </div>
      <div className={styles.chartBox}>
        <div id="myOverviewDiv" className={styles.myOverviewDiv} />
        <div className={styles.flowName}>{flowData.flowName}</div>
        <Spin spinning={chartLoading}>
          <div
            id="myDiagramDiv"
            className={styles.myDiagramDiv}
            style={{ backgroundColor: '#EFF8FA' }}
          />
        </Spin>
        <NodeModal
          flowID={flowID}
          visible={visible}
          editMsg={editMsg}
          modalType={modalType}
          nodeChage={nodeChage}
          currentNode={currentNode.current}
          limitFinshNodes={[...limitFinshNodes.current]}
          afterNodes={Object.fromEntries(afterNodes.current)}
          handleCancel={() => setVisible(false)}
          onSubumit={obj => nodeCallBack(obj)}
          flowData={diagram ? JSON.parse(diagram.model.toJson()) : {}}
        />
      </div>

      <LineModal
        visible={lineVisible}
        lineMsg={lineMsg}
        handleCancel={() => setLineVisible(false)}
        onSubumit={obj => lineCallBack(obj)}
      />
    </>
  );
};

export default FlowChart;