index.tsx 4.3 KB

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