|
@@ -1,7 +1,7 @@
|
|
|
-import { DeleteOutlined, PlusOutlined, QuestionCircleOutlined } from "@ant-design/icons"
|
|
|
-import { Button, DatePicker, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Switch, TimePicker, Tooltip } from "antd"
|
|
|
-import { RuleObject } from "antd/es/form"
|
|
|
-import { StoreValue } from "antd/es/form/interface"
|
|
|
+import { useAjax } from "@/Hook/useAjax"
|
|
|
+import { addSysWarningRuleApi } from "@/services/adMonitor/earlyWarning"
|
|
|
+import { DeleteOutlined, PlusOutlined } from "@ant-design/icons"
|
|
|
+import { Button, Form, Input, InputNumber, message, Modal, Popconfirm, Select, Space, Switch } from "antd"
|
|
|
import React from "react"
|
|
|
import { MonitorFieldEnum, WarningTypeEnum } from "./config"
|
|
|
import './index.less'
|
|
@@ -16,19 +16,21 @@ interface Props {
|
|
|
const AddEdit: React.FC<Props> = (props) => {
|
|
|
|
|
|
/******************************/
|
|
|
- const { visible, onClose } = props
|
|
|
+ const { visible, onClose, onChange } = props
|
|
|
const [form] = Form.useForm();
|
|
|
const rules = Form.useWatch('rules', form);
|
|
|
+
|
|
|
+ const addSysWarningRule = useAjax((params) => addSysWarningRuleApi(params))
|
|
|
/******************************/
|
|
|
|
|
|
|
|
|
const handleOk = () => {
|
|
|
console.log(JSON.stringify(rules));
|
|
|
form.validateFields().then(values => {
|
|
|
- console.log(values);
|
|
|
if (values?.rules) {
|
|
|
let newValues = JSON.parse(JSON.stringify(values))
|
|
|
- let params = newValues?.rules?.map((item: any) => {
|
|
|
+ let { rules, defaultRule, enable, notifyFrequency, ruleName, warningType } = newValues
|
|
|
+ let params = rules?.map((item: any) => {
|
|
|
const { field, ...newItem } = item
|
|
|
return {
|
|
|
rule: Object.keys(newItem).map((item: any) => {
|
|
@@ -39,8 +41,11 @@ const AddEdit: React.FC<Props> = (props) => {
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
- console.log('params--->', params);
|
|
|
-
|
|
|
+ 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?.()
|
|
|
+ })
|
|
|
} else {
|
|
|
message.error('请添加最少一项规则')
|
|
|
}
|
|
@@ -55,6 +60,7 @@ const AddEdit: React.FC<Props> = (props) => {
|
|
|
visible={visible}
|
|
|
onOk={handleOk}
|
|
|
width={750}
|
|
|
+ confirmLoading={addSysWarningRule.loading}
|
|
|
onCancel={() => onClose?.()}
|
|
|
>
|
|
|
<Form
|
|
@@ -66,6 +72,7 @@ const AddEdit: React.FC<Props> = (props) => {
|
|
|
initialValues={{
|
|
|
enable: true,
|
|
|
notifyFrequency: 5,
|
|
|
+ defaultRule: false,
|
|
|
rules: [{
|
|
|
field: [],
|
|
|
}]
|
|
@@ -88,15 +95,15 @@ const AddEdit: React.FC<Props> = (props) => {
|
|
|
{Object.keys(WarningTypeEnum).map((item, index) => <Select.Option value={item} key={index}>{WarningTypeEnum[item]}</Select.Option>)}
|
|
|
</Select>
|
|
|
</Form.Item>
|
|
|
- <Form.Item name="ruleName" label={<strong>规则名称</strong>} rules={[{ required: true, message: '请输入规则名称' }]}>
|
|
|
- <Input placeholder="规则名称" />
|
|
|
- </Form.Item>
|
|
|
<Form.Item name="notifyFrequency" label={<strong>通知频率</strong>} rules={[{ required: true, message: '请选择通知频率' }]}>
|
|
|
<InputNumber min={5} addonAfter="分钟" />
|
|
|
</Form.Item>
|
|
|
<Form.Item name="enable" label={<strong>Enable?</strong>} valuePropName="checked" rules={[{ required: true }]}>
|
|
|
<Switch />
|
|
|
</Form.Item>
|
|
|
+ <Form.Item name="defaultRule" label={<strong>是否默认规则</strong>} rules={[{ required: true }]}>
|
|
|
+ <Switch />
|
|
|
+ </Form.Item>
|
|
|
</div>
|
|
|
<Form.List name="rules">
|
|
|
{(fields, { add, remove }) => <>
|