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

一个listener定义

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

  1. 1const require3 = require('require3');
  2. 2const assert = require3('assert');
  3. 3
  4. 4module.exports = class Listener {
  5. 5 constructor(context) {
  6. 6 this.context = context;
  7. 7 }
  8. 8
  9. 9 async onNodeEnter(contextNode) {
  10. 10 if (contextNode._nodeDef.id === 'startEvent_1') {
  11. 11 const _flowDefKey = this.context.atom._flowDefKey;
  12. 12 assert.equal(_flowDefKey, 'set01_atomUserTask');
  13. 13 }
  14. 14 }
  15. 15
  16. 16 async onTaskCreated(contextTask, contextNode) {
  17. 17 console.log('onTaskCreated: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  18. 18 }
  19. 19
  20. 20 async onTaskClaimed(contextTask, contextNode) {
  21. 21 console.log('onTaskClaimed: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  22. 22 }
  23. 23
  24. 24 async onTaskCompleted(contextTask, contextNode) {
  25. 25 console.log('onTaskCompleted: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  26. 26 console.log('handleStatus: %d, handleRemark: %s', contextTask._flowTask.handleStatus, contextTask._flowTask.handleRemark);
  27. 27 }
  28. 28
  29. 29 async getSchemaRead(contextTask, contextNode/* { schemaBase, schema }*/) {
  30. 30 console.log('getSchemaRead: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  31. 31 }
  32. 32
  33. 33 async getSchemaWrite(contextTask, contextNode/* { schemaBase, schema }*/) {
  34. 34 console.log('getSchemaWrite: ', contextTask._flowTaskId, ' of node: ', contextNode._nodeDef.id);
  35. 35 }
  36. 36
  37. 37 getNodeDefOptions(contextNode /* { options }*/) {
  38. 38 console.log('getNodeDefOptions: ', contextNode._nodeDef.id);
  39. 39 }
  40. 40
  41. 41};

1. 环境对象

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

2. 用户任务事件

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

3. 工具方法

  • getSchemaRead

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

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

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

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

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

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