|
|
@@ -0,0 +1,306 @@
|
|
|
+import React, {
|
|
|
+ useEffect,
|
|
|
+ useState,
|
|
|
+ forwardRef,
|
|
|
+ useImperativeHandle,
|
|
|
+} from "react";
|
|
|
+import { Tooltip, Space, Pagination, Button } from "antd";
|
|
|
+import { Table } from "antd";
|
|
|
+import styles from "./index.module.less";
|
|
|
+import { useMemoizedFn } from "ahooks";
|
|
|
+import { CloseOutlined } from "@ant-design/icons";
|
|
|
+import _ from "lodash";
|
|
|
+import dayjs from "dayjs";
|
|
|
+import API from "../../../../../api/alarm";
|
|
|
+import AlarmConfirm from "../AlarmConfirm";
|
|
|
+
|
|
|
+function TranslateText(arr) {
|
|
|
+ const dtLanguage = localStorage.getItem("dtLanguage");
|
|
|
+ if (!Array.isArray(arr)) {
|
|
|
+ return arr;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (arr.length < 2 && arr.length > 0) {
|
|
|
+ return arr?.[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (dtLanguage === "en") {
|
|
|
+ return arr?.[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ return arr?.[0];
|
|
|
+}
|
|
|
+
|
|
|
+const timeTranslateMap = {
|
|
|
+ s: TranslateText(["秒", "s"]),
|
|
|
+ m: TranslateText(["分钟", "min"]),
|
|
|
+ h: TranslateText(["小时", "h"]),
|
|
|
+ d: TranslateText(["天", "d"]),
|
|
|
+};
|
|
|
+
|
|
|
+const statusEnum = {
|
|
|
+ 0: "执行中",
|
|
|
+ 1: "执行成功",
|
|
|
+ 2: "执行失败",
|
|
|
+ 3: "已取消",
|
|
|
+ 4: "取消中",
|
|
|
+};
|
|
|
+
|
|
|
+const statusEnumColor = {
|
|
|
+ 0: "blue",
|
|
|
+ 1: "green",
|
|
|
+ 2: "red",
|
|
|
+ 3: "gray",
|
|
|
+ 4: "gray",
|
|
|
+};
|
|
|
+
|
|
|
+const alarmTypeMap = {
|
|
|
+ 1: "过程告警",
|
|
|
+ 2: "指令告警",
|
|
|
+ 3: "系统告警",
|
|
|
+};
|
|
|
+
|
|
|
+const levelMap = {
|
|
|
+ 1: TranslateText(["低", "Low"]),
|
|
|
+ 2: TranslateText(["中", "Medium"]),
|
|
|
+ 3: TranslateText(["高", "High"]),
|
|
|
+};
|
|
|
+
|
|
|
+const levelColor = {
|
|
|
+ 1: styles.low,
|
|
|
+ 2: styles.medium,
|
|
|
+ 3: styles.high,
|
|
|
+};
|
|
|
+
|
|
|
+const statusColor = {
|
|
|
+ 0: styles.high,
|
|
|
+ 1: styles.high,
|
|
|
+ 2: styles.low,
|
|
|
+};
|
|
|
+
|
|
|
+const alarmStatusMap = {
|
|
|
+ 0: TranslateText(["进行中", "In progress"]),
|
|
|
+ 1: TranslateText(["进行中", "In progress"]),
|
|
|
+ 2: TranslateText(["已结束", "Ended"]),
|
|
|
+};
|
|
|
+
|
|
|
+const showTotal = (total) => `共${total}条`;
|
|
|
+
|
|
|
+const Index = (props) => {
|
|
|
+ const [tags, setTags] = useState([{ name: "详情1", id: "1" }]);
|
|
|
+ const [current, setCurrent] = useState("history");
|
|
|
+ const [loading, setLoading] = useState(false);
|
|
|
+ const [data, setData] = useState([]);
|
|
|
+ const [total, setTotal] = useState(1);
|
|
|
+ const [page, setPage] = useState(1);
|
|
|
+ const [currentAlarm, setCurrentAlarm] = useState({});
|
|
|
+ const [showConfirm, setShowConfirm] = useState(false);
|
|
|
+
|
|
|
+ const fetchData = useMemoizedFn(async () => {
|
|
|
+ if (props.ruleId === -1) return;
|
|
|
+ const res = await API.getAlarmHistory(page, props.ruleId);
|
|
|
+ setData(res?.data?.history);
|
|
|
+ setTotal(res?.data?.total);
|
|
|
+ });
|
|
|
+
|
|
|
+ const onConfirm = (record) => {
|
|
|
+ setCurrentAlarm(record);
|
|
|
+ setShowConfirm(true);
|
|
|
+ };
|
|
|
+ useEffect(() => {
|
|
|
+ fetchData();
|
|
|
+ }, [page, props.ruleId, fetchData]);
|
|
|
+ const columns = [
|
|
|
+ // {
|
|
|
+ // title: '序号',
|
|
|
+ // width: '58px',
|
|
|
+ // render: (text, record, index) =>
|
|
|
+ // `${(paginationProps.current - 1) * (paginationProps.pageSize) + (index + 1)}`
|
|
|
+ // },
|
|
|
+ {
|
|
|
+ title: TranslateText(["告警时间", "Alarm time"]),
|
|
|
+ width: 180,
|
|
|
+ dataIndex: "created_time",
|
|
|
+ render: (text, record) =>
|
|
|
+ text ? dayjs(text).format("YYYY-MM-DD HH:mm:ss") : "暂无",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TranslateText(["告警名称", "Alarm name"]),
|
|
|
+ dataIndex: "name",
|
|
|
+ ellipsis: true,
|
|
|
+ width: 160,
|
|
|
+ render: (text, record) => {
|
|
|
+ return <Tooltip title={text}>{text}</Tooltip>;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: () => {
|
|
|
+ return (
|
|
|
+ <Tooltip title={TranslateText(["告警级别", "Level"])}>
|
|
|
+ <span>{TranslateText(["告警级别", "Level"])}</span>
|
|
|
+ </Tooltip>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ onHeaderCell: () => ({
|
|
|
+ style: {
|
|
|
+ whiteSpace: "nowrap",
|
|
|
+ overflow: "hidden",
|
|
|
+ textOverflow: "ellipsis",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ dataIndex: "alarm_level",
|
|
|
+ width: 100,
|
|
|
+ render: (text, record) => {
|
|
|
+ return (
|
|
|
+ <div className={styles.state}>
|
|
|
+ <div className={levelColor[text]} />
|
|
|
+ <div>{levelMap[text]}</div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TranslateText(["恢复时间", "Recovery time"]),
|
|
|
+ dataIndex: "recovery_time",
|
|
|
+ width: 180,
|
|
|
+ render: (text, record) =>
|
|
|
+ text ? dayjs(text).format("YYYY-MM-DD HH:mm:ss") : "-",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TranslateText(["持续时间", "duration"]),
|
|
|
+ dataIndex: "duration",
|
|
|
+ width: 180,
|
|
|
+ render: (text, record) => {
|
|
|
+ if (text < 60) {
|
|
|
+ return `${text}${timeTranslateMap["s"]}`;
|
|
|
+ } else if (text >= 60 && text < 3600) {
|
|
|
+ return `${parseInt(text / 60)}${timeTranslateMap["m"]}${
|
|
|
+ text % 60 === 0
|
|
|
+ ? ""
|
|
|
+ : `${parseInt(text % 60)}${timeTranslateMap["s"]}`
|
|
|
+ }`;
|
|
|
+ } else if (text >= 3600 && text < 3600 * 24) {
|
|
|
+ return `${parseInt(text / 3600)}${timeTranslateMap["h"]}${
|
|
|
+ (text / 60) % 60 === 0
|
|
|
+ ? ""
|
|
|
+ : `${parseInt((text / 60) % 60)}${timeTranslateMap["m"]}`
|
|
|
+ }`;
|
|
|
+ } else if (text >= 3600 * 24) {
|
|
|
+ let hour = parseInt((parseInt(text / 36) / 100) % 24);
|
|
|
+ return `${parseInt(text / (3600 * 24))}${timeTranslateMap["d"]}${
|
|
|
+ text % 36 === 0
|
|
|
+ ? ""
|
|
|
+ : hour > 0
|
|
|
+ ? `${hour}${timeTranslateMap["h"]}`
|
|
|
+ : ""
|
|
|
+ }`;
|
|
|
+ }
|
|
|
+ // return `${Math.ceil(text / 36) / 100}小时`
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TranslateText(["告警状态", "Status"]),
|
|
|
+ dataIndex: "status",
|
|
|
+ width: 100,
|
|
|
+ render: (text, record) => {
|
|
|
+ return (
|
|
|
+ <div className={styles.state}>
|
|
|
+ <div className={statusColor[text]} />
|
|
|
+ <div>{alarmStatusMap[text]}</div>
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: () => {
|
|
|
+ return (
|
|
|
+ <Tooltip title={TranslateText(["确认人", "Confirm person"])}>
|
|
|
+ <span>{TranslateText(["确认人", "Confirm person"])}</span>
|
|
|
+ </Tooltip>
|
|
|
+ );
|
|
|
+ },
|
|
|
+ onHeaderCell: () => ({
|
|
|
+ style: {
|
|
|
+ whiteSpace: "nowrap",
|
|
|
+ overflow: "hidden",
|
|
|
+ textOverflow: "ellipsis",
|
|
|
+ },
|
|
|
+ }),
|
|
|
+ dataIndex: "confirmed_oper_name",
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TranslateText(["确认时间", "Confirm time"]),
|
|
|
+ dataIndex: "confirmed_time",
|
|
|
+ width: 180,
|
|
|
+ render: (text, record) =>
|
|
|
+ text ? dayjs(text).format("YYYY-MM-DD HH:mm:ss") : "-",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TranslateText(["备注", "Remarks"]),
|
|
|
+ dataIndex: "remark",
|
|
|
+ width: 120,
|
|
|
+ ellipsis: "true",
|
|
|
+ render: (text, record) => {
|
|
|
+ return <Tooltip title={text}>{text}</Tooltip>;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: TranslateText(["操作", "Operation"]),
|
|
|
+ dataIndex: "action",
|
|
|
+ width: 120,
|
|
|
+ fixed: "right",
|
|
|
+ render: (_, record) => (
|
|
|
+ <div style={{ display: "flex" }}>
|
|
|
+ <Button
|
|
|
+ onClick={() => props.onSelect(record)}
|
|
|
+ style={{ width: 0 }}
|
|
|
+ type="link"
|
|
|
+ >
|
|
|
+ 详情
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ onClick={() => onConfirm(record)}
|
|
|
+ style={{ width: 0 }}
|
|
|
+ type="link"
|
|
|
+ >
|
|
|
+ 确认
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ ),
|
|
|
+ },
|
|
|
+ ];
|
|
|
+ return (
|
|
|
+ <>
|
|
|
+ <Table
|
|
|
+ className={styles.table}
|
|
|
+ loading={loading}
|
|
|
+ columns={columns}
|
|
|
+ dataSource={data}
|
|
|
+ rowKey="id"
|
|
|
+ pagination={false}
|
|
|
+ size="middle"
|
|
|
+ scroll={{
|
|
|
+ x: 1160,
|
|
|
+ y: 432,
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ <div className={styles.page}>
|
|
|
+ <Pagination
|
|
|
+ onChange={setPage}
|
|
|
+ total={total}
|
|
|
+ showTotal={showTotal}
|
|
|
+ showSizeChanger={false}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <AlarmConfirm
|
|
|
+ currentAlarm={currentAlarm}
|
|
|
+ open={showConfirm}
|
|
|
+ onCancel={() => setShowConfirm(false)}
|
|
|
+ onConfirm={fetchData}
|
|
|
+ />
|
|
|
+ </>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default Index;
|