index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. import PageContent from '@/components/PageContent';
  2. import PageTitle from '@/components/PageTitle';
  3. import { getMandateIDs } from '@/services/eqSelfInspection';
  4. import { GetTokenFromUrl, UnityAction } from '@/utils/utils';
  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. const openTaskModal = async () => {
  73. if (!autoReport.Id) {
  74. return;
  75. }
  76. let mandateIDs = await getMandateIDs({
  77. project_id: projectId,
  78. id: autoReport.Id,
  79. }).catch((err) => {
  80. console.log(err);
  81. });
  82. if (mandateIDs?.length) {
  83. mandateIDs = [...new Set(mandateIDs)];
  84. UnityAction.sendMsg('OpenTaskModal', `mandate_id=${mandateIDs.join()}`);
  85. } else {
  86. message.info('未查询到相关任务');
  87. }
  88. };
  89. //消息跳转过来近具体自检报告详情页面
  90. const handleJumpDetail = (id) => {
  91. history.push(
  92. `/self-inspection/detail/${projectId}/${id}?JWT-TOKEN=${GetTokenFromUrl()}`,
  93. );
  94. };
  95. useEffect(() => {
  96. if (routeId) {
  97. dispatch({
  98. type: 'eqSelfInspection/getPatrolDataById',
  99. payload: {
  100. routeId: routeId,
  101. },
  102. });
  103. } else {
  104. getDate();
  105. }
  106. dispatch({
  107. type: 'eqSelfInspection/getList',
  108. payload: {
  109. ProjectId: projectId * 1,
  110. },
  111. });
  112. UnityAction.on('notiZiJian', (id) => {
  113. handleJumpDetail(id);
  114. });
  115. return UnityAction.off('notiZiJian');
  116. }, []);
  117. useEffect(() => {
  118. setPatrolStatus(autoReport?.patrolStatus);
  119. setFaultAnalysisStatus(autoReport?.faultAnalysisStatus);
  120. setSecureStatus(autoReport?.secureStatus);
  121. setSecureChildren(autoReport?.secureChild);
  122. }, [autoReport]);
  123. return (
  124. <PageContent>
  125. <PageTitle>系统自检</PageTitle>
  126. <Spin spinning={loading} tip="正在自检中...">
  127. <div className="content-title">
  128. <div
  129. className={`${styles.itemMain} card-box`}
  130. style={{ padding: '0.2rem 0.24rem', position: 'relative' }}
  131. >
  132. <div style={{ fontSize: '0.28rem', color: 'rgb(110, 110, 110)' }}>
  133. 自检间隔:{autoReport?.RouteInfo?.PlanDur}分钟
  134. </div>
  135. <div className={styles.icon}>
  136. <div
  137. className={styles.iconDiffFilled}
  138. onClick={() => {
  139. history.push(`/self-inspection/list/${projectId}`);
  140. }}
  141. ></div>
  142. <div
  143. className={styles.iconFundFilled}
  144. onClick={() => {
  145. history.push(
  146. `/self-inspection/statistics/${projectId}?JWT-TOKEN=${GetTokenFromUrl()}`,
  147. );
  148. }}
  149. ></div>
  150. </div>
  151. <div className={styles.logoInfo}>
  152. <div className={styles.logo} />
  153. <div className={styles.logoTitle}>
  154. <div>
  155. 系统自检&nbsp;
  156. {autoReport?.Status == 0 ? (
  157. <span style={{ color: '#39CA74' }}>正常</span>
  158. ) : (
  159. <span style={{ color: 'rgba(254, 88, 80, 1)' }}>异常</span>
  160. )}
  161. </div>
  162. </div>
  163. <div className={styles.logoTime}>
  164. {autoReport?.CreatedTime
  165. ? dayjs(autoReport?.CreatedTime).format('YYYY-MM-DD HH:mm')
  166. : ''}
  167. </div>
  168. <div className={styles.insbtn}>
  169. <Button type="primary" onClick={HandleInspection}>
  170. 一键自检
  171. </Button>
  172. </div>
  173. <div className={styles.logoFont}>系统自检中</div>
  174. </div>
  175. </div>
  176. <Item name="设备自检" status={patrolStatus}></Item>
  177. <Item name="工艺自检" status={faultAnalysisStatus}></Item>
  178. <Item name="安全自检" status={secureStatus}>
  179. {secureChildren?.map((item, index) => (
  180. <WarningItem
  181. key={index}
  182. label={item.label}
  183. status={item.status}
  184. />
  185. ))}
  186. </Item>
  187. <div
  188. className={styles.btnContainer}
  189. style={{
  190. justifyContent:
  191. autoReport?.Status == 0 ? 'center' : 'space-between',
  192. }}
  193. >
  194. {autoReport?.Status != 0 && (
  195. <Button
  196. className={styles.reportBtn}
  197. type="primary"
  198. onClick={() => {
  199. openTaskModal();
  200. }}
  201. >
  202. 查看任务
  203. </Button>
  204. )}
  205. <Button
  206. className={styles.reportBtn}
  207. type="primary"
  208. onClick={() => {
  209. history.push(
  210. `/self-inspection/detail/${projectId}/${
  211. autoReport?.Id
  212. }?JWT-TOKEN=${GetTokenFromUrl()}`,
  213. );
  214. }}
  215. >
  216. 查看自检报告
  217. </Button>
  218. </div>
  219. <Modal
  220. title="选择巡检路线"
  221. destroyOnClose
  222. open={visible}
  223. onOk={handleOk}
  224. width="40%"
  225. maskClosable={false}
  226. onCancel={handleCancel}
  227. >
  228. <Form form={form} labelCol={{ span: 5 }} wrapperCol={{ span: 15 }}>
  229. <Form.Item
  230. label="巡检路线"
  231. name="routeId"
  232. rules={[
  233. {
  234. required: true,
  235. message: '请选择巡检路线',
  236. },
  237. ]}
  238. >
  239. <Select placeholder="请选择巡检路线">
  240. {patrolList?.map((item) => (
  241. <Option key={item.Id} value={item.Id}>
  242. {item?.Name}
  243. </Option>
  244. ))}
  245. </Select>
  246. </Form.Item>
  247. </Form>
  248. </Modal>
  249. </div>
  250. </Spin>
  251. </PageContent>
  252. );
  253. };
  254. export default connect(({ eqSelfInspection, loading }) => ({
  255. autoReport: eqSelfInspection.autoReport,
  256. patrolList: eqSelfInspection.patrolList,
  257. loading: loading.models['eqSelfInspection'],
  258. }))(EqSelfInspection);
  259. const Item = (props) => {
  260. const { name, children, warningText = '', status = 0 } = props;
  261. const renderRight = (status) => {
  262. switch (status) {
  263. case 0:
  264. return <div className={`${styles.iconSuccess} ${styles.right}`}></div>;
  265. case 1:
  266. return (
  267. <div className={styles.right} style={{ color: '#FE5850' }}>
  268. 异常
  269. </div>
  270. );
  271. case 2:
  272. return (
  273. <div className={styles.right} style={{ color: '#FFE26D' }}>
  274. 警告
  275. </div>
  276. );
  277. // return <SyncOutlined className={styles.right} spin />;
  278. default:
  279. return <div className={`${styles.iconSuccess} ${styles.right}`}></div>;
  280. }
  281. };
  282. return (
  283. <div className={`${styles.itemMain} card-box`}>
  284. <div className={styles.item} style={{ height: children ? '0.8rem' : '' }}>
  285. <span className={styles.itemName}>{name}</span>
  286. {/* <span className={styles.warningText}>{warningText}</span> */}
  287. {renderRight(status)}
  288. </div>
  289. {children}
  290. </div>
  291. );
  292. };
  293. const WarningItem = (props) => {
  294. const { label, status } = props;
  295. return (
  296. <div className={styles.warningItem}>
  297. <span>{label}</span>
  298. {status === 0 ? (
  299. <div className={styles.iconSuccess}></div>
  300. ) : (
  301. <span
  302. style={{
  303. color: '#FE5850',
  304. }}
  305. >
  306. 异常
  307. </span>
  308. )}
  309. </div>
  310. );
  311. };