位置:首页 > web前端 > vue

Vue如何实现流程引擎ui绘制 vue结合bpmn实现工作流拖拽功能

dearweb 发布:2023-05-26 08:58:28阅读:

计划前端使用vue+bpmn.js,后端使用springboot+activi7实现。这个想法很好,网上案例也挺多,发现配置起来很麻烦,网上的很多案例都是报错的。

bpmn.js是国外的程序员开发的,默认都是英文的,汉化的教程也非常多,后面的代码里,也会把汉化加进去。我这里使用的版本是9.0.3。

前期的准备工作

依赖安装

npm install bpmn-js --save

汉化准备

汉化的话,需要在新建的Vue项目中,新建两个Js文件

translations.js

export default {
    // hong
    // Labels
    'Activate the global connect tool' : '激活全局连接工具',
    'Append {type}': '追加 {type}',
    'Append EndEvent': '追加 结束事件 ',
    'Append Task':'追加 任务',
    'Append Gateway':'追加 网关',
    'Append Intermediate/Boundary Event':'追加 中间/边界 事件',
    'Add Lane above': '在上面添加道',
    'Divide into two Lanes': '分割成两个道',
    'Divide into three Lanes': '分割成三个道',
    'Add Lane below': '在下面添加道',
    'Append compensation activity': '追加补偿活动',
    'Change type': '修改类型',
    'Connect using Association': '使用关联连接',
    'Connect using Sequence/MessageFlow or Association': '使用顺序/消息流或者关联连接',
    'Connect using DataInputAssociation': '使用数据输入关联连接',
    'Remove': '移除',
    'Activate the hand tool': '激活抓手工具',
    'Activate the lasso tool': '激活套索工具',
    'Activate the create/remove space tool': '激活创建/删除空间工具',
    'Create expanded SubProcess': '创建扩展子过程',
    'Create IntermediateThrowEvent/BoundaryEvent' : '创建中间抛出事件/边界事件',
    'Create Pool/Participant': '创建池/参与者',
    'Parallel Multi Instance': '并行多重事件',
    'Sequential Multi Instance': '时序多重事件',
    'DataObjectReference':'数据对象参考',
    'DataStoreReference':'数据存储参考',
    'Loop': '循环',
    'Ad-hoc': '即席',
    'Create {type}': '创建 {type}',
    'Create Task':'创建任务',
    'Create StartEvent':'创建开始事件',
    'Create EndEvent':'创建结束事件',
    'Create Group':'创建组',
    'Task': '任务',
    'Send Task': '发送任务',
    'Receive Task': '接收任务',
    'User Task': '用户任务',
    'Manual Task': '手工任务',
    'Business Rule Task': '业务规则任务',
    'Service Task': '服务任务',
    'Script Task': '脚本任务',
    'Call Activity': '调用活动',
    'Sub Process (collapsed)': '子流程(折叠的)',
    'Sub Process (expanded)': '子流程(展开的)',
    'Start Event': '开始事件',
    'StartEvent': '开始事件',
    'Intermediate Throw Event': '中间事件',
    'End Event': '结束事件',
    'EndEvent': '结束事件',
    'Create Gateway': '创建网关',
    'GateWay':'网关',
    'Create Intermediate/Boundary Event': '创建中间/边界事件',
    'Message Start Event': '消息开始事件',
    'Timer Start Event': '定时开始事件',
    'Conditional Start Event': '条件开始事件',
    'Signal Start Event': '信号开始事件',
    'Error Start Event': '错误开始事件',
    'Escalation Start Event': '升级开始事件',
    'Compensation Start Event': '补偿开始事件',
    'Message Start Event (non-interrupting)': '消息开始事件(非中断)',
    'Timer Start Event (non-interrupting)': '定时开始事件(非中断)',
    'Conditional Start Event (non-interrupting)': '条件开始事件(非中断)',
    'Signal Start Event (non-interrupting)': '信号开始事件(非中断)',
    'Escalation Start Event (non-interrupting)': '升级开始事件(非中断)',
    'Message Intermediate Catch Event': '消息中间捕获事件',
    'Message Intermediate Throw Event': '消息中间抛出事件',
    'Timer Intermediate Catch Event': '定时中间捕获事件',
    'Escalation Intermediate Throw Event': '升级中间抛出事件',
    'Conditional Intermediate Catch Event': '条件中间捕获事件',
    'Link Intermediate Catch Event': '链接中间捕获事件',
    'Link Intermediate Throw Event': '链接中间抛出事件',
    'Compensation Intermediate Throw Event': '补偿中间抛出事件',
    'Signal Intermediate Catch Event': '信号中间捕获事件',
    'Signal Intermediate Throw Event': '信号中间抛出事件',
    'Message End Event': '消息结束事件',
    'Escalation End Event': '定时结束事件',
    'Error End Event': '错误结束事件',
    'Cancel End Event': '取消结束事件',
    'Compensation End Event': '补偿结束事件',
    'Signal End Event': '信号结束事件',
    'Terminate End Event': '终止结束事件',
    'Message Boundary Event': '消息边界事件',
    'Message Boundary Event (non-interrupting)': '消息边界事件(非中断)',
    'Timer Boundary Event': '定时边界事件',
    'Timer Boundary Event (non-interrupting)': '定时边界事件(非中断)',
    'Escalation Boundary Event': '升级边界事件',
    'Escalation Boundary Event (non-interrupting)': '升级边界事件(非中断)',
    'Conditional Boundary Event': '条件边界事件',
    'Conditional Boundary Event (non-interrupting)': '条件边界事件(非中断)',
    'Error Boundary Event': '错误边界事件',
    'Cancel Boundary Event': '取消边界事件',
    'Signal Boundary Event': '信号边界事件',
    'Signal Boundary Event (non-interrupting)': '信号边界事件(非中断)',
    'Compensation Boundary Event': '补偿边界事件',
    'Exclusive Gateway': '互斥网关',
    'Parallel Gateway': '并行网关',
    'Inclusive Gateway': '相容网关',
    'Complex Gateway': '复杂网关',
    'Event based Gateway': '事件网关',
    'Transaction': '转运',
    'Sub Process': '子流程',
    'Event Sub Process': '事件子流程',
    'Collapsed Pool': '折叠池',
    'Expanded Pool': '展开池',
    // Errors
    'no parent for {element} in {parent}': '在{parent}里,{element}没有父类',
    'no shape type specified': '没有指定的形状类型',
    'flow elements must be children of pools/participants': '流元素必须是池/参与者的子类',
    'out of bounds release': 'out of bounds release',
    'more than {count} child lanes': '子道大于{count} ',
    'element required': '元素不能为空',
    'diagram not part of bpmn:Definitions': '流程图不符合bpmn规范',
    'no diagram to display': '没有可展示的流程图',
    'no process or collaboration to display': '没有可展示的流程/协作',
    'element {element} referenced by {referenced}#{property} not yet drawn': '由{referenced}#{property}引用的{element}元素仍未绘制',
    'already rendered {element}': '{element} 已被渲染',
    'failed to import {element}': '导入{element}失败',
    //属性面板的参数
    'Id':'编号',
    'Name':'名称',
    'General':'常规',
    'Details':'详情',
    'Message Name':'消息名称',
    'Message':'消息',
    'Initiator':'创建者',
    'Asynchronous Continuations':'持续异步',
    'Asynchronous Before':'异步前',
    'Asynchronous After':'异步后',
    'Job Configuration':'工作配置',
    'Exclusive':'排除',
    'Job Priority':'工作优先级',
    'Retry Time Cycle':'重试时间周期',
    'Documentation':'文档',
    'Element Documentation':'元素文档',
    'History Configuration':'历史配置',
    'History Time To Live':'历史的生存时间',
    'Forms':'表单',
    'Form Key':'表单key',
    'Form Fields':'表单字段',
    'Business Key':'业务key',
    'Form Field':'表单字段',
    'ID':'编号',
    'Type':'类型',
    'Label':'名称',
    'Default Value':'默认值',
    'Validation':'校验',
    'Add Constraint':'添加约束',
    'Config':'配置',
    'Properties':'属性',
    'Add Property':'添加属性',
    'Value':'值',
    'Add':'添加',
    'Values':'值',
    'Add Value':'添加值',
    'Listeners':'监听器',
    'Execution Listener':'执行监听',
    'Event Type':'事件类型',
    'Listener Type':'监听器类型',
    'Java Class':'Java类',
    'Expression':'表达式',
    'Must provide a value':'必须提供一个值',
    'Delegate Expression':'代理表达式',
    'Script':'脚本',
    'Script Format':'脚本格式',
    'Script Type':'脚本类型',
    'Inline Script':'内联脚本',
    'External Script':'外部脚本',
    'Resource':'资源',
    'Field Injection':'字段注入',
    'Extensions':'扩展',
    'Input/Output':'输入/输出',
    'Input Parameters':'输入参数',
    'Output Parameters':'输出参数',
    'Parameters':'参数',
    'Output Parameter':'输出参数',
    'Timer Definition Type':'定时器定义类型',
    'Timer Definition':'定时器定义',
    'Date':'日期',
    'Duration':'持续',
    'Cycle':'循环',
    'Signal':'信号',
    'Signal Name':'信号名称',
    'Escalation':'升级',
    'Error':'错误',
    'Link Name':'链接名称',
    'Condition':'条件名称',
    'Variable Name':'变量名称',
    'Variable Event':'变量事件',
    'Specify more than one variable change event as a comma separated list.':'多个变量事件以逗号隔开',
    'Wait for Completion':'等待完成',
    'Activity Ref':'活动参考',
    'Version Tag':'版本标签',
    'Executable':'可执行文件',
    'External Task Configuration':'扩展任务配置',
    'Task Priority':'任务优先级',
    'External':'外部',
    'Connector':'连接器',
    'Must configure Connector':'必须配置连接器',
    'Connector Id':'连接器编号',
    'Implementation':'实现方式',
    'Field Injections':'字段注入',
    'Fields':'字段',
    'Result Variable':'结果变量',
    'Topic':'主题',
    'Configure Connector':'配置连接器',
    'Input Parameter':'输入参数',
    'Assignee':'代理人',
    'Candidate Users':'候选用户',
    'Candidate Groups':'候选组',
    'Due Date':'到期时间',
    'Follow Up Date':'跟踪日期',
    'Priority':'优先级',
    'The follow up date as an EL expression (e.g. ${someDate} or an ISO date (e.g. 2015-06-26T09:54:00)':'跟踪日期必须符合EL表达式,如: ${someDate} ,或者一个ISO标准日期,如:2015-06-26T09:54:00',
    'The due date as an EL expression (e.g. ${someDate} or an ISO date (e.g. 2015-06-26T09:54:00)':'跟踪日期必须符合EL表达式,如: ${someDate} ,或者一个ISO标准日期,如:2015-06-26T09:54:00',
    'Variables':'变量',
    'Candidate Starter Configuration':'候选开始配置',
    'Task Listener':'任务监听器',
    'Candidate Starter Groups':'候选开始组',
    'Candidate Starter Users':'候选开始用户',
    'Tasklist Configuration':'任务列表配置',
    'Startable':'启动',
    'Specify more than one group as a comma separated list.':'指定多个组,用逗号分隔',
    'Specify more than one user as a comma separated list.':'指定多个用户,用逗号分隔',
    'This maps to the process definition key.':'这会映射为流程定义的键',
    'CallActivity Type':'调用活动类型',
    'Condition Type':'条件类型',
    'Create UserTask':'创建用户任务',
    'Create CallActivity':'创建调用活动',
    'Called Element':'调用元素',
    'Create DataObjectReference':'创建数据对象引用',
    'Create DataStoreReference':'创建数据存储引用',
    'Multi Instance':'多实例',
    'Loop Cardinality':'实例数量',
    'Collection':'任务参与人列表',
    'Element Variable':'元素变量',
    'Completion Condition':'完成条件'
};

customTranslate.js

import translations from './translations';


export default function customTranslate(template, replacements) {
    replacements = replacements || {};

    // Translate
    template = translations[template] || template;

    // Replace
    return template.replace(/{([^}]+)}/g, function(_, key) {
        return replacements[key] || '{' + key + '}';
    });
}

配置文件  camunda.json

{
  "name":"Camunda",
  "uri": "http://camunda.org/schema/1.0/bpmn",
  "prefix": "camunda",
  "xml": {
    "tagAlias": "lowerCase"
  },
  "associations": [],
  "types": [
    {
      "name": "Definitions",
      "isAbstract": true,
      "extends": [
        "bpmn:Definitions"
      ],
      "properties": [
        {
          "name": "diagramRelationId",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "InOutBinding",
      "superClass": [
        "Element"
      ],
      "isAbstract": true,
      "properties": [
        {
          "name": "source",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "sourceExpression",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "target",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "businessKey",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "local",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
          "name": "variables",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "In",
      "superClass": [
        "InOutBinding"
      ],
      "meta": {
        "allowedIn": [
          "bpmn:CallActivity"
        ]
      }
    },
    {
      "name": "Out",
      "superClass": [
        "InOutBinding"
      ],
      "meta": {
        "allowedIn": [
          "bpmn:CallActivity"
        ]
      }
    },
    {
      "name": "AsyncCapable",
      "isAbstract": true,
      "extends": [
        "bpmn:Activity",
        "bpmn:Gateway",
        "bpmn:Event"
      ],
      "properties": [
        {
          "name": "async",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
          "name": "asyncBefore",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
          "name": "asyncAfter",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        },
        {
          "name": "exclusive",
          "isAttr": true,
          "type": "Boolean",
          "default": true
        }
      ]
    },
    {
      "name": "JobPriorized",
      "isAbstract": true,
      "extends": [
        "bpmn:Process",
        "camunda:AsyncCapable"
      ],
      "properties": [
        {
          "name": "jobPriority",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "SignalEventDefinition",
      "isAbstract": true,
      "extends": [
        "bpmn:SignalEventDefinition"
      ],
      "properties": [
        {
          "name": "async",
          "isAttr": true,
          "type": "Boolean",
          "default": false
        }
      ]
    },
    {
      "name": "ErrorEventDefinition",
      "isAbstract": true,
      "extends": [
        "bpmn:ErrorEventDefinition"
      ],
      "properties": [
        {
          "name": "errorCodeVariable",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "errorMessageVariable",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "Error",
      "isAbstract": true,
      "extends": [
        "bpmn:Error"
      ],
      "properties": [
        {
          "name": "camunda:errorMessage",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "PotentialStarter",
      "superClass": [
        "Element"
      ],
      "properties": [
        {
          "name": "resourceAssignmentExpression",
          "type": "bpmn:ResourceAssignmentExpression"
        }
      ]
    },
    {
      "name": "FormSupported",
      "isAbstract": true,
      "extends": [
        "bpmn:StartEvent",
        "bpmn:UserTask"
      ],
      "properties": [
        {
          "name": "formHandlerClass",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "formKey",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "TemplateSupported",
      "isAbstract": true,
      "extends": [
        "bpmn:Process",
        "bpmn:FlowElement"
      ],
      "properties": [
        {
          "name": "modelerTemplate",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "Initiator",
      "isAbstract": true,
      "extends": [
        "bpmn:StartEvent"
      ],
      "properties": [
        {
          "name": "initiator",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "ScriptTask",
      "isAbstract": true,
      "extends": [
        "bpmn:ScriptTask"
      ],
      "properties": [
        {
          "name": "resultVariable",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "resource",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "Process",
      "isAbstract": true,
      "extends": [
        "bpmn:Process"
      ],
      "properties": [
        {
          "name": "candidateStarterGroups",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "candidateStarterUsers",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "versionTag",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "historyTimeToLive",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "isStartableInTasklist",
          "isAttr": true,
          "type": "Boolean",
          "default": true
        }
      ]
    },
    {
      "name": "EscalationEventDefinition",
      "isAbstract": true,
      "extends": [
        "bpmn:EscalationEventDefinition"
      ],
      "properties": [
        {
          "name": "escalationCodeVariable",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "FormalExpression",
      "isAbstract": true,
      "extends": [
        "bpmn:FormalExpression"
      ],
      "properties": [
        {
          "name": "resource",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "Assignable",
      "extends": [
        "bpmn:UserTask"
      ],
      "properties": [
        {
          "name": "assignee",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "candidateUsers",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "candidateGroups",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "dueDate",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "followUpDate",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "priority",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "CallActivity",
      "extends": [
        "bpmn:CallActivity"
      ],
      "properties": [
        {
          "name": "calledElementBinding",
          "isAttr": true,
          "type": "String",
          "default": "latest"
        },
        {
          "name": "calledElementVersion",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "calledElementVersionTag",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "calledElementTenantId",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "caseRef",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "caseBinding",
          "isAttr": true,
          "type": "String",
          "default": "latest"
        },
        {
          "name": "caseVersion",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "caseTenantId",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "variableMappingClass",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "variableMappingDelegateExpression",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "ServiceTaskLike",
      "extends": [
        "bpmn:ServiceTask",
        "bpmn:BusinessRuleTask",
        "bpmn:SendTask",
        "bpmn:MessageEventDefinition"
      ],
      "properties": [
        {
          "name": "expression",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "class",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "delegateExpression",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "resultVariable",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "DmnCapable",
      "extends": [
        "bpmn:BusinessRuleTask"
      ],
      "properties": [
        {
          "name": "decisionRef",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "decisionRefBinding",
          "isAttr": true,
          "type": "String",
          "default": "latest"
        },
        {
          "name": "decisionRefVersion",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "mapDecisionResult",
          "isAttr": true,
          "type": "String",
          "default": "resultList"
        },
        {
          "name": "decisionRefTenantId",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "ExternalCapable",
      "extends": [
        "camunda:ServiceTaskLike"
      ],
      "properties": [
        {
          "name": "type",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "topic",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "TaskPriorized",
      "extends": [
        "bpmn:Process",
        "camunda:ExternalCapable"
      ],
      "properties": [
        {
          "name": "taskPriority",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "Properties",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "*"
        ]
      },
      "properties": [
        {
          "name": "values",
          "type": "Property",
          "isMany": true
        }
      ]
    },
    {
      "name": "Property",
      "superClass": [
        "Element"
      ],
      "properties": [
        {
          "name": "id",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "name",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "value",
          "type": "String",
          "isAttr": true
        }
      ]
    },
    {
      "name": "Connector",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "camunda:ServiceTaskLike"
        ]
      },
      "properties": [
        {
          "name": "inputOutput",
          "type": "InputOutput"
        },
        {
          "name": "connectorId",
          "type": "String"
        }
      ]
    },
    {
      "name": "InputOutput",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "bpmn:FlowNode",
          "camunda:Connector"
        ]
      },
      "properties": [
        {
          "name": "inputOutput",
          "type": "InputOutput"
        },
        {
          "name": "connectorId",
          "type": "String"
        },
        {
          "name": "inputParameters",
          "isMany": true,
          "type": "InputParameter"
        },
        {
          "name": "outputParameters",
          "isMany": true,
          "type": "OutputParameter"
        }
      ]
    },
    {
      "name": "InputOutputParameter",
      "properties": [
        {
          "name": "name",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "value",
          "isBody": true,
          "type": "String"
        },
        {
          "name": "definition",
          "type": "InputOutputParameterDefinition"
        }
      ]
    },
    {
      "name": "InputOutputParameterDefinition",
      "isAbstract": true
    },
    {
      "name": "List",
      "superClass": [
        "InputOutputParameterDefinition"
      ],
      "properties": [
        {
          "name": "items",
          "isMany": true,
          "type": "InputOutputParameterDefinition"
        }
      ]
    },
    {
      "name": "Map",
      "superClass": [
        "InputOutputParameterDefinition"
      ],
      "properties": [
        {
          "name": "entries",
          "isMany": true,
          "type": "Entry"
        }
      ]
    },
    {
      "name": "Entry",
      "properties": [
        {
          "name": "key",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "value",
          "isBody": true,
          "type": "String"
        },
        {
          "name": "definition",
          "type": "InputOutputParameterDefinition"
        }
      ]
    },
    {
      "name": "Value",
      "superClass": [
        "InputOutputParameterDefinition"
      ],
      "properties": [
        {
          "name": "id",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "name",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "value",
          "isBody": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "Script",
      "superClass": [
        "InputOutputParameterDefinition"
      ],
      "properties": [
        {
          "name": "scriptFormat",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "resource",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "value",
          "isBody": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "Field",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "camunda:ServiceTaskLike",
          "camunda:ExecutionListener",
          "camunda:TaskListener"
        ]
      },
      "properties": [
        {
          "name": "name",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "expression",
          "type": "String"
        },
        {
          "name": "stringValue",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "string",
          "type": "String"
        }
      ]
    },
    {
      "name": "InputParameter",
      "superClass": [
        "InputOutputParameter"
      ]
    },
    {
      "name": "OutputParameter",
      "superClass": [
        "InputOutputParameter"
      ]
    },
    {
      "name": "Collectable",
      "isAbstract": true,
      "extends": [
        "bpmn:MultiInstanceLoopCharacteristics"
      ],
      "superClass": [
        "camunda:AsyncCapable"
      ],
      "properties": [
        {
          "name": "collection",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "elementVariable",
          "isAttr": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "FailedJobRetryTimeCycle",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "camunda:AsyncCapable",
          "bpmn:MultiInstanceLoopCharacteristics"
        ]
      },
      "properties": [
        {
          "name": "body",
          "isBody": true,
          "type": "String"
        }
      ]
    },
    {
      "name": "ExecutionListener",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "bpmn:Task",
          "bpmn:ServiceTask",
          "bpmn:UserTask",
          "bpmn:BusinessRuleTask",
          "bpmn:ScriptTask",
          "bpmn:ReceiveTask",
          "bpmn:ManualTask",
          "bpmn:ExclusiveGateway",
          "bpmn:SequenceFlow",
          "bpmn:ParallelGateway",
          "bpmn:InclusiveGateway",
          "bpmn:EventBasedGateway",
          "bpmn:StartEvent",
          "bpmn:IntermediateCatchEvent",
          "bpmn:IntermediateThrowEvent",
          "bpmn:EndEvent",
          "bpmn:BoundaryEvent",
          "bpmn:CallActivity",
          "bpmn:SubProcess",
          "bpmn:Process"
        ]
      },
      "properties": [
        {
          "name": "expression",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "class",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "delegateExpression",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "event",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "script",
          "type": "Script"
        },
        {
          "name": "fields",
          "type": "Field",
          "isMany": true
        }
      ]
    },
    {
      "name": "TaskListener",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "bpmn:UserTask"
        ]
      },
      "properties": [
        {
          "name": "expression",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "class",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "delegateExpression",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "event",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "script",
          "type": "Script"
        },
        {
          "name": "fields",
          "type": "Field",
          "isMany": true
        },
        {
          "name": "id",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "eventDefinitions",
          "type": "bpmn:TimerEventDefinition",
          "isMany": true
        }
      ]
    },
    {
      "name": "FormProperty",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "bpmn:StartEvent",
          "bpmn:UserTask"
        ]
      },
      "properties": [
        {
          "name": "id",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "name",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "type",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "required",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "readable",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "writable",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "variable",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "expression",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "datePattern",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "default",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "values",
          "type": "Value",
          "isMany": true
        }
      ]
    },
    {
      "name": "FormData",
      "superClass": [
        "Element"
      ],
      "meta": {
        "allowedIn": [
          "bpmn:StartEvent",
          "bpmn:UserTask"
        ]
      },
      "properties": [
        {
          "name": "fields",
          "type": "FormField",
          "isMany": true
        },
        {
          "name": "businessKey",
          "type": "String",
          "isAttr": true
        }
      ]
    },
    {
      "name": "FormField",
      "superClass": [
        "Element"
      ],
      "properties": [
        {
          "name": "id",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "label",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "type",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "datePattern",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "defaultValue",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "properties",
          "type": "Properties"
        },
        {
          "name": "validation",
          "type": "Validation"
        },
        {
          "name": "values",
          "type": "Value",
          "isMany": true
        }
      ]
    },
    {
      "name": "Validation",
      "superClass": [
        "Element"
      ],
      "properties": [
        {
          "name": "constraints",
          "type": "Constraint",
          "isMany": true
        }
      ]
    },
    {
      "name": "Constraint",
      "superClass": [
        "Element"
      ],
      "properties": [
        {
          "name": "name",
          "type": "String",
          "isAttr": true
        },
        {
          "name": "config",
          "type": "String",
          "isAttr": true
        }
      ]
    },
    {
      "name": "ConditionalEventDefinition",
      "isAbstract": true,
      "extends": [
        "bpmn:ConditionalEventDefinition"
      ],
      "properties": [
        {
          "name": "variableName",
          "isAttr": true,
          "type": "String"
        },
        {
          "name": "variableEvent",
          "isAttr": true,
          "type": "String"
        }
      ]
    }
  ],
  "emumerations": []
}

引入依赖和样式

main.js 文件中引入样式

import 'bpmn-js/dist/assets/diagram-js.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';

页面文件中,引入js依赖

import BpmnModeler from 'bpmn-js/lib/Modeler';
import camundaExtension from '@/camunda/camunda.json'; //定义各个元素拥有的属性配置
import customTranslate from "@/conf/customTranslate";//汉化

页面代码展示

<template>
  <div id="app">
    <el-button-group>
      <el-button type="primary" size="mini" @click="handleUndo">后退</el-button>
      <el-button type="success" size="mini" @click="handleRedo">前进</el-button>
      <el-button type="warning" size="mini" @click="handleDownload">下载</el-button>
      <el-upload style="display: inline-block;" :file-list="fileList" class="upload-demo" action="" :auto-upload="false"
                 :show-file-list="false" :on-change="handleOnchangeFile" :on-remove="handleRemove"
                 :before-remove="beforeRemove">
        <el-button type="danger" size="mini">导入</el-button>
      </el-upload>
    </el-button-group>
    <div id="container"></div>
  </div>
</template>

<script>
import BpmnModeler from 'bpmn-js/lib/Modeler';
import camundaExtension from '@/camunda/camunda.json'; //定义各个元素拥有的属性配置
import customTranslate from "@/conf/customTranslate";//汉化
export default {
  name: 'App',
  data() {
    return {
      containerEl: null,
      bpmnModeler: null,
      fileList: [],
    }
  },
  mounted() {
    let customTranslateModule={
      translate:["value",customTranslate]
    };
    this.containerEl = document.getElementById('container');
    this.bpmnModeler = new BpmnModeler({
      container: this.containerEl,
      moddleExtensions: {camunda: camundaExtension},
      additionalModules: [
        // 汉化
        customTranslateModule,
      ],
    });
    this.create();
  },
  methods: {
    create() {
      this.bpmnModeler.createDiagram(() => {
        this.bpmnModeler.get('canvas').zoom('fit-viewport');
      });
    },
    handleRemove(file) {
      for (let i = 0; i < this.fileList.length; i++) {
        if (file.name === this.fileList[i].name) {
          this.fileList.splice(i, 1);
        }
      }
    },
    beforeRemove(file) {
      return this.$confirm(`确定移除 ${file.name}?`);
    },
    // 后退
    handleUndo() {
      this.bpmnModeler.get('commandStack').undo();
    },
    // 前进
    handleRedo() {
      this.bpmnModeler.get('commandStack').redo();
    },
    handleDownload() {
      this.bpmnModeler.saveXML({format: true}, (err, data) => {
        const dataTrack = 'bpmn';
        const a = document.createElement('a');
        const name = `diagram.${dataTrack}`;
        a.setAttribute(
            'href',
            `data:application/bpmn20-xml;charset=UTF-8,${encodeURIComponent(data)}`
        );
        a.setAttribute('target', '_blank');
        a.setAttribute('dataTrack', `diagram:download-${dataTrack}`);
        a.setAttribute('download', name);
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
      });
    },
    handleOnchangeFile(file) {
      const reader = new FileReader();
      let data = '';
      reader.readAsText(file.raw);
      reader.onload = (event) => {
        data = event.target.result;
        this.bpmnModeler.importXML(data, (err) => {
          if (err) {
            this.$message.info('导入失败');
          } else {
            this.$message.success('导入成功');
          }
        });
      };
    }

  }
}
</script>

<style>


#app {
  width: 100%;
  height: 100%;
}

body, html {
  padding: 0;
  margin: 0;
  height: 100%;
  width: 100%;
}

#container {
  height: calc(100% - 50px);
  background-size: 20px 20px, 20px 20px, 10px 10px, 10px 10px;
  background-image: linear-gradient(to right, #dfdfdf 1px, transparent 1px), linear-gradient(to bottom, #dfdfdf 1px, transparent 1px), linear-gradient(to right, #f1f1f1 1px, transparent 1px), linear-gradient(to bottom, #f1f1f1 1px, transparent 1px);
  background-position: left -1px top -1px, left -1px top -1px, left -1px top -1px, left -1px top -1px;
}
</style>

以上就是vue2+与bpmn.js结合的案例展示,希望可以帮助到各位正在做流程这一块儿的小伙伴。

24人点赞 返回栏目 提问 分享一波

小礼物走一波,支持作者

还没有人赞赏,支持一波吧

留言(问题紧急可添加微信 xxl18963067593) 评论仅代表网友个人 留言列表

暂无留言,快来抢沙发吧!

本刊热文
网友在读
手机扫码查看 手机扫码查看