|
|
@@ -6,7 +6,7 @@ import React, {
|
|
|
useImperativeHandle,
|
|
|
} from "react";
|
|
|
import { Form, Input, Select, message } from "antd";
|
|
|
-import { Modal, Button, Table } from "antd";
|
|
|
+import { Modal, Button, Table, Radio } from "antd";
|
|
|
import Formular from "./components/Formular";
|
|
|
import API2 from "../../../api/alarm";
|
|
|
import styles from "./complex.module.less";
|
|
|
@@ -32,7 +32,7 @@ function TranslateText(arr) {
|
|
|
}
|
|
|
|
|
|
const Complex = (props, ref) => {
|
|
|
- const { alarmId, groupList = [] } = props;
|
|
|
+ const { editId, groupList = [], showList } = props;
|
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
const formuRef = useRef();
|
|
|
@@ -51,6 +51,9 @@ const Complex = (props, ref) => {
|
|
|
// showSizeChanger:true,
|
|
|
// size:'Large',
|
|
|
});
|
|
|
+ const [alarmId, setAlarmId] = useState(null);
|
|
|
+ const [type, setType] = useState(0);
|
|
|
+ const [ruleOptions, setRuleOptions] = useState([]);
|
|
|
|
|
|
const handleTableChange = async (pagination) => {
|
|
|
setPaginationProps({ ...pagination, showTotal: (total) => `共${total}条` });
|
|
|
@@ -73,12 +76,23 @@ const Complex = (props, ref) => {
|
|
|
});
|
|
|
formuRef.current.backEndInput(data.formula);
|
|
|
setData(data);
|
|
|
+ } else {
|
|
|
+ form.setFieldsValue({
|
|
|
+ name: "",
|
|
|
+ alarm_level: "",
|
|
|
+ group_id: "",
|
|
|
+ });
|
|
|
+ setData(null);
|
|
|
}
|
|
|
}
|
|
|
run();
|
|
|
}, [alarmId]);
|
|
|
|
|
|
const onModalOk = async () => {
|
|
|
+ if (type === 0) {
|
|
|
+ props.onConfirm(null);
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (alarmId == -1) {
|
|
|
const value = await form.validateFields();
|
|
|
const obj = {
|
|
|
@@ -109,7 +123,7 @@ const Complex = (props, ref) => {
|
|
|
const { state } = await API2.editRule(obj);
|
|
|
if (state === 0) {
|
|
|
message.success("保存成功");
|
|
|
- props.onConfirm();
|
|
|
+ props.onConfirm(data.id);
|
|
|
}
|
|
|
}
|
|
|
form.resetFields();
|
|
|
@@ -182,6 +196,43 @@ const Complex = (props, ref) => {
|
|
|
form.resetFields();
|
|
|
};
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ function run() {
|
|
|
+ if (editId && editId !== -1) {
|
|
|
+ setAlarmId(editId);
|
|
|
+ if (showList) {
|
|
|
+ setType(1);
|
|
|
+ }
|
|
|
+ } else if (showList) {
|
|
|
+ setType(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ run();
|
|
|
+ }, [editId, showList]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ async function run() {
|
|
|
+ if (showList) {
|
|
|
+ const res = await API2.getRuleList();
|
|
|
+ setRuleOptions(
|
|
|
+ res?.data?.rules?.map((item) => ({
|
|
|
+ label: item.name,
|
|
|
+ value: item.id,
|
|
|
+ }))
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ run();
|
|
|
+ }, [showList]);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (type === 2) {
|
|
|
+ setAlarmId(-1);
|
|
|
+ } else if(alarmId === -1 && type !== 2) {
|
|
|
+ setAlarmId(null);
|
|
|
+ }
|
|
|
+ }, [type, alarmId]);
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.wrapper}>
|
|
|
<div className="main">
|
|
|
@@ -200,158 +251,203 @@ const Complex = (props, ref) => {
|
|
|
span: 15,
|
|
|
}}
|
|
|
>
|
|
|
- <Form.Item
|
|
|
- label={TranslateText(["告警名称", "Alarm name"])}
|
|
|
- name="name"
|
|
|
- rules={[
|
|
|
- {
|
|
|
- required: true,
|
|
|
- message: TranslateText(["请输入告警名称", "Please input"]),
|
|
|
- },
|
|
|
- ]}
|
|
|
- >
|
|
|
- <Input
|
|
|
- placeholder={TranslateText(["请输入告警名称", "Please input"])}
|
|
|
- style={{ width: "240px" }}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
+ {showList && (
|
|
|
+ <>
|
|
|
+ <Form.Item label="类型">
|
|
|
+ <Radio.Group
|
|
|
+ value={type}
|
|
|
+ onChange={(e) => setType(e.target.value)}
|
|
|
+ >
|
|
|
+ <Radio value={0}>无规则</Radio>
|
|
|
+ <Radio value={1}>关联规则</Radio>
|
|
|
+ <Radio value={2}>新建规则</Radio>
|
|
|
+ </Radio.Group>
|
|
|
+ </Form.Item>
|
|
|
+ {type === 1 && (
|
|
|
+ <Form.Item label="关联规则">
|
|
|
+ <Select
|
|
|
+ value={alarmId}
|
|
|
+ onChange={setAlarmId}
|
|
|
+ style={{ width: 240 }}
|
|
|
+ options={ruleOptions}
|
|
|
+ placeholder={TranslateText(["请选择", "Please choose"])}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+ )}
|
|
|
+ </>
|
|
|
+ )}
|
|
|
+ {(!showList || type !== 0) && (
|
|
|
+ <>
|
|
|
+ <Form.Item
|
|
|
+ label={TranslateText(["告警名称", "Alarm name"])}
|
|
|
+ name="name"
|
|
|
+ rules={[
|
|
|
+ {
|
|
|
+ required: true,
|
|
|
+ message: TranslateText([
|
|
|
+ "请输入告警名称",
|
|
|
+ "Please input",
|
|
|
+ ]),
|
|
|
+ },
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <Input
|
|
|
+ placeholder={TranslateText([
|
|
|
+ "请输入告警名称",
|
|
|
+ "Please input",
|
|
|
+ ])}
|
|
|
+ style={{ width: "240px" }}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
|
|
|
- <Form.Item
|
|
|
- label={TranslateText(["条件符号", "Symbol"])}
|
|
|
- // name="symb"
|
|
|
- >
|
|
|
- <div className="symb" style={{ width: "500px" }}>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- ()
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- {"&&(and)"}
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- {"||(or)"}
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- ≥
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- {">"}
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- =
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>{`<`}</Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- ≤
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- +
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- -
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- ×
|
|
|
- </Button>
|
|
|
- <Button type="primary" onClick={symbClick}>
|
|
|
- ÷
|
|
|
- </Button>
|
|
|
- </div>
|
|
|
- </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label={TranslateText(["条件符号", "Symbol"])}
|
|
|
+ // name="symb"
|
|
|
+ >
|
|
|
+ <div className="symb" style={{ width: "500px" }}>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ ()
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ {"&&(and)"}
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ {"||(or)"}
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ ≥
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ {">"}
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ =
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>{`<`}</Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ ≤
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ +
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ -
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ ×
|
|
|
+ </Button>
|
|
|
+ <Button type="primary" onClick={symbClick}>
|
|
|
+ ÷
|
|
|
+ </Button>
|
|
|
+ </div>
|
|
|
+ </Form.Item>
|
|
|
|
|
|
- <Form.Item
|
|
|
- label={TranslateText(["条件编辑", "Edit"])}
|
|
|
- // name="formu"
|
|
|
- >
|
|
|
- <Formular ref={formuRef} />
|
|
|
- </Form.Item>
|
|
|
+ <Form.Item
|
|
|
+ label={TranslateText(["条件编辑", "Edit"])}
|
|
|
+ // name="formu"
|
|
|
+ >
|
|
|
+ <Formular ref={formuRef} key={`${type}-${alarmId}`} />
|
|
|
+ </Form.Item>
|
|
|
|
|
|
- <Form.Item
|
|
|
- label={TranslateText(["告警组", "Alarm group"])}
|
|
|
- name={"group_id"}
|
|
|
- >
|
|
|
- <Select
|
|
|
- style={{ width: 240 }}
|
|
|
- options={[
|
|
|
- ...[
|
|
|
+ <Form.Item
|
|
|
+ label={TranslateText(["告警组", "Alarm group"])}
|
|
|
+ name={"group_id"}
|
|
|
+ >
|
|
|
+ <Select
|
|
|
+ style={{ width: 240 }}
|
|
|
+ options={[
|
|
|
+ ...[
|
|
|
+ {
|
|
|
+ label: "未分组",
|
|
|
+ value: 0,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ ...(groupList?.map((item) => {
|
|
|
+ return {
|
|
|
+ label: item?.name,
|
|
|
+ value: item?.id,
|
|
|
+ };
|
|
|
+ }) ?? []),
|
|
|
+ ]}
|
|
|
+ placeholder={TranslateText(["请选择", "Please choose"])}
|
|
|
+ />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item
|
|
|
+ label={TranslateText(["告警级别", "Alarm level"])}
|
|
|
+ name="alarm_level"
|
|
|
+ rules={[
|
|
|
{
|
|
|
- label: "未分组",
|
|
|
- value: 0,
|
|
|
+ required: true,
|
|
|
+ message: TranslateText([
|
|
|
+ "请输入告警级别",
|
|
|
+ "Please input",
|
|
|
+ ]),
|
|
|
},
|
|
|
- ],
|
|
|
- ...(groupList?.map((item) => {
|
|
|
- return {
|
|
|
- label: item?.name,
|
|
|
- value: item?.id,
|
|
|
- };
|
|
|
- }) ?? []),
|
|
|
- ]}
|
|
|
- placeholder={TranslateText(["请选择", "Please choose"])}
|
|
|
- />
|
|
|
- </Form.Item>
|
|
|
-
|
|
|
- <Form.Item
|
|
|
- label={TranslateText(["告警级别", "Alarm level"])}
|
|
|
- name="alarm_level"
|
|
|
- rules={[
|
|
|
- {
|
|
|
- required: true,
|
|
|
- message: TranslateText(["请输入告警级别", "Please input"]),
|
|
|
- },
|
|
|
- ]}
|
|
|
- >
|
|
|
- <Select
|
|
|
- placeholder={TranslateText(["请选择", "Please choose"])}
|
|
|
- style={{ width: "240px" }}
|
|
|
- >
|
|
|
- <Select.Option value={1}>
|
|
|
- {TranslateText(["低", "Low"])}
|
|
|
- </Select.Option>
|
|
|
- <Select.Option value={2}>
|
|
|
- {TranslateText(["中", "Medium"])}
|
|
|
- </Select.Option>
|
|
|
- <Select.Option value={3}>
|
|
|
- {TranslateText(["高", "High"])}
|
|
|
- </Select.Option>
|
|
|
- </Select>
|
|
|
- </Form.Item>
|
|
|
+ ]}
|
|
|
+ >
|
|
|
+ <Select
|
|
|
+ placeholder={TranslateText(["请选择", "Please choose"])}
|
|
|
+ style={{ width: "240px" }}
|
|
|
+ >
|
|
|
+ <Select.Option value={1}>
|
|
|
+ {TranslateText(["低", "Low"])}
|
|
|
+ </Select.Option>
|
|
|
+ <Select.Option value={2}>
|
|
|
+ {TranslateText(["中", "Medium"])}
|
|
|
+ </Select.Option>
|
|
|
+ <Select.Option value={3}>
|
|
|
+ {TranslateText(["高", "High"])}
|
|
|
+ </Select.Option>
|
|
|
+ </Select>
|
|
|
+ </Form.Item>
|
|
|
+ </>
|
|
|
+ )}
|
|
|
</Form>
|
|
|
</div>
|
|
|
|
|
|
- <div
|
|
|
- style={{
|
|
|
- borderRight: "1px solid rgba(255, 255, 255, 0.12)",
|
|
|
- marginLeft: "16px",
|
|
|
- }}
|
|
|
- ></div>
|
|
|
+ {(!showList || type !== 0) && (
|
|
|
+ <>
|
|
|
+ <div
|
|
|
+ style={{
|
|
|
+ borderRight: "1px solid rgba(255, 255, 255, 0.12)",
|
|
|
+ marginLeft: "16px",
|
|
|
+ }}
|
|
|
+ ></div>
|
|
|
|
|
|
- <div className="right">
|
|
|
- <div className="header">
|
|
|
- <Search
|
|
|
- placeholder={TranslateText(["请输入点位名称", "Please input"])}
|
|
|
- onSearch={onSearch}
|
|
|
- style={{ width: "240px" }}
|
|
|
- // className={styles.deviceListTreeSearch}
|
|
|
- />
|
|
|
- </div>
|
|
|
- <Table
|
|
|
- onRow={(record) => {
|
|
|
- return {
|
|
|
- onClick: (event) => {
|
|
|
- clickTableRow(record);
|
|
|
- }, // 点击行
|
|
|
- };
|
|
|
- }}
|
|
|
- key={deviceList}
|
|
|
- loading={loading}
|
|
|
- columns={columns}
|
|
|
- dataSource={deviceList}
|
|
|
- rowKey="point_id"
|
|
|
- // className="deviceListTable"
|
|
|
- pagination={paginationProps}
|
|
|
- onChange={handleTableChange}
|
|
|
- size="middle"
|
|
|
- />
|
|
|
- </div>
|
|
|
+ <div className="right">
|
|
|
+ <div className="header">
|
|
|
+ <Search
|
|
|
+ placeholder={TranslateText([
|
|
|
+ "请输入点位名称",
|
|
|
+ "Please input",
|
|
|
+ ])}
|
|
|
+ onSearch={onSearch}
|
|
|
+ style={{ width: "240px" }}
|
|
|
+ // className={styles.deviceListTreeSearch}
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ <Table
|
|
|
+ onRow={(record) => {
|
|
|
+ return {
|
|
|
+ onClick: (event) => {
|
|
|
+ clickTableRow(record);
|
|
|
+ }, // 点击行
|
|
|
+ };
|
|
|
+ }}
|
|
|
+ key={deviceList}
|
|
|
+ loading={loading}
|
|
|
+ columns={columns}
|
|
|
+ dataSource={deviceList}
|
|
|
+ rowKey="point_id"
|
|
|
+ // className="deviceListTable"
|
|
|
+ pagination={paginationProps}
|
|
|
+ onChange={handleTableChange}
|
|
|
+ size="middle"
|
|
|
+ />
|
|
|
+ </div>
|
|
|
+ </>
|
|
|
+ )}
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|