wjx hace 2 años
padre
commit
c69a8fd0dd
Se han modificado 1 ficheros con 12 adiciones y 5 borrados
  1. 12 5
      src/components/EarlyWarning/addEdit.tsx

+ 12 - 5
src/components/EarlyWarning/addEdit.tsx

@@ -25,7 +25,7 @@ const AddEdit: React.FC<Props> = (props) => {
 
 
     const handleOk = () => {
-        console.log(JSON.stringify(rules));
+        // console.log(JSON.stringify(rules));
         form.validateFields().then(values => {
             if (values?.rules) {
                 let newValues = JSON.parse(JSON.stringify(values))
@@ -51,7 +51,6 @@ const AddEdit: React.FC<Props> = (props) => {
             }
         })
     }
-
     return <Modal
         title={<Space size={2} align='end'>
             <strong>设置预警</strong>
@@ -105,8 +104,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">
@@ -143,7 +143,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>)}