index.js 9.9 KB

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