|
@@ -0,0 +1,140 @@
|
|
|
+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 React from "react"
|
|
|
+import { MonitorFieldEnum } from "./config"
|
|
|
+import './index.less'
|
|
|
+import PriceInput from "./priceInput"
|
|
|
+
|
|
|
+
|
|
|
+interface Props {
|
|
|
+ visible?: boolean
|
|
|
+ onClose?: () => void
|
|
|
+ onChange?: () => void
|
|
|
+}
|
|
|
+const AddEdit: React.FC<Props> = (props) => {
|
|
|
+
|
|
|
+ /******************************/
|
|
|
+ const { visible, onClose } = props
|
|
|
+ const [form] = Form.useForm();
|
|
|
+ const rules = Form.useWatch('rules', form);
|
|
|
+ /******************************/
|
|
|
+
|
|
|
+
|
|
|
+ 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) => {
|
|
|
+ const { field, ...newItem } = item
|
|
|
+ return {
|
|
|
+ rule: Object.keys(newItem).map((item: any) => {
|
|
|
+ return {
|
|
|
+ ...newItem[item],
|
|
|
+ field: item
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ console.log('params--->', params);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ message.error('请添加最少一项规则')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return <Modal
|
|
|
+ title={<Space size={2} align='end'>
|
|
|
+ <strong>设置预警</strong>
|
|
|
+ <span style={{ fontSize: 12, color: 'red' }}>(条件与条件之间是或者关系,条件内字段是并且关系, 满足任意一条件立即触发报警提醒)</span>
|
|
|
+ </Space>}
|
|
|
+ visible={visible}
|
|
|
+ onOk={handleOk}
|
|
|
+ width={750}
|
|
|
+ onCancel={() => onClose?.()}
|
|
|
+ >
|
|
|
+ <Form
|
|
|
+ name="dynamic_form_nest_item"
|
|
|
+ form={form}
|
|
|
+ className="addEdit_form"
|
|
|
+ labelCol={{ span: 5 }}
|
|
|
+ colon={false}
|
|
|
+ initialValues={{
|
|
|
+ enable: true,
|
|
|
+ notifyFrequency: 5,
|
|
|
+ rules: [{
|
|
|
+ field: [],
|
|
|
+ }]
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div style={{ padding: '0 4px' }}>
|
|
|
+ <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">
|
|
|
+ <Switch />
|
|
|
+ </Form.Item>
|
|
|
+ </div>
|
|
|
+ <Form.List name="rules">
|
|
|
+ {(fields, { add, remove }) => <>
|
|
|
+ <>{fields.map(({ key, name, ...restField }) => {
|
|
|
+ return <div key={key} style={{ width: '100%' }} className="field">
|
|
|
+ <Space className="field_name">
|
|
|
+ <span>条件{key + 1}</span>
|
|
|
+ {fields.length > 1 && <Popconfirm
|
|
|
+ title="确定删除"
|
|
|
+ onConfirm={() => remove(name)}
|
|
|
+ okText="Yes"
|
|
|
+ cancelText="No"
|
|
|
+ >
|
|
|
+ <DeleteOutlined style={{ color: 'red' }} />
|
|
|
+ </Popconfirm>}
|
|
|
+ </Space>
|
|
|
+ <Form.Item
|
|
|
+ {...restField}
|
|
|
+ label={<strong>字段</strong>}
|
|
|
+ name={[name, 'field']}
|
|
|
+ rules={[{ required: true, message: '请选择字段' }]}
|
|
|
+ >
|
|
|
+ <Select
|
|
|
+ mode="multiple"
|
|
|
+ showSearch
|
|
|
+ allowClear
|
|
|
+ placeholder="选择要设置的字段"
|
|
|
+ filterOption={(input, option) =>
|
|
|
+ ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
|
|
|
+ }
|
|
|
+ >
|
|
|
+ {Object.keys(MonitorFieldEnum).map((item, index) => <Select.Option disabled={rules?.[key]?.['field']?.length >= 3 && !rules?.[key]['field'].includes(item)} value={item} key={index}>{MonitorFieldEnum[item]}</Select.Option>)}
|
|
|
+ </Select>
|
|
|
+ </Form.Item>
|
|
|
+ {rules?.[key]?.['field']?.map((field: string, index: number) => <Form.Item
|
|
|
+ {...restField}
|
|
|
+ key={index}
|
|
|
+ label={<strong>{MonitorFieldEnum[field]}</strong>}
|
|
|
+ name={[name, field]}
|
|
|
+ rules={[{ required: true, message: '请设置条件' }]}
|
|
|
+ >
|
|
|
+ <PriceInput />
|
|
|
+ </Form.Item>)}
|
|
|
+ </div>
|
|
|
+ })}</>
|
|
|
+
|
|
|
+ <Form.Item>
|
|
|
+ <Button type="dashed" onClick={() => add()} block icon={<PlusOutlined />}>新增条件</Button>
|
|
|
+ </Form.Item>
|
|
|
+ </>}
|
|
|
+ </Form.List>
|
|
|
+
|
|
|
+ </Form>
|
|
|
+ </Modal>
|
|
|
+}
|
|
|
+
|
|
|
+export default React.memo(AddEdit)
|