index.tsx 3.8 KB

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