刘光辉
13 小时以前 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import { changeTypeByTaskShape, typeConfig } from '../../config';
import { append as svgAppend, create as svgCreate } from 'tiny-svg';
import {
  bpmnChoose,
  bpmnEnd,
  bpmnExclusive,
  bpmnGroup,
  bpmnInclusive,
  bpmnLabel,
  bpmnOutside,
  bpmnParallel,
  bpmnProcessing,
  bpmnStart,
  bpmnSubFlow,
  bpmnTask,
  bpmnTrigger,
  typeChoose,
  typeCondition,
  typeConfluence,
  typeOutside,
  typeProcessing,
  typeSubFlow,
  typeTrigger,
} from '../../config/variableName';
 
/**
 * svg重画bpmn节点
 */
export default (parentNode: any, element: any, jnpfFlowInfo: any, injector: any) => {
  let type = element.type; // 获取到类型
  let data = jnpfFlowInfo?.flowNodes[element.id];
  let wnType = element.wnType || data?.type;
  if (typeConfig && typeConfig[type]) {
    if (type === bpmnGroup) return null;
    const typeMap = {
      [typeSubFlow]: bpmnSubFlow,
      [typeProcessing]: bpmnProcessing,
      [typeTrigger]: bpmnTrigger,
      [typeOutside]: bpmnOutside,
    };
    let matchedType = typeMap[data?.type] || typeMap[element.wnType];
    if(matchedType) type = matchedType;
    if (changeTypeByTaskShape[data?.type] || changeTypeByTaskShape[element?.wnType]) type = changeTypeByTaskShape[element?.wnType || data?.type];
    if (type === bpmnInclusive && wnType === typeChoose) type = bpmnChoose;
    let { renderer } = typeConfig[type];
    let { icon, iconColor, rendererName, background, titleColor, attr, bodyDefaultText } = renderer;
    //  直接修改元素的宽高
    element['width'] = wnType === typeConfluence ? 1 : element.isPreview ? 1 : attr.width;
    element['height'] = wnType === typeConfluence ? 1 : element.isPreview ? 1 : attr.height;
    let nodeName = element.nodeName != null ? element.nodeName : data?.nodeName != null ? data.nodeName : rendererName;
    let nodeContent = element.elementBodyName || data?.content || bodyDefaultText;
    let foreignObject: any = svgCreate('foreignObject', {
      width: wnType === typeConfluence ? 0 : element.isPreview ? 1 : wnType === typeCondition ? 128 : attr.width,
      height: wnType === typeConfluence ? 0 : element.isPreview ? 1 : wnType === typeCondition ? 28 : attr.height,
      class: type === bpmnStart || type === bpmnEnd ? 'begin-or-end-node' : 'task-node',
    });
    // 开始节点
    if (type === bpmnStart) {
      foreignObject.innerHTML = `
      <div class="node-container start-node-container" style="background:${background}" >
        <div class='node-top-container'>
          <i class="${icon}" style="color:${iconColor}"></i>
          <span>${nodeName}</span>
        </div>
      </div>`;
      svgAppend(parentNode, foreignObject);
      return parentNode;
    }
    // 审批节点
    if (type === bpmnTask) {
      foreignObject.innerHTML = `
      <div class="node-container" style="background:${background}" >
        <div class='node-top-container' style="background:${titleColor};">
          <i class="${icon}" style="color:${iconColor}"></i>
          <span>${nodeName}</span>
        </div>
        <div class='node-bottom-container'>
          <span>${nodeContent}</span>  
        </div>
      </div>`;
      svgAppend(parentNode, foreignObject);
      return parentNode;
    }
    // 子流程节点
    if (type === bpmnSubFlow || type === bpmnProcessing || type === bpmnOutside || type === bpmnTrigger || changeTypeByTaskShape[element?.wnType || data?.type]) {
      foreignObject.innerHTML = `
      <div class="node-container" style="background:${background}" >
        <div class='node-top-container' style="background:${titleColor}">
          <i class="${icon}" style="color:${iconColor}"></i>
          <span>${nodeName}</span>
        </div>
        <div class='node-bottom-container'>
          <span>${nodeContent}</span>
        </div>
      </div>`;
      svgAppend(parentNode, foreignObject);
      return parentNode;
    }
    // 结束节点
    if (type === bpmnEnd) {
      foreignObject.innerHTML = `
      <div class="node-container end-node-container" style="background:${background}" >
        <div class='node-top-container'>
          <i class="${icon}" style="color:${iconColor}"></i>
          <span>${nodeName}</span>
        </div>
      </div>`;
      svgAppend(parentNode, foreignObject);
      return parentNode;
    }
    // label改为按钮
    if (type === bpmnLabel) {
      if (wnType === 'condition') {
        let jnpfData = injector?.get('jnpfData');
        let data = jnpfData.getValue('global');
        let connectName = jnpfData.data[element.id.replace('_condition', '')]?.nodeName || '连接线';
        if (data.isShowConditions) {
          let foreignObject: any = svgCreate('foreignObject', {
            width: 128,
            height: 28,
            class: 'label-node',
          });
          foreignObject.innerHTML = `
          <div class="node-container-label" >
            <div class='node-top-container'>
              <span>${data.showNameType === 1 ? element.text : connectName}</span>
            </div>
          </div>`;
          element.text && svgAppend(parentNode, foreignObject);
        }
        return null;
      } else {
        foreignObject.innerHTML = `
        <div class="node-container"  >
          <div class='label-node-container'>+</div>
        </div>`;
        svgAppend(parentNode, foreignObject);
      }
      return parentNode;
    }
 
    // 条件分支
    if (type === bpmnInclusive) {
      // 合流 展示一个点
      if (element.wnType === typeConfluence) {
        foreignObject.innerHTML = `
        <div class="node-container start-node-container node-simpleModeler" style="background:${background}" >
          <div class='node-top-container'>
            <span>合流</span>
          </div>
        </div>`;
      } else if (wnType === typeChoose) {
        foreignObject.innerHTML = `
        <div class="node-container start-node-container node-simpleModeler" style="background:${background}" >
          <div class='node-top-container'>
            <span>${rendererName}</span>
          </div>
        </div>`;
      } else {
        foreignObject.innerHTML = `
        <div class="node-container start-node-container node-simpleModeler" style="background:${background}" >
          <div class='node-top-container'>
            <span>添加条件</span>
          </div>
        </div>`;
      }
      svgAppend(parentNode, foreignObject);
      return parentNode;
    }
 
    // 其它网关
    let otherGatewayRule = new Set([bpmnParallel, bpmnExclusive, bpmnChoose]);
    if (otherGatewayRule.has(type)) {
      foreignObject.innerHTML = `
      <div class="node-container start-node-container node-simpleModeler" style="background:${background}" >
        <div class='node-top-container'>
          <span>${rendererName}</span>
        </div>
      </div>`;
      svgAppend(parentNode, foreignObject);
      return parentNode;
    }
  }
};