detail.jsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import React, {
  2. useEffect,
  3. useState,
  4. forwardRef,
  5. useImperativeHandle,
  6. } from "react";
  7. import { Form, Input, Select, message, Switch, Space, Col, Tabs } from "antd";
  8. import { Modal, Button, Radio } from "antd";
  9. import styles from "./detail.module.less";
  10. import API from "../../../api/alarm";
  11. import { useMemoizedFn } from "ahooks";
  12. import { CloseOutlined } from "@ant-design/icons";
  13. import _ from "lodash";
  14. import AlarmHistory from "./components/AlarmHistory";
  15. import AlarmDetail from "./components/AlarmDetail";
  16. import AlarmConfirm from "./components/AlarmConfirm";
  17. // import { AlarmConfig } from "./components/AlarmConfig";
  18. const Detail = (props) => {
  19. const { options, isDiagram } = props;
  20. const [tags, setTags] = useState([]);
  21. const [current, setCurrent] = useState("history");
  22. const [ruleId, setRuleId] = useState(undefined);
  23. const [showConfirm, setShowConfirm] = useState(false);
  24. // const [showAlarmConfig, setShowAlarmConfig] = useState(false);
  25. const getRuleIdByPointId = useMemoizedFn(async (ruleId, pointId) => {
  26. const ids = [];
  27. if (options.pointId) {
  28. const res = await API.getRuleIdByPointId(pointId);
  29. ids.push(res?.data?.[0]?.id);
  30. }
  31. if (options.ruleId) {
  32. ids.push(ruleId);
  33. }
  34. setRuleId(ids);
  35. setCurrent("history");
  36. setTags([]);
  37. });
  38. useEffect(() => {
  39. if (options.group) {
  40. setCurrent("history");
  41. setTags([]);
  42. setRuleId(undefined);
  43. } else if (options.ruleId || options.pointId) {
  44. getRuleIdByPointId(options.ruleId, options.pointId);
  45. } else if (options.detail) {
  46. setRuleId([options.detail.rule_id]);
  47. setTags([
  48. {
  49. id: options.detail.id,
  50. data: options.detail,
  51. },
  52. ]);
  53. setCurrent(options.detail.id);
  54. }
  55. }, [
  56. options.detail,
  57. options.ruleId,
  58. options.pointId,
  59. options.group,
  60. getRuleIdByPointId,
  61. ]);
  62. const currentData = tags.find((item) => item.id === current) ?? {};
  63. const onRemove = (index) => {
  64. const newTags = _.cloneDeep(tags);
  65. newTags.splice(index, 1);
  66. setTags(newTags);
  67. };
  68. const onSelect = (record) => {
  69. if (!tags.some((item) => item.id === record.id)) {
  70. const newTags = _.cloneDeep(tags);
  71. newTags.push({
  72. id: record.id,
  73. data: record,
  74. });
  75. setTags(newTags);
  76. }
  77. setCurrent(record.id);
  78. };
  79. const onAlarmConfirm = (newRecord) => {
  80. if (newRecord) {
  81. const newTags = _.clone(tags);
  82. const currentIndex = newTags.findIndex((item) => item.id === current);
  83. newTags[currentIndex].data = newRecord;
  84. setTags(newTags);
  85. }
  86. };
  87. return (
  88. <>
  89. <Modal
  90. title="告警记录"
  91. centered
  92. open={props.open}
  93. width="90vw"
  94. onCancel={() => {
  95. props.onCancel();
  96. }}
  97. zIndex="1001"
  98. footer={null}
  99. destroyOnClose
  100. bodyStyle={{
  101. height: "calc(80vh - 80px)",
  102. display: "flex",
  103. flexDirection: "column",
  104. }}
  105. >
  106. {props.open && (
  107. <>
  108. <div className={styles.header}>
  109. <div
  110. className={`${styles.tags} ${
  111. current !== "history" || props.noSettings
  112. ? styles.nobutton
  113. : ""
  114. }`}
  115. >
  116. <Tabs
  117. hideAdd
  118. onChange={(value) => {
  119. setCurrent(value === "history" ? value : Number(value));
  120. }}
  121. activeKey={current}
  122. type="card"
  123. items={[
  124. { label: "告警记录", children: null, key: "history" },
  125. ...tags.map((item, index) => ({
  126. label: (
  127. <div className={styles.tagContainer}>
  128. <div className={styles.label}>详情{index + 1}</div>
  129. <CloseOutlined
  130. style={{ fontSize: 10 }}
  131. onClick={(e) => {
  132. e.stopPropagation();
  133. if (current === item.id) {
  134. setCurrent("history");
  135. }
  136. onRemove(index);
  137. }}
  138. />
  139. </div>
  140. ),
  141. children: null,
  142. key: item.id,
  143. })),
  144. ]}
  145. />
  146. {/* <Radio.Group
  147. value={current}
  148. onChange={(e) => setCurrent(e.target.value)}
  149. size="middle"
  150. >
  151. <Radio.Button value="history">告警记录</Radio.Button>
  152. {tags.map((item, index) => (
  153. <Radio.Button value={item.id}>
  154. <div className={styles.tagContainer}>
  155. <div className={styles.label}>详情{index + 1}</div>
  156. <CloseOutlined
  157. style={{ fontSize: 10 }}
  158. onClick={() => {
  159. if (current === item.id) {
  160. setCurrent("history");
  161. }
  162. onRemove(index);
  163. }}
  164. />
  165. </div>
  166. </Radio.Button>
  167. ))}
  168. </Radio.Group> */}
  169. </div>
  170. <div className={styles.oper}>
  171. {/* {current !== "history" && (
  172. <Button
  173. disabled={currentData?.data?.op_status === 1}
  174. onClick={() => setShowConfirm(true)}
  175. >
  176. {currentData?.data?.op_status === 1 ? "已确认" : "确认"}
  177. </Button>
  178. )} */}
  179. {current === "history" && !props.noSettings && (
  180. <Button onClick={props?.onSetting} style={{ marginLeft: 10 }}>
  181. 告警配置
  182. </Button>
  183. )}
  184. </div>
  185. </div>
  186. {current === "history" && (
  187. <AlarmHistory
  188. onSelect={onSelect}
  189. ruleId={ruleId}
  190. group={options?.group}
  191. diagramId={options?.diagramId}
  192. ></AlarmHistory>
  193. )}
  194. {current !== "history" && (
  195. <AlarmDetail
  196. onSetting={props?.onSetting}
  197. onConfirm={() => setShowConfirm(true)}
  198. data={currentData}
  199. ></AlarmDetail>
  200. )}
  201. </>
  202. )}
  203. </Modal>
  204. <AlarmConfirm
  205. currentAlarm={currentData?.data}
  206. open={showConfirm}
  207. onCancel={() => setShowConfirm(false)}
  208. onConfirm={onAlarmConfirm}
  209. />
  210. {/* <AlarmConfig
  211. visible={showAlarmConfig}
  212. pointId={props.alarmConfig?.pointId}
  213. ruleId={props.alarmConfig?.ruleId}
  214. onClose={() => {
  215. setShowAlarmConfig(false);
  216. }}
  217. onConfirm={({ id }) => props.onConfirm?.({ ruleId: id ?? 0 })}
  218. isDiagram={isDiagram}
  219. ></AlarmConfig> */}
  220. </>
  221. );
  222. };
  223. export default Detail;