index.ts 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import ContextPadProvider from 'bpmn-js/lib/features/context-pad/ContextPadProvider';
  2. import CustomizeContextPad from '../provider/CustomizeContextPad';
  3. import { jnpfConfigBpmnContextPad } from '../../config/contextPad';
  4. class YmContextPadProvider extends ContextPadProvider {
  5. _modeling: any;
  6. _rules: any;
  7. _injector: any;
  8. _eventBus: any;
  9. _canvas: any;
  10. constructor(
  11. config: any,
  12. injector: any,
  13. eventBus: any,
  14. contextPad: any,
  15. modeling: any,
  16. elementFactory: any,
  17. connect: any,
  18. create: any,
  19. popupMenu: any,
  20. canvas: any,
  21. rules: any,
  22. translate: any,
  23. ) {
  24. super(config, injector, eventBus, contextPad, modeling, elementFactory, connect, create, popupMenu, canvas, rules, translate);
  25. this._rules = rules;
  26. this._modeling = modeling;
  27. this._injector = injector;
  28. this._eventBus = eventBus;
  29. this._canvas = canvas;
  30. }
  31. override getContextPadEntries(element: any): (() => any) | any | undefined {
  32. return CustomizeContextPad(this, element);
  33. }
  34. // 多个元素框选时 默认包含框选删除元素
  35. override getMultiElementContextPadEntries(element: any) {
  36. var actions = {};
  37. const { del } = jnpfConfigBpmnContextPad;
  38. Object.assign(actions, {
  39. delete: {
  40. group: 'edit',
  41. className: del.className,
  42. title: del.title,
  43. action: {
  44. click: (_event: any, elements: any) => {
  45. //判断存在开始节点给出不能删除的提示
  46. const hasStartElement = elements.some(o => o.type == 'bpmn:StartEvent');
  47. hasStartElement &&
  48. this._eventBus.fire('custom.message', {
  49. context: '无法删除开始节点',
  50. messageType: 'warning',
  51. });
  52. //过滤开始节点后删除选择的节点
  53. const newElements = elements.filter(o => o.type != 'bpmn:StartEvent');
  54. this._eventBus.fire('commandStack.canExecute', {
  55. command: 'elements.delete',
  56. context: {
  57. elements: newElements,
  58. },
  59. });
  60. },
  61. },
  62. },
  63. });
  64. return actions;
  65. }
  66. }
  67. YmContextPadProvider.$inject = [
  68. 'config.contextPad',
  69. 'injector',
  70. 'eventBus',
  71. 'contextPad',
  72. 'modeling',
  73. 'elementFactory',
  74. 'connect',
  75. 'create',
  76. 'popupMenu',
  77. 'canvas',
  78. 'rules',
  79. 'translate',
  80. ];
  81. export default YmContextPadProvider;