index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import PageContent from '@/components/PageContent';
  2. import PageTitle from '@/components/PageTitle';
  3. import { GetTokenFromUrl, UnityAction } from '@/utils/utils';
  4. import { DiffFilled, FundFilled } from '@ant-design/icons';
  5. import { connect, history, useLocation, useParams } from '@umijs/max';
  6. import { Button, Form, Modal, Select, Spin, message } from 'antd';
  7. import dayjs from 'dayjs';
  8. import { useEffect, useState } from 'react';
  9. import styles from './index.less';
  10. const EqSelfInspection = (props) => {
  11. const { dispatch, autoReport, patrolList, loading } = props;
  12. const { projectId } = useParams();
  13. const { routeId } = useLocation();
  14. const [form] = Form.useForm();
  15. const [visible, setVisible] = useState(false);
  16. // 0 正常 1 异常 2 loading
  17. const [patrolStatus, setPatrolStatus] = useState(0);
  18. const [faultAnalysisStatus, setFaultAnalysisStatus] = useState(0);
  19. const [secureStatus, setSecureStatus] = useState(0);
  20. const [secureChildren, setSecureChildren] = useState([]);
  21. const getDate = () => {
  22. dispatch({
  23. type: 'eqSelfInspection/getAutoPatrol',
  24. payload: {
  25. projectId,
  26. },
  27. });
  28. };
  29. const HandleInspection = () => {
  30. if (patrolList?.length === 0) {
  31. message.error('请配置巡检路线!');
  32. } else {
  33. UnityAction.sendMsg('StartInspection', '');
  34. dispatch({
  35. type: 'eqSelfInspection/getAutoPatrol',
  36. payload: { projectId },
  37. callback: (data) => {
  38. setPatrolStatus(data?.patrolStatus);
  39. setFaultAnalysisStatus(data?.faultAnalysisStatus);
  40. setSecureStatus(data?.secureStatus);
  41. setSecureChildren(data?.secureChild);
  42. history.replace(`/self-inspection/${projectId}?routeId=${data.Id}`);
  43. },
  44. });
  45. }
  46. };
  47. const handleOk = () => {
  48. UnityAction.sendMsg('StartInspection', '');
  49. form.validateFields((err, values) => {
  50. if (err) return;
  51. dispatch({
  52. type: 'eqSelfInspection/inspectionRoute',
  53. payload: { projectId, routeId: values.routeId },
  54. callback: (data) => {
  55. setPatrolStatus(data?.patrolStatus);
  56. setFaultAnalysisStatus(data?.faultAnalysisStatus);
  57. setSecureStatus(data?.secureStatus);
  58. setSecureChildren(data?.secureChild);
  59. history.replace(`/self-inspection/${projectId}?routeId=${data.Id}`);
  60. },
  61. });
  62. });
  63. handleCancel();
  64. setPatrolStatus(2);
  65. setSecureStatus(2);
  66. setFaultAnalysisStatus(2);
  67. };
  68. const handleCancel = () => {
  69. setVisible(false);
  70. form.resetFields();
  71. };
  72. useEffect(() => {
  73. if (routeId) {
  74. dispatch({
  75. type: 'eqSelfInspection/getPatrolDataById',
  76. payload: {
  77. routeId: routeId,
  78. },
  79. });
  80. } else if (autoReport.Id) {
  81. dispatch({
  82. type: 'eqSelfInspection/getPatrolDataById',
  83. payload: {
  84. routeId: autoReport.Id,
  85. },
  86. });
  87. } else {
  88. getDate();
  89. }
  90. dispatch({
  91. type: 'eqSelfInspection/getList',
  92. payload: {
  93. ProjectId: projectId * 1,
  94. },
  95. });
  96. }, []);
  97. useEffect(() => {
  98. setPatrolStatus(autoReport?.patrolStatus);
  99. setFaultAnalysisStatus(autoReport?.faultAnalysisStatus);
  100. setSecureStatus(autoReport?.secureStatus);
  101. setSecureChildren(autoReport?.secureChild);
  102. }, [autoReport]);
  103. return (
  104. <PageContent>
  105. <PageTitle>系统自检</PageTitle>
  106. <Spin spinning={loading} tip="正在自检中...">
  107. <div className={`${styles.itemMain} card-box`} style={{ padding: 20 }}>
  108. <div style={{ position: 'relative', display: 'flex' }}>
  109. <div style={{ fontSize: 24 }}>
  110. 自检间隔:{autoReport?.RouteInfo?.PlanDur}h
  111. </div>
  112. <div className={styles.icon}>
  113. <DiffFilled
  114. style={{ cursor: 'pointer', marginRight: 20 }}
  115. onClick={() => {
  116. history.push(
  117. `/self-inspection/list/${projectId}`,
  118. );
  119. }}
  120. />
  121. <FundFilled
  122. onClick={() => {
  123. history.push(
  124. `/self-inspection/statistics/${projectId}?JWT-TOKEN=${GetTokenFromUrl()}`,
  125. );
  126. }}
  127. />
  128. </div>
  129. </div>
  130. <div className={styles.logoInfo}>
  131. <div className={styles.logo} />
  132. <div style={{ display: 'flex', fontSize: 20 }}>
  133. <div>系统自检发现</div>
  134. <div
  135. style={{
  136. color: autoReport?.warningTotalNum === 0 ? '#333' : '#FE5850',
  137. margin: '0 6px 0 6px',
  138. }}
  139. >
  140. {autoReport?.warningTotalNum === 0
  141. ? '暂无'
  142. : autoReport?.warningTotalNum || 0}
  143. </div>
  144. <div>项异常</div>
  145. </div>
  146. <div style={{ fontSize: 20 }}>
  147. {autoReport?.CreatedTime
  148. ? dayjs(autoReport?.CreatedTime).format('YYYY-MM-DD HH:mm')
  149. : ''}
  150. </div>
  151. <div className={styles.insbtn}>
  152. <Button type="primary" onClick={HandleInspection}>
  153. 一键自检
  154. </Button>
  155. <div
  156. style={{
  157. position: 'absolute',
  158. display: 'flex',
  159. alignItems: 'flex-end',
  160. right: 0,
  161. height: '100%',
  162. }}
  163. >
  164. <div>系统自检中</div>
  165. </div>
  166. </div>
  167. </div>
  168. </div>
  169. <Item name="设备自检" status={patrolStatus}></Item>
  170. <Item name="工艺自检" status={faultAnalysisStatus}></Item>
  171. <Item
  172. name="安全自检"
  173. warningText={
  174. secureStatus === 1
  175. ? `共发现${
  176. secureChildren?.filter((item) => item.status === 1)?.length ||
  177. 0
  178. }项异常`
  179. : ''
  180. }
  181. status={secureStatus}
  182. >
  183. {secureChildren?.map((item) => (
  184. <WarningItem label={item.label} status={item.status} />
  185. ))}
  186. </Item>
  187. <div className={styles.reportBtn}>
  188. <Button
  189. type="primary"
  190. onClick={() => {
  191. history.push(
  192. `/self-inspection/detail/${projectId}/${
  193. autoReport?.Id
  194. }?JWT-TOKEN=${GetTokenFromUrl()}`,
  195. );
  196. }}
  197. >
  198. 查看自检报告
  199. </Button>
  200. </div>
  201. <Modal
  202. title="选择巡检路线"
  203. destroyOnClose
  204. open={visible}
  205. onOk={handleOk}
  206. width="40%"
  207. maskClosable={false}
  208. onCancel={handleCancel}
  209. >
  210. <Form form={form} labelCol={{ span: 5 }} wrapperCol={{ span: 15 }}>
  211. <Form.Item
  212. label="巡检路线"
  213. name="routeId"
  214. rules={[
  215. {
  216. required: true,
  217. message: '请选择巡检路线',
  218. },
  219. ]}
  220. >
  221. <Select placeholder="请选择巡检路线">
  222. {patrolList?.map((item) => (
  223. <Option key={item.Id} value={item.Id}>
  224. {item?.Name}
  225. </Option>
  226. ))}
  227. </Select>
  228. </Form.Item>
  229. </Form>
  230. </Modal>
  231. </Spin>
  232. </PageContent>
  233. );
  234. };
  235. export default connect(({ eqSelfInspection, loading }) => ({
  236. autoReport: eqSelfInspection.autoReport,
  237. patrolList: eqSelfInspection.patrolList,
  238. loading: loading.models['eqSelfInspection'],
  239. }))(EqSelfInspection);
  240. const Item = (props) => {
  241. const { name, children, warningText = '', status = 0 } = props;
  242. const renderRight = (status) => {
  243. switch (status) {
  244. case 0:
  245. return (
  246. <div className={styles.right} style={{ color: '#52c41a' }}>
  247. 正常
  248. </div>
  249. );
  250. case 1:
  251. return (
  252. <div className={styles.right} style={{ color: '#FE5850' }}>
  253. 异常
  254. </div>
  255. );
  256. case 2:
  257. return;
  258. // return <SyncOutlined className={styles.right} spin />;
  259. default:
  260. return (
  261. <div className={styles.right} style={{ color: '#52c41a' }}>
  262. 正常
  263. </div>
  264. );
  265. }
  266. };
  267. return (
  268. <div
  269. className={`${styles.itemMain} card-box`}
  270. style={{
  271. paddingBottom: children ? 20 : 0,
  272. }}
  273. >
  274. <div className={styles.item}>
  275. <span>{name}</span>
  276. <span className={styles.warningText}>{warningText}</span>
  277. {renderRight(status)}
  278. </div>
  279. {children}
  280. </div>
  281. );
  282. };
  283. const WarningItem = (props) => {
  284. const { label, status } = props;
  285. return (
  286. <div className={styles.warningItem}>
  287. <span>{label}</span>
  288. <div
  289. style={{
  290. color: status === 1 ? '#FE5850' : '#52c41a',
  291. fontSize: 20,
  292. position: 'absolute',
  293. right: 20,
  294. }}
  295. >
  296. {status === 0 ? '正常' : '异常'}
  297. </div>
  298. </div>
  299. );
  300. };