Selaa lähdekoodia

修改/新增添加校验

zsw007 3 vuotta sitten
vanhempi
commit
ef12ecb6bd

+ 7 - 1
src/components/DictManager/AddDict.js

@@ -152,9 +152,14 @@ import React, {
         }
       })
     }
+
     function cancel() {
-      props.userChange()
+      props.cancel()
     }
+      
+      function onValuesChange() {
+        props.isChange(form.isFieldsTouched())
+      }
   
     return (
       <>
@@ -165,6 +170,7 @@ import React, {
           name="register"
           onFinish={onFinish}
           initialValues={initialValues}
+          onValuesChange={onValuesChange}
         >
           <Form.Item
             name="groupType"

+ 48 - 70
src/components/DictManager/index.js

@@ -33,6 +33,8 @@ function DictManager() {
   const [groupTypeList, setGroupTypeList] = useState([]);
   const [total, setTotal] = useState(0);
   const [current, setCurrent] = useState(1);
+  const [revise, setRevise] = useState(false);//是否修改 新增修改内容
+  const [unsaved, setUnsaved] = useState(false);// 修改未保存弹窗
   const [params, setParams] = useState({
     pages: 1,
     current: 1,
@@ -111,60 +113,6 @@ function DictManager() {
     })
   }
 
-  // 处理组织结构数据回显
-  function getHospitals(arr) {
-    arr.forEach((item, i, array) => {
-      item.value = item.hospitalId
-      item.title = item.hospitalName
-      if (!item.children && item.depts) {
-        item.depts.forEach(it => {
-          it.value = item.parentId + '-' + it.deptId
-          if (it.relation == 1) {
-            list.push(it.value)
-          }
-        })
-      }
-      if (item.type != 0 && item.relation == 1) {
-        list.push(item.value)
-        console.log(list)
-      }
-      if (item.children) {
-        getHospitals(item.children)
-      }
-    })
-    return list
-  }
-
-  // 禁用/启用接口
-  function disableUser(id, status) {
-    const param = { id: id, status: status };
-    xPost(api.disableUser, param).then((res) => {
-      if (res.data.code === 200) {
-        getDictionary();
-        setMsvisible(false);
-        message.success((status ? '启用' : '禁用') + "成功");
-      } else {
-        message.warning(res.data.msg || '操作失败');
-      }
-    }).catch(() => {
-      message.error("接口出错");
-    });
-  }
-
-  //重置密码
-  function onResetPsd(id) {
-    const param = { id: id };
-    xPost(api.resetPasswordUser, param).then((res) => {
-      if (res.data.code === 200) {
-        getDictionary();
-        message.success("重置成功");
-      } else {
-        message.warning(res.data.msg || '操作失败');
-      }
-    }).catch(() => {
-      message.error("接口出错");
-    });
-  }
 
   //删除
   function deleteDictionary() {
@@ -173,6 +121,7 @@ function DictManager() {
       if (res.data.code === 200) {
         getDictionary();
         setMsvisible(false);
+        setDictId(null)
         message.success("删除成功");
       } else {
         message.warning(res.data.msg || '操作失败');
@@ -229,24 +178,43 @@ function DictManager() {
     setModalType(type)
   }
 
-  //提示框确认事件
-  function handleOk() {
-    if (modalType == 1) {
-      deleteDictionary(id)
-    } else if (modalType == 2) {
-      disableUser(id, 0)
-    } else if (modalType == 3) {
-      onResetPsd(id);
-    }
-  }
   //提示框取消
-  function handleCancel() {
+  function deleteCancel() {
     setMsvisible(false);
   }
+  // 新增修改 取消/关闭
   function cancel() {
+    if(revise){
+      setUnsaved(true)
+    }else{
+      setVisible(false)
+      setFormData(null)
+    }
+  }
+
+  function isChange(tog){
+    setRevise(tog)
+  }
+
+  function addCancel() {
+    setRevise(false)
     setVisible(false)
+    setUnsaved(false)
     setFormData(null)
   }
+    
+  function unsavedCancel() {
+      setUnsaved(false)
+  }
+
+    // 保存 新增修改
+    function userChange() {
+       setRevise(false)
+        setVisible(false)
+        getDictionary()
+    }
+
+
   function userChange() {
     let val = form.getFieldsValue()  // 页面刷新
     const param = {
@@ -363,9 +331,19 @@ function DictManager() {
           forceRender={true}
         >
           <UserContext.Provider value={{ id, type, formData, dictList }}>
-            <AddUser userChange={userChange} />
+            <AddUser userChange={userChange} cancel={cancel} isChange={isChange} />
           </UserContext.Provider>
-
+          <Modal
+            title="提示"
+            okText='确定'
+            cancelText='取消'
+            width={400}
+            visible={unsaved}
+            onOk={addCancel}
+            onCancel={unsavedCancel}
+            >
+                <p>当前数据未保存 是否确认关闭?</p>
+				  </Modal>
         </Modal>
         : ''}
       <Modal
@@ -374,10 +352,10 @@ function DictManager() {
         cancelText='取消'
         width={400}
         visible={msvisible}
-        onOk={handleOk}
-        onCancel={handleCancel}
+        onOk={deleteDictionary}
+        onCancel={deleteCancel}
       >
-        <p>{tipText[modalType]}</p>
+        <p>确定要删除该参数?</p>
       </Modal>
     </div >
   )

+ 10 - 53
src/components/ParaManager/AddPara.js

@@ -21,7 +21,6 @@ function AddPara(props) {
   const { id, type, formData, roleList } = useContext(UserContext);
   const [treeData, setTreeData] = useState([]);
   const [treeRloe, setTreeRloe] = useState([]);
-  const [hospitalNamesList, setHospitalNamesList] = useState([]);
   const [addHospitalTreeVO, setAddHospitalTreeVO] = useState({
     depts: [],
     hospitals: []
@@ -54,16 +53,7 @@ function AddPara(props) {
       }
     })
   }
-  function addAttr(data) {
-    for (var j = 0; j < data.length; j++) {
-      data[j].title = data[j].name //添加title属性
-      data[j].key = data[j].code //添加key属性
-      if (data[j].children.length > 0) {
-        addAttr(data[j].children)
-      }
-    }
-    return data
-  }
+  
   //获取当前用于所属角色
   function getCreateRoles() {
     const params = {
@@ -88,32 +78,7 @@ function AddPara(props) {
   function swichChange(val) {
     form.setFieldsValue({ status: val ? 1 : 0 })
   }
-  // 判断元素存在格式
-  function getSameNum(val, arr) {
-    let processArr = arr.filter(function (value) {
-      return value == val;
-    })
-    return processArr.length;
-  }
-  //递归获取科室
-  function gethospitals(arr, val) {
-    arr.forEach(item => {
-      if (item.value == val) {
-        if (item.children) {
-          getdepts(item.children)
-        }
-        if (item.children && item.depts) {
-          item.children.forEach(item => {
-            addHospitalTreeVOs.depts.push(item.value.split('-')[1])
-          })
-        }
-      } else {
-        if (item.children) {
-          gethospitals(item.children, val)
-        }
-      }
-    })
-  }
+  
   //递归获取医院
   function getdepts(arr) {
     arr.forEach(item => {
@@ -131,21 +96,7 @@ function AddPara(props) {
       }
     })
   }
-  const onChange = value => {
-    value.forEach(it => {
-      if (JSON.stringify(it).indexOf('-') > 0) {
-        addHospitalTreeVOs.depts.push(it.split('-')[1])
-      } else {
-        addHospitalTreeVOs.hospitals.push(it)
-        gethospitals(treeData, it)
-      }
-    })
-    setAddHospitalTreeVO(addHospitalTreeVOs)
-    console.log(form.getFieldsValue())
-  };
-  const onChangeRloe = value => {
-    form.setFieldsValue({ roles: value })
-  };
+  
   // 点击保存
   const onFinish = values => {
     let params = values
@@ -185,9 +136,14 @@ function AddPara(props) {
       }
     })
   }
+
   function cancel() {
-    props.userChange()
+    props.cancel()
   }
+    
+    function onValuesChange() {
+      props.isChange(form.isFieldsTouched())
+    }
 
   return (
     <>
@@ -198,6 +154,7 @@ function AddPara(props) {
         name="register"
         onFinish={onFinish}
         initialValues={initialValues}
+        onValuesChange={onValuesChange}
       >
         <Form.Item
           name="hospitalName"

+ 62 - 19
src/components/ParaManager/index.js

@@ -28,14 +28,14 @@ function DictManager() {
   const [modalType, setModalType] = useState("");
   const [type, setType] = useState("");
   const [formData, setFormData] = useState(null);
-  const [username, setUsername] = useState(null);
-  const [roleList, setRoleList] = useState([]);
   const [size, setSize] = useState(15);
   const [HospitalNamesList, setHospitalNamesList] = useState([]);
   const [total, setTotal] = useState(0);
   const [current, setCurrent] = useState(1);
   const { organizationData } = utils;
   const { SHOW_PARENT } = TreeSelect;
+  const [revise, setRevise] = useState(false);//是否修改 新增修改内容
+  const [unsaved, setUnsaved] = useState(false);// 修改未保存弹窗
   const [addHospitalTreeVO, setAddHospitalTreeVO] = useState({
     depts: [],
     hospitals: []
@@ -213,6 +213,7 @@ function DictManager() {
       if (res.data.code === 200) {
         getHospitalSet();
         setMsvisible(false);
+        setParaId(null)
         message.success((status ? '启用' : '禁用') + "成功");
       } else {
         message.warning(res.data.msg || '操作失败');
@@ -244,6 +245,7 @@ function DictManager() {
       if (res.data.code === 200) {
         getHospitalSet();
         setMsvisible(false);
+        setParaId(null)
         message.success("删除成功");
       } else {
         message.warning(res.data.msg || '操作失败');
@@ -294,23 +296,53 @@ function DictManager() {
   }
 
   //提示框确认事件
-  function handleOk() {
-    if (modalType == 1) {
-      deleteHospitalSet(id)
-    } else if (modalType == 2) {
-      disableUser(id, 0)
-    } else if (modalType == 3) {
-      onResetPsd(id);
-    }
-  }
-  //提示框取消
-  function handleCancel() {
+  // function handleOk() {
+  //   if (modalType == 1) {
+  //     deleteHospitalSet(id)
+  //   } else if (modalType == 2) {
+  //     disableUser(id, 0)
+  //   } else if (modalType == 3) {
+  //     onResetPsd(id);
+  //   }
+  // }
+  
+  // 确认删除是否继续
+  function deleteCancel() {
     setMsvisible(false);
   }
+
+  // 新增修改 取消/关闭
   function cancel() {
+    if(revise){
+      setUnsaved(true)
+    }else{
+      setVisible(false)
+      setFormData(null)
+    }
+  }
+
+  function isChange(tog){
+    setRevise(tog)
+  }
+
+  function addCancel() {
+    setRevise(false)
     setVisible(false)
+    setUnsaved(false)
     setFormData(null)
   }
+    
+  function unsavedCancel() {
+      setUnsaved(false)
+  }
+
+    // 保存 新增修改
+    function userChange() {
+       setRevise(false)
+        setVisible(false)
+        getHospitalSet()
+    }
+
   function userChange() {
     let val = form.getFieldsValue()  // 页面刷新
     const param = {
@@ -439,22 +471,33 @@ function DictManager() {
           footer={null}
           forceRender={true}
         >
-          <UserContext.Provider value={{ id, type, formData, dictList }}>
-            <AddUser userChange={userChange} />
+          <UserContext.Provider value={{type, formData }}>
+            <AddUser userChange={userChange}  cancel={cancel} isChange={isChange} />
           </UserContext.Provider>
-
+          <Modal
+            title="提示"
+            okText='确定'
+            cancelText='取消'
+            width={400}
+            visible={unsaved}
+            onOk={addCancel}
+            onCancel={unsavedCancel}
+            >
+                <p>当前数据未保存 是否确认关闭?</p>
+				  </Modal>
         </Modal>
         : ''}
+      
       <Modal
         title="提示"
         okText='确定'
         cancelText='取消'
         width={400}
         visible={msvisible}
-        onOk={handleOk}
-        onCancel={handleCancel}
+        onOk={deleteHospitalSet}
+        onCancel={deleteCancel}
       >
-        <p>{tipText[modalType]}</p>
+        <p>确定要删除该参数?</p>
       </Modal>
     </div >
   )