detail.jsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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(-1);
  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.ruleId || options.pointId) {
  40. getRuleIdByPointId(options.ruleId, options.pointId);
  41. } else if (options.detail) {
  42. setRuleId([options.detail.rule_id]);
  43. setTags([
  44. {
  45. id: options.detail.id,
  46. data: options.detail,
  47. },
  48. ]);
  49. setCurrent(options.detail.id);
  50. }
  51. }, [options.detail, options.ruleId, options.pointId]);
  52. const currentData = tags.find((item) => item.id === current) ?? {};
  53. const onRemove = (index) => {
  54. const newTags = _.cloneDeep(tags);
  55. newTags.splice(index, 1);
  56. setTags(newTags);
  57. };
  58. const onSelect = (record) => {
  59. if (!tags.some((item) => item.id === record.id)) {
  60. const newTags = _.cloneDeep(tags);
  61. newTags.push({
  62. id: record.id,
  63. data: record,
  64. });
  65. setTags(newTags);
  66. }
  67. setCurrent(record.id);
  68. };
  69. const onAlarmConfirm = (newRecord) => {
  70. if (newRecord) {
  71. const newTags = _.clone(tags);
  72. const currentIndex = newTags.findIndex((item) => item.id === current);
  73. newTags[currentIndex].data = newRecord;
  74. setTags(newTags);
  75. }
  76. };
  77. return (
  78. <>
  79. <Modal
  80. title="告警记录"
  81. open={props.open}
  82. width="90vw"
  83. onCancel={() => {
  84. props.onCancel();
  85. }}
  86. zIndex="1001"
  87. footer={null}
  88. destroyOnClose
  89. style={{
  90. top: 50,
  91. }}
  92. bodyStyle={{
  93. height: "calc(90vh - 80px)",
  94. }}
  95. >
  96. {props.open && (
  97. <>
  98. <div className={styles.header}>
  99. <div className={styles.tags}>
  100. <Tabs
  101. hideAdd
  102. onChange={setCurrent}
  103. activeKey={current}
  104. type="card"
  105. items={[
  106. { label: "告警记录", children: null, key: "history" },
  107. ...tags.map((item, index) => ({
  108. label: (
  109. <div className={styles.tagContainer}>
  110. <div className={styles.label}>详情{index + 1}</div>
  111. <CloseOutlined
  112. style={{ fontSize: 10 }}
  113. onClick={(e) => {
  114. e.stopPropagation();
  115. if (current === item.id) {
  116. setCurrent("history");
  117. }
  118. onRemove(index);
  119. }}
  120. />
  121. </div>
  122. ),
  123. children: null,
  124. key: item.id,
  125. })),
  126. ]}
  127. />
  128. {/* <Radio.Group
  129. value={current}
  130. onChange={(e) => setCurrent(e.target.value)}
  131. size="middle"
  132. >
  133. <Radio.Button value="history">告警记录</Radio.Button>
  134. {tags.map((item, index) => (
  135. <Radio.Button value={item.id}>
  136. <div className={styles.tagContainer}>
  137. <div className={styles.label}>详情{index + 1}</div>
  138. <CloseOutlined
  139. style={{ fontSize: 10 }}
  140. onClick={() => {
  141. if (current === item.id) {
  142. setCurrent("history");
  143. }
  144. onRemove(index);
  145. }}
  146. />
  147. </div>
  148. </Radio.Button>
  149. ))}
  150. </Radio.Group> */}
  151. </div>
  152. <div className={styles.oper}>
  153. {current !== "history" && (
  154. <Button
  155. disabled={currentData?.data?.op_status === 1}
  156. onClick={() => setShowConfirm(true)}
  157. >
  158. {currentData?.data?.op_status === 1 ? "已确认" : "确认"}
  159. </Button>
  160. )}
  161. <Button onClick={props?.onSetting} style={{ marginLeft: 10 }}>
  162. 告警配置
  163. </Button>
  164. </div>
  165. </div>
  166. {current === "history" && (
  167. <AlarmHistory onSelect={onSelect} ruleId={ruleId}></AlarmHistory>
  168. )}
  169. {current !== "history" && (
  170. <AlarmDetail data={currentData}></AlarmDetail>
  171. )}
  172. </>
  173. )}
  174. </Modal>
  175. <AlarmConfirm
  176. currentAlarm={currentData?.data}
  177. open={showConfirm}
  178. onCancel={() => setShowConfirm(false)}
  179. onConfirm={onAlarmConfirm}
  180. />
  181. {/* <AlarmConfig
  182. visible={showAlarmConfig}
  183. pointId={props.alarmConfig?.pointId}
  184. ruleId={props.alarmConfig?.ruleId}
  185. onClose={() => {
  186. setShowAlarmConfig(false);
  187. }}
  188. onConfirm={({ id }) => props.onConfirm?.({ ruleId: id ?? 0 })}
  189. isDiagram={isDiagram}
  190. ></AlarmConfig> */}
  191. </>
  192. );
  193. };
  194. export default Detail;