用户任务活动节点也提供了一组事件监听器

一个listener定义

src/module/test-flow/backend/src/config/static/flowDef/listener/set01_atomUserTask.spec.js

const require3 = require('require3');
const assert = require3('assert');

module.exports = class Listener {
  constructor(context) {
    this.context = context;
  }

  async onNodeEnter(contextNode) {
    if (contextNode._nodeDef.id === 'startEvent_1') {
      const _flowDefKey = this.context.atom._flowDefKey;
      assert.equal(_flowDefKey, 'set01_atomUserTask');
    }
  }

  async onTaskCreated(contextTask, contextNode) {
    console.log('onTaskCreated: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  }

  async onTaskClaimed(contextTask, contextNode) {
    console.log('onTaskClaimed: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  }

  async onTaskCompleted(contextTask, contextNode) {
    console.log('onTaskCompleted: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
    console.log('handleStatus: %d, handleRemark: %s', contextTask._flowTask.handleStatus, contextTask._flowTask.handleRemark);
  }

  async getSchemaRead(contextTask, contextNode/* { schemaBase, schema }*/) {
    console.log('getSchemaRead: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  }

  async getSchemaWrite(contextTask, contextNode/* { schemaBase, schema }*/) {
    console.log('getSchemaWrite: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  }

  getNodeDefOptions(contextNode /* { options }*/) {
    console.log('getNodeDefOptions: ', contextNode._nodeDef.id);
  }

};

1. 环境对象

  • this.context:流程实例环境对象
  • contextNode:活动节点环境对象
  • contextTask:用户任务环境对象

2. 用户任务事件

  • onTaskCreated:用户任务创建事件
async onTaskCreated(contextTask, contextNode)
  • onTaskClaimed:用户任务签收事件
async onTaskClaimed(contextTask, contextNode)
  • onTaskCompleted:用户任务完成事件
async onTaskCompleted(contextTask, contextNode)

3. 工具方法

  • getSchemaRead

Read Schema可以控制当前用户任务可以读取哪些字段

通过重载此方法,可以提供动态修改之后的用户任务Read Schema参数

async getSchemaRead(contextTask, contextNode, { schemaBase, schema })
  • getSchemaWrite

Write Schema可以控制当前用户任务可以修改哪些字段

通过重载此方法,可以提供动态修改之后的用户任务Write Schema参数

async getSchemaWrite(contextTask, contextNode, { schemaBase, schema })