|
@@ -1,5 +1,5 @@
|
|
import { useAjax } from "@/Hook/useAjax"
|
|
import { useAjax } from "@/Hook/useAjax"
|
|
-import { addSysWarningRuleApi } from "@/services/adMonitor/earlyWarning"
|
|
|
|
|
|
+import { addSysWarningRuleApi, editSysWarningRuleApi } from "@/services/adMonitor/earlyWarning"
|
|
import { DeleteOutlined, PlusOutlined } from "@ant-design/icons"
|
|
import { DeleteOutlined, PlusOutlined } from "@ant-design/icons"
|
|
import { Button, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Switch } from "antd"
|
|
import { Button, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Switch } from "antd"
|
|
import React from "react"
|
|
import React from "react"
|
|
@@ -11,18 +11,22 @@ import PriceInput from "./priceInput"
|
|
interface Props {
|
|
interface Props {
|
|
visible?: boolean
|
|
visible?: boolean
|
|
onClose?: () => void
|
|
onClose?: () => void
|
|
- onChange?: () => void
|
|
|
|
|
|
+ onChange?: () => void,
|
|
|
|
+ initialValues?: any
|
|
}
|
|
}
|
|
const AddEdit: React.FC<Props> = (props) => {
|
|
const AddEdit: React.FC<Props> = (props) => {
|
|
|
|
|
|
/******************************/
|
|
/******************************/
|
|
- const { visible, onClose, onChange } = props
|
|
|
|
|
|
+ const { visible, onClose, onChange, initialValues } = props
|
|
const [form] = Form.useForm();
|
|
const [form] = Form.useForm();
|
|
const rules = Form.useWatch('rules', form);
|
|
const rules = Form.useWatch('rules', form);
|
|
|
|
|
|
const addSysWarningRule = useAjax((params) => addSysWarningRuleApi(params))
|
|
const addSysWarningRule = useAjax((params) => addSysWarningRuleApi(params))
|
|
|
|
+ const editSysWarningRule = useAjax((params) => editSysWarningRuleApi(params))
|
|
/******************************/
|
|
/******************************/
|
|
|
|
|
|
|
|
+ console.log('initialValues--->', initialValues);
|
|
|
|
+
|
|
|
|
|
|
const handleOk = () => {
|
|
const handleOk = () => {
|
|
// console.log(JSON.stringify(rules));
|
|
// console.log(JSON.stringify(rules));
|
|
@@ -41,11 +45,17 @@ const AddEdit: React.FC<Props> = (props) => {
|
|
})
|
|
})
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- console.log('params--->', { rules: params, notifyFrequency, ruleName, warningType, defaultRule: defaultRule ? 1 : 0, enable: enable ? 1 : 0 });
|
|
|
|
- addSysWarningRule.run({ rules: params, notifyFrequency, ruleName, warningType, defaultRule: defaultRule ? 1 : 0, enable: enable ? 1 : 0 }).then(res => {
|
|
|
|
- message.success('新增成功')
|
|
|
|
- onChange?.()
|
|
|
|
- })
|
|
|
|
|
|
+ if (initialValues?.id) {
|
|
|
|
+ editSysWarningRule.run({ ruleId: initialValues.id, rules: params, notifyFrequency, ruleName, warningType, defaultRule: defaultRule ? 1 : 0, enable: enable ? 1 : 0 }).then(res => {
|
|
|
|
+ message.success('修改成功')
|
|
|
|
+ onChange?.()
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ addSysWarningRule.run({ rules: params, notifyFrequency, ruleName, warningType, defaultRule: defaultRule ? 1 : 0, enable: enable ? 1 : 0 }).then(res => {
|
|
|
|
+ message.success('新增成功')
|
|
|
|
+ onChange?.()
|
|
|
|
+ })
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
message.error('请添加最少一项规则')
|
|
message.error('请添加最少一项规则')
|
|
}
|
|
}
|
|
@@ -53,13 +63,13 @@ const AddEdit: React.FC<Props> = (props) => {
|
|
}
|
|
}
|
|
return <Modal
|
|
return <Modal
|
|
title={<Space size={2} align='end'>
|
|
title={<Space size={2} align='end'>
|
|
- <strong>设置预警</strong>
|
|
|
|
|
|
+ <strong>{initialValues?.id ? '修改预警规则' : '新增预警规则'}</strong>
|
|
<span style={{ fontSize: 12, color: 'red' }}>(条件与条件之间是或者关系,条件内字段是并且关系, 满足任意一条件立即触发报警提醒)</span>
|
|
<span style={{ fontSize: 12, color: 'red' }}>(条件与条件之间是或者关系,条件内字段是并且关系, 满足任意一条件立即触发报警提醒)</span>
|
|
</Space>}
|
|
</Space>}
|
|
visible={visible}
|
|
visible={visible}
|
|
onOk={handleOk}
|
|
onOk={handleOk}
|
|
width={750}
|
|
width={750}
|
|
- confirmLoading={addSysWarningRule.loading}
|
|
|
|
|
|
+ confirmLoading={addSysWarningRule.loading || editSysWarningRule.loading}
|
|
onCancel={() => onClose?.()}
|
|
onCancel={() => onClose?.()}
|
|
>
|
|
>
|
|
<Form
|
|
<Form
|
|
@@ -68,7 +78,7 @@ const AddEdit: React.FC<Props> = (props) => {
|
|
className="addEdit_form"
|
|
className="addEdit_form"
|
|
labelCol={{ span: 5 }}
|
|
labelCol={{ span: 5 }}
|
|
colon={false}
|
|
colon={false}
|
|
- initialValues={{
|
|
|
|
|
|
+ initialValues={initialValues || {
|
|
enable: true,
|
|
enable: true,
|
|
notifyFrequency: 5,
|
|
notifyFrequency: 5,
|
|
defaultRule: false,
|
|
defaultRule: false,
|