index.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, { useEffect, useMemo } from 'react';
  2. judgeServe;
  3. import judgeServe, { ComponentName, FormItem, TYPE } from './mapServe';
  4. // import { Badge } from 'antd';
  5. import { useXFlowApp, XFlowNodeCommands } from '@antv/xflow';
  6. import { JudgeType, JudgeOptions, SiginOptions } from '../../components/judgeComponent';
  7. import { connect } from 'dva';
  8. export { judgeServe };
  9. const JudgeRect = props => {
  10. const { size = { width: 130, height: 50 }, data, depUserTree } = props;
  11. const { width, height } = size;
  12. const { label, stroke, fill, fontFill, fontSize, type, priority, formItems } = data;
  13. const contentText = useMemo(() => {
  14. let text = [];
  15. const getName = (id, data) => {
  16. let name = '';
  17. for (let i = 0; i < data.length; i++) {
  18. let item = data[i];
  19. if (item.ID == id) {
  20. return item.title;
  21. } else if (item.children?.length > 0) {
  22. let title = getName(id, item.children);
  23. if (title) return title;
  24. }
  25. }
  26. return name;
  27. };
  28. if (formItems) {
  29. let data: FormItem[] = JSON.parse(formItems);
  30. data.forEach((item: FormItem) => {
  31. let judge: JudgeType = item.judge;
  32. const label: String = item.props.label;
  33. switch (judge?.type) {
  34. case ComponentName.Inner:
  35. const list = judge?.values
  36. .map(item => {
  37. return getName(item.value, depUserTree);
  38. })
  39. .filter(item => item);
  40. text.push('发起人属于:' + list.join('或'));
  41. break;
  42. case ComponentName.Number:
  43. const type: Number = judge.values[0];
  44. const condition = judge.condition;
  45. if (!condition) break;
  46. if (type != 6) {
  47. let JudgeLabel = JudgeOptions.find(item => item.value == type)?.label;
  48. text.push(`${label} ${JudgeLabel} ${condition.smallValue}`);
  49. } else {
  50. const { smallSign, smallValue, bigSign, bigValue } = condition;
  51. if (!smallSign || !smallValue || !bigSign || !bigValue) break;
  52. const getSigin = (sigin: Number) =>
  53. SiginOptions.find(item => item.value == sigin)?.label;
  54. text.push(
  55. `${smallValue} ${getSigin(smallSign)} ${label} ${getSigin(bigSign)} ${bigValue} `
  56. );
  57. }
  58. break;
  59. case ComponentName.Select:
  60. case ComponentName.MultiSelect:
  61. const values = judge.values;
  62. text.push(`${label} ${values.join(' 或 ')}`);
  63. break;
  64. }
  65. });
  66. }
  67. return text;
  68. }, [formItems]);
  69. return (
  70. <div
  71. style={{
  72. width,
  73. height,
  74. padding: '6px',
  75. boxShadow: '0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)',
  76. }}
  77. >
  78. <span style={{ color: '##7E8185', float: 'right', fontSize: '8px' }}>优先级{priority}</span>
  79. <div style={{ color: '#15BC83' }}>{label}</div>
  80. <div
  81. style={{
  82. height: `${height - 32}px`,
  83. overflow: 'hidden',
  84. textOverflow: 'ellipsis',
  85. }}
  86. >
  87. {(contentText || []).map((text, index) => (
  88. <>
  89. {index != 0 && (
  90. <>
  91. <br />
  92. 并且
  93. <br />
  94. </>
  95. )}
  96. {text}
  97. </>
  98. ))}
  99. </div>
  100. </div>
  101. );
  102. };
  103. export default connect(({ flow }) => ({
  104. depUserTree: flow.depUserTree,
  105. }))(JudgeRect);
  106. const enum COLOR {
  107. AUDIT = '#FF943E',
  108. INITIATOR = '#576A95',
  109. COPYMAN = '#3296FA',
  110. }
  111. const enum TITLETEXT {
  112. AUDIT = '审批人',
  113. INITIATOR = '发起人',
  114. COPYMAN = '抄送人',
  115. }