TimeNode.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import React, {useEffect, useState, useRef} from 'react';
  2. import {Form} from '@ant-design/compatible';
  3. import '@ant-design/compatible/assets/index.css';
  4. import {connect} from 'dva';
  5. import {Steps, Button, Modal, Tooltip} from 'antd';
  6. import styles from './Index.less';
  7. import {getCurrentUser} from '@/utils/authority';
  8. const {Step} = Steps;
  9. // 时间节点
  10. function TimeNode(props) {
  11. const {
  12. isAuditor,
  13. flowDetail,
  14. style,
  15. flow,
  16. versionList,
  17. version,
  18. templateId,
  19. setAuditVisible,
  20. projectId,
  21. dispatch,
  22. stepDirection,
  23. currentUser,
  24. } = props;
  25. const {current, list, active} = flow;
  26. console.log(list.FlowNodes)
  27. function calculateHoursDifference(date1, date2) {
  28. const timestamp1 = date1.getTime(); // 获取第一个Date对象的时间戳(以毫秒为单位)
  29. const timestamp2 = date2.getTime(); // 获取第二个Date对象的时间戳(以毫秒为单位)
  30. const timeDifferenceInMillis = Math.abs(timestamp2 - timestamp1); // 计算时间戳之间的差值(毫秒数)
  31. const hoursDifference = timeDifferenceInMillis / (1000 * 60 * 60); // 将差值转换为小时数
  32. return hoursDifference.toFixed(2);
  33. }
  34. const getDescription = (node, prevNode) => {
  35. let str = node?.AuditRoleInfo
  36. ? `审批人:${node?.AuditRoleInfo.Name || '-'}`
  37. : `审批人:${node?.AuditorUser.CName || '-'}`;
  38. const date = new Date(node.audit_time)
  39. const auditTime = node.audit_time === '0001-01-01T00:00:00Z' ? '-' : date.toLocaleDateString('zh-CN', {
  40. format: 'YYYY-MM-DD hh:mm:ss'
  41. })
  42. // const residenceTime = auditTime === '-' ? '-' : calculateHoursDifference(date, new Date(prevNode.audit_time))
  43. return (
  44. <div>
  45. {str}
  46. <div>
  47. <span style={{color: '#1A73E8', textDecoration: 'undeline'}}>
  48. 审批意见:{node.desc || '-'}
  49. </span>
  50. </div>
  51. <div>
  52. <span>
  53. 审批时间:{auditTime}
  54. </span>
  55. </div>
  56. {/* <div> */}
  57. {/* <span> */}
  58. {/* 滞留时间:{`${residenceTime}小时`} */}
  59. {/* </span> */}
  60. {/* </div> */}
  61. </div>
  62. );
  63. // return str;
  64. };
  65. if (!list || list.FlowNodes?.length != 0) {
  66. return (
  67. <div style={style}>
  68. <Steps
  69. direction={stepDirection || 'horizontal'}
  70. current={current}
  71. status={active == 0 ? 'error' : 'process'}
  72. >
  73. {list.FlowNodes.map(( item) => {
  74. return <Step key={item.id} title={item.node} description={getDescription(item)} />
  75. })}
  76. </Steps>
  77. {isAuditor && active != 0 && (
  78. <div className={styles.btns} style={{margin: '40px 0'}}>
  79. <Button type="primary" onClick={() => setAuditVisible(1)}>
  80. 审批通过
  81. </Button>
  82. <Button onClick={() => setAuditVisible(2)} danger>
  83. 审批拒绝
  84. </Button>
  85. </div>
  86. )}
  87. </div>
  88. );
  89. }
  90. // else {
  91. // if (!flowDetail?.nodes) return;
  92. // const node = flowDetail.nodes.find(item => item.Id == nodeId);
  93. // return `当前节点:${node?.label || '-'}`;
  94. // }
  95. return null;
  96. }
  97. export default connect(({user, detail}) => ({
  98. currentUser: user.currentUser,
  99. versionList: detail.versionList,
  100. }))(TimeNode);