shenwu hace 2 años
padre
commit
e403db856b
Se han modificado 1 ficheros con 14 adiciones y 6 borrados
  1. 14 6
      src/components/EarlyWarning/addEdit.tsx

+ 14 - 6
src/components/EarlyWarning/addEdit.tsx

@@ -2,7 +2,7 @@ import { DeleteOutlined, PlusOutlined, QuestionCircleOutlined } from "@ant-desig
 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 React, { useState } from "react"
 import { MonitorFieldEnum, WarningTypeEnum } from "./config"
 import './index.less'
 import PriceInput from "./priceInput"
@@ -19,11 +19,12 @@ const AddEdit: React.FC<Props> = (props) => {
     const { visible, onClose } = props
     const [form] = Form.useForm();
     const rules = Form.useWatch('rules', form);
+    const [errorList, setErrorList] = useState([])
     /******************************/
 
 
     const handleOk = () => {
-        console.log(JSON.stringify(rules));
+        // console.log(JSON.stringify(rules));
         form.validateFields().then(values => {
             console.log(values);
             if (values?.rules) {
@@ -46,7 +47,6 @@ const AddEdit: React.FC<Props> = (props) => {
             }
         })
     }
-
     return <Modal
         title={<Space size={2} align='end'>
             <strong>设置预警</strong>
@@ -98,8 +98,9 @@ const AddEdit: React.FC<Props> = (props) => {
                     <Switch />
                 </Form.Item>
             </div>
-            <Form.List name="rules">
-                {(fields, { add, remove }) => <>
+            <Form.List name="rules"
+            >
+                {(fields, { add, remove }, { errors }) => <>
                     <>{fields.map(({ key, name, ...restField }) => {
                         return <div key={key} style={{ width: '100%' }} className="field">
                             <Space className="field_name">
@@ -136,7 +137,14 @@ const AddEdit: React.FC<Props> = (props) => {
                                 key={index}
                                 label={<strong>{MonitorFieldEnum[field]}</strong>}
                                 name={[name, field]}
-                                rules={[{ required: true, message: '请设置条件' }]}
+                                rules={[{
+                                    required: true, message: MonitorFieldEnum[field] + '的值不能为0', validator(rule, value, callback) {
+                                        if (!value?.value) {
+                                            return Promise.reject()
+                                        }
+                                        return Promise.resolve()
+                                    },
+                                }]}
                             >
                                 <PriceInput />
                             </Form.Item>)}