bpmn-js快速上手及汉化

7 篇文章 0 订阅
3 篇文章 3 订阅

一、效果

二、结构

三、步骤

1、引入依赖包

2、入口文件(index.vue)

<template>
  <div>
    <a @click="$refs.modeler.showDrawer()">流程图设计器</a>
    <modeler ref="modeler"/>
  </div>
</template>

<script>
import modeler from './modeler/index'
export default {
  name: 'Index',
  components: {
    modeler
  }
}
</script>

<style scoped>

</style>

3、bpmn-js使用(index.vue)

<template>
  <a-drawer
    placement="right"
    :closable="true"
    :visible="visible"
    width="100%"
    @close="onClose"
  >
    <div class="containers">
      <div class="canvas" ref="canvas"></div>
      <div id="js-properties-panel" class="panel"></div>
    </div>
  </a-drawer>
</template>

<script>
// 引入相关的依赖
import BpmnModeler from 'bpmn-js/lib/Modeler'
// import {
//   xmlStr
// } from '../mock/xmlStr' // 这里是直接引用了xml字符串

import propertiesProviderModule from 'bpmn-js-properties-panel/lib/provider/camunda'
import propertiesPanelModule from 'bpmn-js-properties-panel'

import customTranslate from './i18/customTranslate'

// Our custom translation module
// We need to use the array syntax that is used by bpmn-js internally
// 'value' tells bmpn-js to use the function instead of trying to instanciate it
var customTranslateModule = {
  translate: [ 'value', customTranslate ]
}
const xmlStr = `<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="sid-38422fae-e03e-43a3-bef4-bd33b32041b2" targetNamespace="http://bpmn.io/bpmn" exporter="bpmn-js (https://demo.bpmn.io)" exporterVersion="5.1.2">
<process id="Process_1" isExecutable="false">
    <startEvent id="StartEvent_1y45yut" name="开始">
    <outgoing>SequenceFlow_0h21x7r</outgoing>
    </startEvent>
    <task id="Task_1hcentk">
    <incoming>SequenceFlow_0h21x7r</incoming>
    </task>
    <sequenceFlow id="SequenceFlow_0h21x7r" sourceRef="StartEvent_1y45yut" targetRef="Task_1hcentk" />
</process>
<bpmndi:BPMNDiagram id="BpmnDiagram_1">
    <bpmndi:BPMNPlane id="BpmnPlane_1" bpmnElement="Process_1">
    <bpmndi:BPMNShape id="StartEvent_1y45yut_di" bpmnElement="StartEvent_1y45yut">
        <omgdc:Bounds x="152" y="102" width="36" height="36" />
        <bpmndi:BPMNLabel>
        <omgdc:Bounds x="160" y="145" width="22" height="14" />
        </bpmndi:BPMNLabel>
    </bpmndi:BPMNShape>
    <bpmndi:BPMNShape id="Task_1hcentk_di" bpmnElement="Task_1hcentk">
        <omgdc:Bounds x="240" y="80" width="100" height="80" />
    </bpmndi:BPMNShape>
    <bpmndi:BPMNEdge id="SequenceFlow_0h21x7r_di" bpmnElement="SequenceFlow_0h21x7r">
        <omgdi:waypoint x="188" y="120" />
        <omgdi:waypoint x="240" y="120" />
    </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>`

export default {
  data() {
    return {
      visible: false,
      // bpmn建模器
      bpmnModeler: null,
      container: null,
      canvas: null
    }
  },
  methods: {
    showDrawer(record) {
      setTimeout(() => {
        this.init()
      }, 100)
      this.visible = true
    },
    onClose() {
      this.bpmnModeler.destroy()
      this.visible = false
    },
    init() {
      // 获取到属性ref为“canvas”的dom节点
      // 建模
      this.bpmnModeler = new BpmnModeler({
        container: this.$refs.canvas,
        keyboard: {
          bindTo: window
        },
        // 添加控制板
        propertiesPanel: {
          parent: '#js-properties-panel'
        },
        additionalModules: [
          // 左边工具栏以及节点
          propertiesProviderModule,
          // 右边的工具栏
          propertiesPanelModule,
          customTranslateModule
        ]
      })
      this.createNewDiagram()
    },
    async createNewDiagram() {
      // 将字符串转换成图显示出来
      // this.bpmnModeler.importXML(xmlStr, (err) => {
      //   if (err) {
      //     // console.error(err)
      //   } else {
      //     // 这里是成功之后的回调, 可以在这里做一系列事情
      //     this.success()
      //   }
      // })
      try {
        const result = await this.bpmnModeler.importXML(xmlStr)
        const { warnings } = result
        console.log(warnings)
      } catch (err) {
        console.log(err.message, err.warnings)
      }
    },
    success() {
      // console.log('创建成功!')
    }
  }
}
</script>

<style scoped>
.containers{
  position: absolute;
  background-color: #ffffff;
  width: 100%;
  height: 100%;
}
.canvas{
  width: 100%;
  height: 100%;
}
.panel{
  position: absolute;
  right: 0;
  top: 0;
  /*width: 300px;*/
}
</style>

4、汉化

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 + '}'
  })
}

// import translations from './translations'
//
// export default function customTranslate(template, replacements) {
//   replacements = replacements || {}
//
//   // Translate
//   template = translations[template] || template
//
//   // Replace
//   return template.replace(/{([^}]+)}/g, function (_, key) {
//     var str = replacements[key]
//     if (
//       translations[replacements[key]] != null &&
//       translations[replacements[key]] !== 'undefined'
//     ) {
//       str = translations[replacements[key]]
//     }
//     return str || '{' + key + '}'
//   })
// }

translations.js

/**
 * This is a sample file that should be replaced with the actual translation.
 *
 * Checkout https://github.com/bpmn-io/bpmn-js-i18n for a list of available
 * translations and labels to translate.
 */
// export default {
//
//   // Labels
//   'Activate the global connect tool': '启动全局连接工具',
//   'Append {type}': '追加 {type}',
//   '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': '启动 Lasso 工具',
//   'Activate the create/remove space tool': '启动创建/删除空间工具',
//   'Create expanded SubProcess': '创建可折叠子流程',
//   'Create IntermediateThrowEvent/BoundaryEvent': '创建中间抛出/边界事件',
//   'Create Pool/Participant': '创建池/参与者',
//   'Parallel Multi Instance': '并行多实例',
//   'Sequential Multi Instance': '串行多实例',
//   'Loop': '循环',
//   'Ad-hoc': 'Ad-hoc子流程',
//   'Create {type}': '创建 {type}',
//   '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': '开始事件',
//   'Intermediate Throw Event': '中间抛出事件',
//   'End 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}': '在 {element} 中没有父元素 {parent}',
//   'no shape type specified': '未指定形状类型',
//   'flow elements must be children of pools/participants': '元素必须是池/参与者的子级',
//   'out of bounds release': '越界释放',
//   'more than {count} child lanes': '超过 {count} 条通道',
//   'element required': '需要元素',
//   'diagram not part of bpmn:Definitions': '图表不是 bpmn:Definitions 的一部分',
//   'no diagram to display': '没有要显示的图表',
//   'no process or collaboration to display': '没有可显示的流程或协作',
//   'element {element} referenced by {referenced}#{property} not yet drawn': '元素 {element} 的引用 {referenced}#{property} 尚未绘制',
//   'already rendered {element}': '{element} 已呈现',
//   'failed to import {element}': '{element} 导入失败'
// }

export default {
  // Labels
  'Activate the global connect tool': '激活全局连接工具',
  'Append {type}': '添加 {type}',
  '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}',
  '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': '创建网关',
  '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': '值',
  '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': '变量'
}

 

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

<每天一点>

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值