index.jsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { Col, Image, Spin, Tooltip } from 'antd';
  2. import React, { useEffect, useState } from 'react';
  3. import { connect } from 'umi';
  4. import styles from './index.less';
  5. import { timeToString } from '@/utils/common';
  6. import {
  7. DislikeOutlined, LeftOutlined,
  8. LikeOutlined, RightOutlined,
  9. } from '@ant-design/icons';
  10. import { recurrent, severity, bug_categories } from '@/pages/edit/components/Step2/const';
  11. const BugItemDetail = (props) => {
  12. const {
  13. bugItemDetail, dispatch, reportCommonInfo, commonId,
  14. getReportReview,
  15. } = props;
  16. const [detail, setDetail] = useState({});
  17. const [operator, setOperator] = useState(-1);
  18. const handleChangeImgToLeft = () => {
  19. let newDetail = { ...detail };
  20. newDetail.left--;
  21. newDetail.right--;
  22. newDetail['imgArr'] = newDetail['originArr'].slice(newDetail['left'], newDetail['right']);
  23. setDetail(newDetail);
  24. };
  25. const handleChangeImgToRight = () => {
  26. let newDetail = { ...detail };
  27. newDetail.left++;
  28. newDetail.right++;
  29. newDetail['imgArr'] = newDetail['originArr'].slice(newDetail['left'], newDetail['right']);
  30. setDetail(newDetail);
  31. };
  32. const handleOperateIcon = (type) => {
  33. if (operator === -1) {
  34. //这里的操作是点赞点踩操作
  35. setOperator(type);
  36. if (type) {
  37. //type===1表示点赞
  38. dispatch({
  39. type: 'editReport/goodForReport',
  40. payload: {
  41. id: detail.id,//被点赞的报告的id
  42. report_id: reportCommonInfo.id,
  43. user_id: commonId.userId,
  44. action: 'like',
  45. },
  46. }).then(() => {
  47. getReportReview();
  48. });
  49. } else {
  50. dispatch({
  51. type: 'editReport/badForReport',
  52. payload: {
  53. id: detail.id,//被点赞的报告的id
  54. report_id: reportCommonInfo.id,
  55. user_id: commonId.userId,
  56. action: 'dislike',
  57. },
  58. }).then(() => {
  59. getReportReview();
  60. });
  61. }
  62. } else {
  63. //这里的操作是取消点赞点踩操作
  64. setOperator(-1);
  65. if (type) {
  66. //type===1表示点赞
  67. dispatch({
  68. type: 'editReport/cancelGoodForReport',
  69. payload: {
  70. id: detail.id,//被点赞的报告的id
  71. report_id: reportCommonInfo.id,
  72. },
  73. }).then(_ => {
  74. getReportReview();
  75. });
  76. } else {
  77. dispatch({
  78. type: 'editReport/cancelBadForReport',
  79. payload: {
  80. id: detail.id,//被点赞的报告的id
  81. report_id: reportCommonInfo.id,
  82. },
  83. }).then(_ => {
  84. getReportReview();
  85. });
  86. }
  87. }
  88. };
  89. useEffect(() => {
  90. if (JSON.stringify(bugItemDetail) !== '{}') {
  91. let { detail } = bugItemDetail;
  92. detail['originArr'] = detail.img_url ? detail.img_url.split(',') : [];
  93. if (detail['originArr'].length >= 3) {
  94. //通过更改左右的标记值来更改显示的图片
  95. detail['left'] = 0;
  96. detail['right'] = 3;
  97. detail['imgArr'] = detail['originArr'].slice(detail['left'], detail['right']);
  98. } else if (detail['originArr'].length > 0 && detail['originArr'].length < 3) {
  99. detail['imgArr'] = detail['originArr'];
  100. detail['left'] = 0;
  101. detail['right'] = detail['originArr'].length;
  102. }
  103. setDetail(detail);
  104. }
  105. }, [bugItemDetail]);
  106. return (
  107. detail && detail.id ?
  108. <div className={styles.bugItemDetail}>
  109. <div className={styles.detailItem}>
  110. <Tooltip title={detail.id}>
  111. <span className={styles.detailLabel}>Bug标识:</span>
  112. {detail && detail.id || ''}
  113. </Tooltip>
  114. </div>
  115. <div className={styles.detailItem}>
  116. <Tooltip title={detail.title}>
  117. <span className={styles.detailLabel}>Bug题目:</span>
  118. {detail && detail.title || ''}
  119. </Tooltip>
  120. </div>
  121. <div className={`${styles.detailItem} ${styles.detailItemDesc}`}>
  122. <Tooltip title={detail.description}>
  123. <span className={styles.detailLabel}>Bug描述:</span>
  124. {detail && detail.description+detail.description+detail.description}
  125. </Tooltip>
  126. </div>
  127. <div className={styles.detailItem}><span
  128. className={styles.detailLabel}>创建时间:</span>{timeToString(detail.create_time_millis)}</div>
  129. <div className={styles.detailItem}><span className={styles.detailLabel}>页面路径:</span>{detail.bug_page}
  130. </div>
  131. <div className={styles.detailItem}><span
  132. className={styles.detailLabel}>漏洞分类:</span>{detail.bug_category}</div>
  133. <div className={styles.detailItem}><span
  134. className={styles.detailLabel}>严重等级:</span>{severity[detail.severity - 1]}</div>
  135. <div className={styles.detailItem}><span
  136. className={styles.detailLabel}>复现程度:</span>{recurrent[detail.recurrent - 1]}</div>
  137. {
  138. detail && detail.img_url ? (
  139. <div className={`${styles.detailItem} ${styles.detailItemOperator}`}><span
  140. className={styles.detailLabel}>Bug截图:</span>
  141. <div span={12} className={styles.bugImgList}>
  142. {detail.left > 0 ? <LeftOutlined
  143. onClick={handleChangeImgToLeft} /> :
  144. <div className={styles.switchImgBtn}></div>}
  145. {detail.imgArr.map(img => {
  146. return <Image src={img} key={img} />;
  147. })}
  148. {detail.right < (detail.originArr.length - 1) ?
  149. <RightOutlined onClick={handleChangeImgToRight} /> :
  150. <div className={styles.switchImgBtn}></div>}
  151. </div>
  152. </div>)
  153. : null
  154. }
  155. <div className={`${styles.detailItem} ${styles.detailItemOperator}`}><span
  156. className={styles.detailLabel}>Bug评价:</span>
  157. {operator !== 0 ?
  158. <LikeOutlined className={`${styles.operatorIcon} ${operator === 1 ? styles.operatorIconActive : ''}`}
  159. onClick={() => handleOperateIcon(1)} /> : null}
  160. {operator !== 1 ?
  161. <DislikeOutlined className={`${styles.operatorIcon} ${operator === 0 ? styles.operatorIconActive : ''}`}
  162. onClick={() => handleOperateIcon(0)} /> : null}
  163. </div>
  164. </div> : <Spin />
  165. );
  166. };
  167. export default connect(({ allBugs, editReport }) => ({
  168. bugItemDetail: allBugs.bugItemDetail,
  169. reportCommonInfo: editReport.reportCommonInfo,
  170. commonId: editReport.commonId,
  171. }))(BugItemDetail);