CustomizeRenderer.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import { changeTypeByTaskShape, typeConfig } from '../../config';
  2. import { append as svgAppend, create as svgCreate } from 'tiny-svg';
  3. import {
  4. bpmnEnd,
  5. bpmnExecute,
  6. bpmnGroup,
  7. bpmnLabel,
  8. bpmnOutside,
  9. bpmnProcessing,
  10. bpmnStart,
  11. bpmnSubFlow,
  12. bpmnTask,
  13. bpmnTrigger,
  14. typeExecute,
  15. typeOutside,
  16. typeProcessing,
  17. typeSubFlow,
  18. typeTrigger,
  19. } from '../../config/variableName';
  20. /**
  21. * svg重画bpmn节点
  22. */
  23. export default (parentNode: any, element: any, jnpfFlowInfo: any, injector: any) => {
  24. let data = jnpfFlowInfo?.flowNodes[element.id];
  25. let nodeMap = jnpfFlowInfo?.nodeList;
  26. let isPreview = jnpfFlowInfo?.isPreview;
  27. let type = element.type; // 获取到类型
  28. if (typeConfig && typeConfig[type]) {
  29. if (type === bpmnGroup) return null;
  30. if (data?.type === typeSubFlow || element.wnType === typeSubFlow) type = bpmnSubFlow;
  31. if (data?.type === typeProcessing || element.wnType === typeProcessing) type = bpmnProcessing;
  32. if (data?.type === typeTrigger || element.wnType === typeTrigger) type = bpmnTrigger;
  33. if (data?.type === typeExecute || element.wnType === typeExecute) type = bpmnExecute;
  34. if (data?.type === typeOutside || element.wnType === typeOutside) type = bpmnOutside;
  35. if (changeTypeByTaskShape[data?.type] || changeTypeByTaskShape[element?.wnType]) type = changeTypeByTaskShape[element?.wnType || data?.type];
  36. let { renderer } = typeConfig[type];
  37. let { icon, iconColor, rendererName, background, titleColor, attr, bodyDefaultText } = renderer;
  38. // 直接修改元素的宽高
  39. element['width'] = type === bpmnLabel ? 128 : attr.width;
  40. element['height'] = type === bpmnLabel ? 28 : attr.height;
  41. let nodeName = element.nodeName != null ? element.nodeName : data?.nodeName != null ? data.nodeName : rendererName;
  42. let nodeContent = element.elementBodyName || nodeMap.get(element.id)?.userName || data?.content || bodyDefaultText;
  43. if (isPreview) {
  44. if (nodeMap.get(element.id)?.type) {
  45. if (nodeMap.get(element.id)?.type === '0') {
  46. titleColor = 'linear-gradient(90deg, #AEEFC2 0%, #4ED587 100%)';
  47. iconColor = '#25a210';
  48. }
  49. if (nodeMap.get(element.id)?.type === '1') {
  50. titleColor = 'linear-gradient(90deg, #C0EDF8 0%, #A6DEF8 100%)';
  51. iconColor = '#1eaceb';
  52. }
  53. if (nodeMap.get(element.id)?.type === '3') {
  54. titleColor = 'linear-gradient(90deg, #FDC9D1 0%,#E03845 100%)';
  55. iconColor = '#E03845';
  56. }
  57. } else {
  58. titleColor = 'linear-gradient(90deg, #CED1D5 0%, #CBCBCC 100%);';
  59. iconColor = '#4c4c58';
  60. }
  61. }
  62. let foreignObject: any = svgCreate('foreignObject', {
  63. width: type === bpmnLabel ? 128 : attr.width,
  64. height: type === bpmnLabel ? 28 : attr.height,
  65. class: type === bpmnStart || type === bpmnEnd ? 'begin-or-end-node' : 'task-node',
  66. });
  67. // 开始节点
  68. if (type === bpmnStart) {
  69. foreignObject.innerHTML = `
  70. <div class="node-container start-node-container" style="background:${background}" >
  71. <div class='node-top-container'>
  72. <i class="${icon}" style="color:${iconColor}"></i>
  73. <span>${nodeName}</span>
  74. </div>
  75. </div>`;
  76. svgAppend(parentNode, foreignObject);
  77. return parentNode;
  78. }
  79. // 审批节点
  80. if (type === bpmnTask) {
  81. foreignObject.innerHTML = `
  82. <div class="node-container" style="background:${background}" >
  83. <div class='node-top-container' style="background:${titleColor};">
  84. <i class="${icon}" style="color:${iconColor}"></i>
  85. <span>${nodeName}</span>
  86. </div>
  87. <div class='node-bottom-container'>
  88. <span>${nodeContent}</span>
  89. </div>
  90. </div>`;
  91. svgAppend(parentNode, foreignObject);
  92. return parentNode;
  93. }
  94. // 子流程节点
  95. if (type === bpmnSubFlow || type === bpmnProcessing || type === bpmnTrigger || changeTypeByTaskShape[element?.wnType || data?.type]) {
  96. foreignObject.innerHTML = `
  97. <div class="node-container" style="background:${background}" >
  98. <div class='node-top-container' style="background:${titleColor}">
  99. <i class="${icon}" style="color:${iconColor}"></i>
  100. <span>${nodeName}</span>
  101. </div>
  102. <div class='node-bottom-container'>
  103. <span>${nodeContent}</span>
  104. </div>
  105. </div>`;
  106. svgAppend(parentNode, foreignObject);
  107. return parentNode;
  108. }
  109. // 结束节点
  110. if (type === bpmnEnd) {
  111. foreignObject.innerHTML = `
  112. <div class="node-container end-node-container" style="background:${background}" >
  113. <div class='node-top-container'>
  114. <i class="${icon}" style="color:${iconColor}"></i>
  115. <span>${nodeName}</span>
  116. </div>
  117. </div>`;
  118. svgAppend(parentNode, foreignObject);
  119. return parentNode;
  120. }
  121. // label渲染
  122. if (type === bpmnLabel) {
  123. let jnpfData = injector?.get('jnpfData');
  124. let data = jnpfData.getValue('global');
  125. let connectName = jnpfData.getValue(element.id.replace('_label', ''))?.nodeName || '连接线';
  126. if (data.isShowConditions) {
  127. let foreignObject: any = svgCreate('foreignObject', {
  128. width: 128,
  129. height: 28,
  130. class: 'label-node',
  131. });
  132. foreignObject.innerHTML = `
  133. <div class="node-container-label" >
  134. <div class='node-top-container'>
  135. <span> ${data.showNameType === 1 ? element.text : connectName}</span>
  136. </div>
  137. </div>`;
  138. element.text && svgAppend(parentNode, foreignObject);
  139. return parentNode;
  140. }
  141. return null;
  142. }
  143. }
  144. };