当前位置:   article > 正文

LogicFlow 来绘制兼容 BPMN2.0 规范的流程 (React hooks版)_vmuu78.top

vmuu78.top

Ⅰ- 壹 - 功能展示和使用需求

需求描述

使用LogicFlow来绘制兼容 BPMN2.0 规范的流程,使用react hooks 根据官方示例改的

下载图片功能只能在谷歌浏览器中使用(官方不支持其他的)

功能展示

在这里插入图片描述
在这里插入图片描述

目录结构

在这里插入图片描述

Ⅱ - 贰 - 封装代码

img文件

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

index.tsx

import LogicFlow from '@logicflow/core';
import {
  BpmnElement,
  BpmnXmlAdapter,
  Snapshot,
  Control,
  Menu,
  SelectionSelect,
} from '@logicflow/extension';
import './index.css';
import '@logicflow/extension/lib/style/index.css';
import '@logicflow/core/dist/style/index.css';
import { useEffect, useRef, useState } from 'react';
import BpmnPattern from './pattern';
import BpmnIo from './io';
const config = {
  stopScrollGraph: true,
  stopZoomGraph: true,
  metaKeyMultipleSelected: true,
  grid: {
    size: 10,
    type: 'dot',
  },
  keyboard: {
    enabled: true,
  },
  snapline: true,
  width: 1500,
  height: 800,
};

const index = () => {
  const refContainer = useRef<any>();
  const [lfData, setLfData] = useState<any>(null);
  useEffect(() => {
    LogicFlow.use(BpmnElement);
    LogicFlow.use(BpmnXmlAdapter);
    LogicFlow.use(Snapshot);
    LogicFlow.use(Control);
    LogicFlow.use(Menu);
    LogicFlow.use(SelectionSelect);
    // use 必须放上面
    const lf = new LogicFlow({
      container: document.querySelector('#graph') as HTMLElement,
      // container: refContainer.current,
      ...config,
    });

    lf.render();
    setLfData(() => lf);
  }, []);
  useEffect(() => {
    if (!lfData) return;
    // setIState(() => true);
  }, [lfData]);

  return (
    <div className="bpmn-example-container">
      <div id="graph" ref={refContainer} className="viewport"></div>
      {lfData && (
        <>
          <BpmnPattern lf={lfData} />
          <BpmnIo lf={lfData} />
        </>
      )}
    </div>
  );
};
export default index;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70

index.css

.bpmn-example-container {
  position: relative;
  height: 100%;
  overflow: hidden;
}
.pattern {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 111;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 60px;
  padding: 10px 0;
  color: #676768;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  -ms-user-select: none;
  -webkit-user-select: none;
  user-select: node;
}
.pattern-selection {
  width: 36px;
  height: 36px;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAAH6ji2bAAAABGdBTUEAALGPC/xhBQAAAOVJREFUOBGtVMENwzAIjKP++2026ETdpv10iy7WFbqFyyW6GBywLCv5gI+Dw2Bluj1znuSjhb99Gkn6QILDY2imo60p8nsnc9bEo3+QJ+AKHfMdZHnl78wyTnyHZD53Zzx73MRSgYvnqgCUHj6gwdck7Zsp1VOrz0Uz8NbKunzAW+Gu4fYW28bUYutYlzSa7B84Fh7d1kjLwhcSdYAYrdkMQVpsBr5XgDGuXwQfQr0y9zwLda+DUYXLaGKdd2ZTtvbolaO87pdo24hP7ov16N0zArH1ur3iwJpXxm+v7oAJNR4JEP8DoAuSFEkYH7cAAAAASUVORK5CYII=')
    center center no-repeat;
  cursor: pointer;
  opacity: 0.99;
}
.pattern-start {
  width: 36px;
  height: 36px;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAAH6ji2bAAAABGdBTUEAALGPC/xhBQAAAnBJREFUOBGdVL1rU1EcPfdGBddmaZLiEhdx1MHZQXApraCzQ7GKLgoRBxMfcRELuihWKcXFRcEWF8HBf0DdDCKYRZpnl7p0svLe9Zzbd29eQhTbC8nv+9zf130AT63jvooOGS8Vf9Nt5zxba7sXQwODfkWpkbjTQfCGUd9gIp3uuPP8bZ946g56dYQvnBg+b1HB8VIQmMFrazKcKSvFW2dQTxJnJdQ77urmXWOMBCmXM2Rke4S7UAW+/8ywwFoewmBps2tu7mbTdp8VMOkIRAkKfrVawalJTtIliclFbaOBqa0M2xImHeVIfd/nKAfVq/LGnPss5Kh00VEdSzfwnBXPUpmykNss4lUI9C1ga+8PNrBD5YeqRY2Zz8PhjooIbfJXjowvQJBqkmEkVnktWhwu2SM7SMx7Cj0N9IC0oQXRo8xwAGzQms+xrB/nNSUWVveI48ayrFGyC2+E2C+aWrZHXvOuz+CiV6iycWe1Rd1Q6+QUG07nb5SbPrL4426d+9E1axKjY3AoRrlEeSQo2Eu0T6BWAAr6COhTcWjRaYfKG5csnvytvUr/WY4rrPMB53Uo7jZRjXaG6/CFfNMaXEu75nG47X+oepU7PKJvvzGDY1YLSKHJrK7vFUwXKkaxwhCW3u+sDFMVrIju54RYYbFKpALZAo7sB6wcKyyrd+aBMryMT2gPyD6GsQoRFkGHr14TthZni9ck0z+Pnmee460mHXbRAypKNy3nuMdrWgVKj8YVV8E7PSzp1BZ9SJnJAsXdryw/h5ctboUVi4AFiCd+lQaYMw5z3LGTBKjLQOeUF35k89f58Vv/tGh+l+PE/wG0rgfIUbZK5AAAAABJRU5ErkJggg==')
    center center no-repeat;
  cursor: grab;
  opacity: 0.99;
}
.pattern-end {
  width: 36px;
  height: 36px;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAAH6ji2bAAAABGdBTUEAALGPC/xhBQAAA1B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lwrLaCJl66JBocYZnrNlvm2+MBCTmUymPrYZVbjdlr/BxlMjmNmNI3SAAAAAElFTkSuQmCC')
    center center no-repeat;
  cursor: grab;
  opacity: 0.99;
}
.pattern-user {
  width: 36px;
  height: 36px;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAEFVwZaAAAABGdBTUEAALGPC/xhBQAAAqlJREFUOBF9VM9rE0EUfrMJNUKLihGbpLGtaCOIR8VjQMGDePCgCCIiCNqzCAp2MyYUCXhUtF5E0D+g1t48qAd7CCLqQUQKEWkStcEfVGlLdp/fm3aW2QQdyLzf33zz5m2IsAZ9XhDpyaaIZkTS4ASzK41TFao88GuJ3hsr2pAbipHxuSYyKRugagICGANkfFnNh3HeE2N0b3nN2cgnpcictw5veJIzxmDamSlxxQZicq/mflxhbaH8BLRbuRwNtZp0JAhoplVRUdzmCe/vO27wFuuA3S5qXruGdboy5/PRGFsbFGKo/haRtQHIrM83bVeTrOgNhZReWaYGnE4aUQgTJNvijJFF4jQ8BxJE5xfKatZWmZcTQ+BVgh7s8SgPlCkcec4mGTmieTP4xd7PcpIEg1TX6gdeLW8rTVMVLVvb7ctXoH0Cydl2QOPJBG21STE5OsnbweVYzAnD3A7PVILuY0yiiyDwSm2g441r6rMSgp6iK42yqroI2QoXeJVeA+YeZSa47gZdXaZWQKTrG93rukk/l2Al6Kzh5AZEl7dDQy+JjgFahQjRopSxPbrbvK7GRe9ePWBo1wcU7sYrFZtavXALwGw/7Dnc50urrHJuTPSoO2IMV3gUQGNg87IbSOIY9BpiT9HV7FCZ94nPXb3MSnwHn/FFFE1vG6DTby+r31KAkUktB3Qf6ikUPWxW1BkXSPQeMHHiW0+HAd2GelJsZz1OJegCxqzl+CLVHa/IibuHeJ1HAKzhuDR+ymNaRFM+4jU6UWKXorRmbyqkq/D76FffevwdCp+jN3UAN/C9JRVTDuOxC/oh+EdMnqIOrlYteKSfadVRGLJFJPSB/ti/6K8f0CNymg/iH2gO/f0DwE0yjAFO6l8JaR5j0VPwPwfaYHqOqrCI319WzwhwzNW/aQAAAABJRU5ErkJggg==')
    center center no-repeat;
  cursor: grab;
  opacity: 0.99;
}
.pattern-condition {
  width: 36px;
  height: 36px;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAVCAYAAAHeEJUAAAAABGdBTUEAALGPC/xhBQAAAvVJREFUOBGNVEFrE0EU/mY3bQoiFlOkaUJrQUQoWMGePLX24EH0IIoHKQiCV0G8iE1covgLiqA/QTzVm1JPogc9tIJYFaQtlhQxqYjSpunu+L7JvmUTU3AgmTfvffPNN++9WSA1DO182f6xwILzD5btfAoQmwL5KJEwiQyVbSVZ0IgRyV6PTpIJ81E5ZvqfHQR0HUOBHW4L5Et2kQ6Zf7iAOhTFAA8s0pEP7AXO1uAA52SbqGk6h/6J45LaLhO64ByfcUzM39V7ZiAdS2yCePPEIQYvTUHqM/n7dgQNfBKWPjpF4ISk8q3J4nB11qw6X8l+FsF3EhlkEMfrjIer3wJTLwS2aCNcj4DbGxXTw00JmAuO+Ni6bBxVUCvS5d9aa04+so4pHW5jLTywuXAL7jJ+D06sl82Sgl2JuVBQn498zkc2bGKxULHjCnSMadBKYDYYHAtsby1EQ5lNGrQd4Y3v4Zo0XdGEmDno46yCM9Tk+RiJmUYHS/aXHPNTcjxcbTFna000PFJHIVZ5lFRqRpJWk9/+QtlOUYJj9HG5pVFEU7zqIYDVsw2s+AJaD8wTd2umgSCCyUxgGsS1Y6TBwXQQTFuZaHcd8gAGioE90hlsY+wMcs30RduYtxanjMGal8H5dMW67dmT1JFtYUEe8LiQLRsPZ6IIc7A4J5tqco3T0pnv/4u0kyzrYUq7gASuEyI8VXKvB9Odytv6jS/PNaZBln0nioJG/AVQRZvApOdhjj3Jt8QC8Im09SafwdBdvIpztpxWxpeKCC+EsFdS8DCyuCn2munFpL7ctHKp+Xc5cMybeIyMAN33SPL3ZR9QV1XVwLyzHm6Iv0/yeUuUb7PPlZC4D4HZkeu6dpF4v9j9MreGtMbxMMRLIcjJic9yHi7WQ3yVKzZVWUr5UrViJvn1FfUlwe/KYVfYyWRLSGNu16hR01U9IacajXPei0wx/5BqgInvJN+MMNtNme7ReU9SBbgntovn0kKHpFg7UogZvaZiOue/q1SBo9ktHzQAAAAASUVORK5CYII=')
    center center no-repeat;
  cursor: grab;
  opacity: 0.99;
}
.pattern-circle {
  width: 36px;
  height: 36px;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACEAAAAfCAYAAABplKSyAAAKrGlDQ1BJQ0MgUHJvZmlsZQAASImVlgdUE9kax+9MeqMlREBK6L23ANJrAOldVEJCCSXEQFCxI4sruBZUREARdKkKrkoRFRFRbIuiUqwLsiio62JBVFR2gEd4+9557533n3Nzf/nmm2/+c2fuOR8A5AG2QJACSwGQys8QBnm6MCIioxi43wEEyIACJIAkm5MucA4I8AWI5ue/62Mfko3onuFMrX8//18lzY1L5wAABSAcy03npCJ8BhltHIEwAwAUMoD66gzBDBchTBMiBhE+PsMJc9w+w7FzfH82JyTIFeFRAPBkNluYAADpAxJnZHISkDpkGsImfC6Pj7Abwg6cRDYX4RyEDVJT02b4JMI6sf9UJ+FvNWPFNdnsBDHPPcus8G68dEEKe+3/uRz/W6kpovl7qCGDnCj0CkJmOrJm1clpPmLmx/r5zzOPO5s/y4kir9B55qS7Rs0zl+3mM8+i5FDneWYLF67lZbBC5lmYFiSuz0/x8xXXj2OJOS7dPXie43kerHnOSgwJn+dMXpjfPKcnB/ss5LiK40JRkNhzvNBD/Iyp6QveOOyFe2UkhngteIgQ++HGubmL4/xQcb4gw0VcU5ASsOA/xVMcT88MFl+bgXxg85zE9g5YqBMgXh/gBtyBL3IwQAAwQw5TYA0QVxlxa2a+aeCaJlgr5CUkZjCckV0Tx2DxOUYGDDMTMxMAZvbg3Ct+PzC7tyA6fiHGQXyYxSJweyGWlAfAOVkApJgLMV0cADJIvEOTIxJmzsXQMz8YQASSgAbkgTJQBzrAEHFnBeyAE+LYG/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2794QS0HWdHj96OBZKc7Zsb+94JgBx1R+Bt4u/WYUUMVyEu6JfnaxOcvOsxsI6A5cTUgR2AYA1cJG/wBmc6ywEsQHm4n4hAnmAtyEWISZ5DcREbABc4GQIEV/3h3kA2xC7wC8gNjgAJD+G1m63qVwui2fDyE69DTmAmxJbHLkGQPb9fbp9tX1HNsxcz7iJea6xSHYMXgLacfNYtEHl4uIV7vetRLblpHfy60TwaN1uV1RwFgQF5mJuKYIPoyCEMJcUEQTpJA4tHA6LMTiOgwJzMbcUAT8QFJhLiliILwhuHL/wA37Dtn9I8zN/eV7QaSsD98OAIfEbB5UDSQHnBWjRaJTgCQE4ItWiiQ6PbohdrX4X0ZaW0nTp9EATZwdMKQBLBkfkFxCbbd/N1VVJI0TAFfOrgSVjJyRHeVBBTMQGwOV04kIEOuCKAXhCpyUTjRe8sc1jv8lcHFaKgC2HKwZ4khdvRI21uXl37BNAigA5bDlcMaBOFo0ub2oMGF1zbWhsnKHG3DY6Z275WeHMP35YyMw/A1kIypl+EDuFoA5PCEsGRwQvwH4ABxEunEM4BpCF3eAv0kmPwgfSI+wAAAAASUVORK5CYII=')
    center center no-repeat;
  cursor: grab;
  opacity: 0.99;
}

.pattern-rect {
  width: 36px;
  height: 36px;
  background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAcCAYAAAAJKR1YAAAKrGlDQ1BJQ0MgUHJvZmlsZQAASImVlgdUE9kax+9MeqMlREBK6L23ANJrAOldVEJCCSXEQFCxI4sruBZUREARdKkKrkoRFRFRbIuiUqwLsiio62JBVFR2gEd4+9557533n3Nzf/nmm2/+c2fuOR8A5AG2QJACSwGQys8QBnm6MCIioxi43wEEyIACJIAkm5MucA4I8AWI5ue/62Mfko3onuFMrX8//18lzY1L5wAABSAcy03npCJ8BhltHIEwAwAUMoD66gzBDBchTBMiBhE+PsMJc9w+w7FzfH82JyTIFeFRAPBkNluYAADpAxJnZHISkDpkGsImfC6Pj7Abwg6cRDYX4RyEDVJT02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3p6qnl6+lslYvYhAO0f53rzGUkh/f+RfhM3y9DeDaPgX/UXJvQF32DTLzIAAACTSURBVEgN7dfBCcAgEATAM6QWm7EZS7EZm7EWIcGAspB95BO5xwqSzZFwMr4u9N4vc7TOeZZSirXW5uvWZ4zRcs5Pz2Nr5w/NltD8NqVkY+9YtVYbG5c7IR0Ir4dlCTEVrEkINViWEFPBmoRQg2UJMRWsSQg1WJYQU8GahFCDZQkxFay9pg42CeAPf2d3Vxa8jdI3E7sYYZtsfeUAAAAASUVORK5CYII=')
    center center no-repeat;
  cursor: grab;
  opacity: 0.99;
}
.graph-io {
  position: absolute;
  bottom: 10px;
  left: 10px;
  z-index: 9999;
  display: flex;
  padding: 10px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}
.graph-io > span {
  margin: 0 5px;
  cursor: pointer;
}
#upload-xml {
  position: relative;
  display: inline-block;
  overflow: hidden;
  cursor: pointer;
}
.upload {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 99;
  cursor: pointer;
  opacity: 0;
}
.upload::-webkit-file-upload-button {
  cursor: pointer;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112

io.tsx


import React from 'react';
import LogicFlow from '@logicflow/core';
import { Input, Image } from 'antd';

const downloadImg = require('./img/download.png');
const photo = require('./img/img.png');
const uploadImg = require('./img/upload.png');

type IProps = {
  lf: LogicFlow;
};

function download(filename: string, text: string) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}

type FileEventTarget = EventTarget & { files: FileList };

const BpmnIo: any = (props: IProps) => {
  const { lf } = props;
  const downloadXml = () => {
    const data = lf.getGraphData() as string;
    download('logic-flow.xml', data);
  };
  const uploadXml = (ev: React.ChangeEvent<HTMLInputElement>) => {
    const file = (ev.target as FileEventTarget).files[0];
    const reader = new FileReader();
    reader.onload = (event: ProgressEvent<FileReader>) => {
      if (event.target) {
        const xml = event.target.result as string;
        lf.render(xml);
      }
    };
    reader.readAsText(file); // you could also read images and other binaries
  };

  const downloadImage = async () => {
    const { lf } = props;
    lf.getSnapshot('', '#fff');
    // lf.extension.snapshot.getSnapshot();
  };
  return (
    <div className="graph-io">
      <span title="下载 XML" onMouseDown={() => downloadXml()}>
        <Image preview={false} width={'10'} height={'10'} src={downloadImg} alt="下载XML" />
      </span>
      <span id="download-img" title="下载图片" onMouseDown={() => downloadImage()}>
        <Image preview={false} width={'10'} height={'10'} src={photo} alt="下载图片" />
      </span>
      <span id="upload-xml" title="上传 XML">
        <Input type="file" className="upload" onChange={(ev) => uploadXml(ev)} />
        <Image preview={false} width={'10'} height={'10'} src={uploadImg} alt="上传XML" />
      </span>
    </div>
  );
};

export default BpmnIo;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69

pattern.tsx

import React, { useEffect } from 'react';
import LogicFlow from '@logicflow/core';

type IProps = {
  lf: LogicFlow;
};

const BpmnPattern = (props: IProps) => {
  const { lf } = props;
  useEffect(() => {
    lf &&
      lf.on('selection:selected', () => {
        lf.updateEditConfig({
          stopMoveGraph: false,
        });
      });
  }, [lf]);
  const addStartNode = () => {
    lf.dnd.startDrag({
      type: 'bpmn:startEvent',
      text: '开始',
    });
  };
  const addUserTask = () => {
    lf.dnd.startDrag({
      type: 'bpmn:userTask',
    });
  };
  const addServiceTask = () => {
    lf.dnd.startDrag({
      type: 'bpmn:serviceTask',
    });
  };
  const addGateWay = () => {
    lf.dnd.startDrag({
      type: 'bpmn:exclusiveGateway',
    });
  };
  const addEndNode = () => {
    lf.dnd.startDrag({
      type: 'bpmn:endEvent',
      text: '结束',
    });
  };
  const openSelection = () => {
    lf.updateEditConfig({
      stopMoveGraph: true,
    });
  };

  const onMouseDownFun = (type: any) => {
    switch (type) {
      case 'openSelection':
        lf.updateEditConfig({
          stopMoveGraph: true,
        });
        break;
      case 'addStartNode':
        lf.dnd.startDrag({
          type: 'bpmn:startEvent',
          text: '开始',
        });
        break;
      case 'addUserTask':
        lf.dnd.startDrag({
          type: 'bpmn:userTask',
        });
        break;
      case 'addServiceTask':
        lf.dnd.startDrag({
          type: 'bpmn:serviceTask',
        });
        break;
      case 'addGateWay':
        lf.dnd.startDrag({
          type: 'bpmn:exclusiveGateway',
        });
        break;
      case 'addEndNode':
        lf.dnd.startDrag({
          type: 'bpmn:endEvent',
          text: '结束',
        });
        break;
      case 'circle':
        lf.dnd.startDrag({
          type: 'circle',
          text: '圆形',
        });
        break;
      case 'rect':
        lf.dnd.startDrag({
          type: 'rect',
          text: '矩形',
        });
        break;

      default:
        break;
    }
  };

  return (
    <div className="pattern">
      <div className="pattern-selection" onMouseDown={() => onMouseDownFun('openSelection')} />
      <div>选区</div>
      <div className="pattern-start" onMouseDown={() => onMouseDownFun('addStartNode')} />
      <div>开始</div>
      <div className="pattern-user" onMouseDown={() => onMouseDownFun('addUserTask')}></div>
      <div>用户任务</div>
      <div className="pattern-user" onMouseDown={() => onMouseDownFun('addServiceTask')}></div>
      <div>系统任务</div>
      <div className="pattern-circle" onMouseDown={() => onMouseDownFun('circle')}></div>
      <div>圆形</div>
      <div className="pattern-rect" onMouseDown={() => onMouseDownFun('rect')}></div>
      <div>矩形</div>
      <div className="pattern-condition" onMouseDown={() => onMouseDownFun('addGateWay')}></div>
      <div>条件判断</div>
      <div className="pattern-end" onMouseDown={() => onMouseDownFun('addEndNode')}></div>
      <div>结束</div>
    </div>
  );
};

export default BpmnPattern;

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126

Ⅲ - 叁 - 使用

import Bpmn from './components/bpmn/index';
const Demo = () => {
  return <Bpmn></Bpmn>;
};

export default Demo;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/529165
推荐阅读
相关标签
  

闽ICP备14008679号