AuditFlow.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import React, { useMemo, useEffect, useState, useRef } from 'react';
  2. import { Steps, Popover } from 'antd';
  3. import styles from './Index.less';
  4. import { queryDDProcessesForecast } from '@/services/boom';
  5. const { Step } = Steps;
  6. const ACTOR_TYPE = {
  7. approver: '审批人',
  8. notifier: '抄送人',
  9. audit: '办理人',
  10. };
  11. const APPROVAL_TYPE = {
  12. MANUAL: '人工审批',
  13. AUTO_AGREE: '自动通过',
  14. AUTO_REFUSE: '自动拒绝',
  15. };
  16. const APPROVAL_METHOD = {
  17. ONE_BY_ONE: '依次审批',
  18. AND: '会签审批',
  19. OR: '或签审批',
  20. };
  21. const ACTIVITY_TYPE = {
  22. target_select: '自选审批人',
  23. target_approval: '指定审批人',
  24. };
  25. function AuditFlow(props) {
  26. const {
  27. processCode,
  28. deptId = '14169890',
  29. userId = '16569001414345099',
  30. formComponentValues,
  31. activityId,
  32. direction,
  33. } = props;
  34. const [flow, setFlow] = useState({ workflowActivityRules: [] });
  35. const timerRef = useRef({
  36. id: '',
  37. status: false,
  38. });
  39. const current = useMemo(() => {
  40. if (!activityId) {
  41. return flow.workflowActivityRules.length;
  42. } else {
  43. return flow.workflowActivityRules.findIndex(item => item.activityId == activityId);
  44. }
  45. }, [activityId, flow]);
  46. const renderDesc = item => {
  47. return <></>;
  48. };
  49. const customDot = (dot, { status, index }) => {
  50. let item = flow.workflowActivityRules[index];
  51. return (
  52. <Popover
  53. content={
  54. <div>
  55. 节点类型:{ACTIVITY_TYPE[item.activityType]}
  56. <br />
  57. 操作人类型:{ACTOR_TYPE[item.workflowActor?.actorType]}
  58. <br />
  59. 审批类型:{APPROVAL_TYPE[item.workflowActor?.approvalType]}
  60. <br />
  61. 审批方式:{APPROVAL_METHOD[item.workflowActor?.approvalMethod]}
  62. </div>
  63. }
  64. >
  65. {dot}
  66. </Popover>
  67. );
  68. };
  69. const getDetail = async () => {
  70. if (!timerRef.current.status) {
  71. // 上锁
  72. timerRef.current.status = true;
  73. try {
  74. let flow = await queryDDProcessesForecast({
  75. processCode,
  76. deptId,
  77. userId,
  78. formComponentValues,
  79. });
  80. setFlow(flow);
  81. } catch (error) {}
  82. setTimeout(() => {
  83. // 延时解锁
  84. timerRef.current.status = false;
  85. }, 2000);
  86. } else {
  87. clearTimeout(timerRef.current.id);
  88. // 延迟调用
  89. timerRef.current.id = setTimeout(() => {
  90. getDetail();
  91. }, 2000);
  92. }
  93. };
  94. useEffect(() => {
  95. if (!processCode || !formComponentValues) return;
  96. getDetail();
  97. }, [processCode, formComponentValues]);
  98. return (
  99. <div className={styles.top}>
  100. <Steps current={current} progressDot={customDot} direction={direction}>
  101. {flow.workflowActivityRules.map(item => (
  102. <Step key={item.activityId} title={item?.activityName} />
  103. ))}
  104. {/* <Step key={item.activityId} title={item?.activityName} description={renderDesc(item)} /> */}
  105. </Steps>
  106. </div>
  107. );
  108. }
  109. export default AuditFlow;