¶Ô±ÈÐÂÎļþ |
| | |
| | | import ContextPadProvider from 'bpmn-js/lib/features/context-pad/ContextPadProvider'; |
| | | import { Injector } from 'didi'; |
| | | import EventBus from 'diagram-js/lib/core/EventBus'; |
| | | import ContextPad from 'diagram-js/lib/features/context-pad/ContextPad'; |
| | | import Modeling from 'bpmn-js/lib/features/modeling/Modeling.js'; |
| | | import ElementFactory from 'bpmn-js/lib/features/modeling/ElementFactory'; |
| | | import Connect from 'diagram-js/lib/features/connect/Connect'; |
| | | import Create from 'diagram-js/lib/features/create/Create'; |
| | | import PopupMenu from 'diagram-js/lib/features/popup-menu/PopupMenu'; |
| | | import Canvas from 'diagram-js/lib/core/Canvas'; |
| | | import Rules from 'diagram-js/lib/features/rules/Rules'; |
| | | import { Element, Shape } from 'diagram-js/lib/model/Types'; |
| | | import BpmnFactory from 'bpmn-js/lib/features/modeling/BpmnFactory'; |
| | | import modeler from '@/store/modules/modeler'; |
| | | |
| | | // @Description: å¢å¼ºå
ç´ è¿çº¿äºä»¶ |
| | | |
| | | class CustomContextPadProvider extends ContextPadProvider { |
| | | private _contextPad: ContextPad; |
| | | private _modeling: Modeling; |
| | | private _elementFactory: ElementFactory; |
| | | private _autoPlace: any; |
| | | private _connect: Connect; |
| | | private _create: Create; |
| | | private _popupMenu: PopupMenu; |
| | | private _canvas: Canvas; |
| | | private _rules: Rules; |
| | | |
| | | constructor( |
| | | config: any, |
| | | injector: Injector, |
| | | eventBus: EventBus, |
| | | contextPad: ContextPad, |
| | | modeling: Modeling, |
| | | elementFactory: ElementFactory, |
| | | connect: Connect, |
| | | create: Create, |
| | | popupMenu: PopupMenu, |
| | | canvas: Canvas, |
| | | rules: Rules, |
| | | translate |
| | | ) { |
| | | // @ts-expect-error 忽ç¥å¼å¸¸ |
| | | super(config, injector, eventBus, contextPad, modeling, elementFactory, connect, create, popupMenu, canvas, rules, translate); |
| | | |
| | | this._contextPad = contextPad; |
| | | this._modeling = modeling; |
| | | this._elementFactory = elementFactory; |
| | | this._connect = connect; |
| | | this._create = create; |
| | | this._popupMenu = popupMenu; |
| | | this._canvas = canvas; |
| | | this._rules = rules; |
| | | |
| | | this._autoPlace = injector.get('autoPlace', false); |
| | | } |
| | | |
| | | getContextPadEntries(element: Element) { |
| | | const actions: Record<string, any> = {}; |
| | | |
| | | const appendUserTask = (event: Event, element: Shape) => { |
| | | const shape = this._elementFactory.createShape({ type: 'bpmn:UserTask' }); |
| | | this._create.start(event, shape, { |
| | | source: element |
| | | }); |
| | | }; |
| | | |
| | | const appendMultiInstanceUserTask = (event: Event, element: Shape) => { |
| | | const store = modeler(); |
| | | const bpmnFactory = store.getModeler().get('bpmnFactory') as BpmnFactory; |
| | | const businessObject = bpmnFactory.create('bpmn:UserTask', { |
| | | // name: 'å¤å®ä¾ç¨æ·ä»»å¡', |
| | | isForCompensation: false |
| | | }); |
| | | businessObject.loopCharacteristics = bpmnFactory.create('bpmn:MultiInstanceLoopCharacteristics'); |
| | | // å建 Shape |
| | | const shape = this._elementFactory.createShape({ |
| | | type: 'bpmn:UserTask', |
| | | businessObject: businessObject |
| | | }); |
| | | this._create.start(event, shape, { source: element }); |
| | | }; |
| | | |
| | | const appendTask = this._autoPlace |
| | | ? (event, element) => { |
| | | const bpmnFactory: BpmnFactory | undefined = modeler().getModeler().get('bpmnFactory'); |
| | | const businessObject = bpmnFactory.create('bpmn:UserTask', { |
| | | // name: 'å¤å®ä¾ç¨æ·ä»»å¡',// å³é®å建æ¾ç¤º |
| | | isForCompensation: false |
| | | }); |
| | | |
| | | // å建å¤å®ä¾å±æ§å¹¶åé
ç»ç¨æ·ä»»å¡ç loopCharacteristics |
| | | businessObject.loopCharacteristics = bpmnFactory.create('bpmn:MultiInstanceLoopCharacteristics'); |
| | | |
| | | // å建 Shape |
| | | const shape = this._elementFactory.createShape({ |
| | | type: 'bpmn:UserTask', |
| | | businessObject: businessObject |
| | | }); |
| | | |
| | | this._autoPlace.append(element, shape); |
| | | } |
| | | : appendMultiInstanceUserTask; |
| | | |
| | | const append = this._autoPlace |
| | | ? (event: Event, element: Shape) => { |
| | | const shape = this._elementFactory.createShape({ type: 'bpmn:UserTask' }); |
| | | this._autoPlace.append(element, shape); |
| | | } |
| | | : appendUserTask; |
| | | |
| | | // // æ·»å åå»ºç¨æ·ä»»å¡æé® |
| | | actions['append.append-user-task'] = { |
| | | group: 'model', |
| | | className: 'bpmn-icon-user-task', |
| | | title: 'ç¨æ·ä»»å¡', |
| | | action: { |
| | | dragstart: appendUserTask, |
| | | click: append |
| | | } |
| | | }; |
| | | |
| | | // æ·»å å建å¤å®ä¾ç¨æ·ä»»å¡æé® |
| | | actions['append.append-multi-instance-user-task'] = { |
| | | group: 'model', |
| | | className: 'bpmn-icon-user', // ä½ å¯ä»¥ä½¿ç¨å¤å®ä¾ç¨æ·ä»»å¡ç徿 bpmn-icon-user bpmn-icon-user-task |
| | | title: 'å¤å®ä¾ç¨æ·ä»»å¡', |
| | | action: { |
| | | dragstart: appendMultiInstanceUserTask, |
| | | click: appendTask |
| | | } |
| | | }; |
| | | |
| | | return actions; |
| | | } |
| | | } |
| | | |
| | | export default CustomContextPadProvider; |