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