customPalette.js 2.93 KB
/* eslint-disable no-unused-vars */
export default class CustomPalette {
  constructor(bpmnFactory, create, elementFactory, palette, translate) {
    this.bpmnFactory = bpmnFactory
    this.create = create
    this.elementFactory = elementFactory
    this.translate = translate

    palette.registerProvider(this)
  }

  getPaletteEntries(element) {
    const { bpmnFactory, create, elementFactory, translate } = this
    function createTask() {
      return function(event) {
        const extensionElements = bpmnFactory.create('bpmn:ExtensionElements')
        const Properties = bpmnFactory.create('camunda:Properties')
        const Property = bpmnFactory.create('camunda:Property')
        Property.name = 'custom'
        Property.value = 'msgTask'
        Properties.values = [Property]
        extensionElements.values = [Properties]
        const businessObject = bpmnFactory.create('bpmn:ServiceTask', {
          'camunda:class': 'com.yonde.dex.wfc.engine.camunda.delegate.CamundaServiceTaskDelegate',
          extensionElements: extensionElements
        })

        const shape = elementFactory.createShape({
          type: 'bpmn:ServiceTask',
          businessObject: businessObject
        })
        create.start(event, shape)
      }
    }
    function createUserTask() {
      return function(event) {
        const extensionElements = bpmnFactory.create('bpmn:ExtensionElements')
        const Properties = bpmnFactory.create('camunda:Properties')
        const Property = bpmnFactory.create('camunda:Property')
        Property.name = 'relationInfo'
        Property.value = JSON.stringify({
          taskExtInfo: {
            custom: 'userTask'
          }
        })
        Properties.values = [Property]
        extensionElements.values = [Properties]
        const businessObject = bpmnFactory.create('bpmn:UserTask', {
          extensionElements: extensionElements
        })

        const shape = elementFactory.createShape({
          type: 'bpmn:UserTask',
          businessObject: businessObject
        })
        create.start(event, shape)
      }
    }
    return {
      'create.notify-task': {
        title: '消息通知', // 鼠标悬浮到节点上显示的文字
        className: 'icon-custom bpmn-icon-notify', // 样式名
        action: { // 操作该节点时会触发的事件,此时只注册一个拖动事件即可,否则拖动时没有效果
          dragstart: createTask(),
          click: createTask()
        }
      },
      'create.user-task': {
        title: '插入', // 鼠标悬浮到节点上显示的文字
        className: 'icon-custom bpmn-icon-custom-user-task', // 样式名
        action: { // 操作该节点时会触发的事件,此时只注册一个拖动事件即可,否则拖动时没有效果
          dragstart: createUserTask(),
          click: createUserTask()
        }
      }
    }
  }
}

CustomPalette.$inject = [
  'bpmnFactory',
  'create',
  'elementFactory',
  'palette',
  'translate'
]