Pārlūkot izejas kodu

数据权限-修改-

zhouna 3 gadi atpakaļ
vecāks
revīzija
15b8efe965

+ 22 - 18
src/components/DataManager/AddData.js

@@ -45,7 +45,7 @@ function AddData(props) {
   const staticInfo = useSelector(state => {
     return state.staticInfo;
   });
-  const { dataList } = staticInfo;console.log('formData:',formData)
+  const { dataList } = staticInfo;
   const initialValues = formData
   const validateMessages = {
     required: '${label}不能为空',
@@ -68,7 +68,7 @@ function AddData(props) {
         const data = authChecksArr[tabIndex]||{};
         const sysObj = form.getFieldValue().softwareVOS[tabIndex]||{};
         const dataType = sysObj.dataType;
-        const isCustom = dataType === '7';console.log(form.getFieldValue(),dataType,isCustom)
+        const isCustom = dataType === '7';
         //判断权限范围类型,是否显示自定义内容
         setShowCustom(isCustom);
         if(!isCustom||!data){      //非自定义不处理
@@ -77,12 +77,15 @@ function AddData(props) {
         const depts = data.depts||[];
         const doctors = data.doctors||[];
         const hospitals = data.hospitals||[];
+        const hosIds = filterIds(hospitals);
+        const deptIds = filterIds(depts);
         setCheckedUser(doctors);
-        setCheckedUserIds(filterIds(doctors,'name'));
-        setCheckedHosIds(filterIds(hospitals,'name'));
+        setCheckedUserIds(filterIds(doctors,['id','name']));
+        setCheckedTreeItems(filterIds(hospitals,['hospitalId','hospitalName','id','name'],true));
+        setCheckedHosIds(hosIds);
         //setHosArr(hospitals||[]);
         setCheckedDepts([...hospitals,...depts]);
-        setCheckedDeptIds(filterIds((hospitals).concat(depts)));
+        setCheckedDeptIds(hosIds.concat(deptIds));
     }
   //获取当前用于所属角色
   function getCreateRoles(softwareId) {
@@ -138,21 +141,24 @@ function AddData(props) {
     arr[tabIndex].id = tabKey
     arr[tabIndex].softwareMenuIds = []
     arr[tabIndex].dataAuthDetails = []
-    arr[tabIndex].selectedRowKeys = []
+    //arr[tabIndex].selectedRowKeys = []
     if (e.target.value !== '7') {
+      setShowCustom(false);
       arr[tabIndex].dataAuthDetails = [{
         dataType: e.target.value
       }]
+    }else{
+        setShowCustom(true);
     }
-    tags[tabIndex] = []
+    //tags[tabIndex] = []
     val[i] = e.target.value
-    selectedRowKeys[tabIndex] = []
+    //selectedRowKeys[tabIndex] = []
     form.setFieldsValue({
       softwareVOS: arr
     });
-    setTags([...tags])
-    setValue([...val])
-    setSelectedRowKeys([...selectedRowKeys])
+    //setTags([...tags])
+    //setValue([...val])
+    //setSelectedRowKeys([...selectedRowKeys])
     setIsChange(true)
   };
 
@@ -208,7 +214,7 @@ function AddData(props) {
     });
     const docArr = unique(arr);
     formData.softwareVOS[tabIndex].dataAuthDetails = [...docArr,...checkedDepts];
-    formData.softwareVOS[tabIndex].selectedRowKeys = selectedRowKeys;
+    //formData.softwareVOS[tabIndex].selectedRowKeys = selectedRowKeys;
     form.setFieldsValue({
       softwareVOS: formData.softwareVOS
     });
@@ -226,11 +232,11 @@ function AddData(props) {
         });
         //console.log('排序后:',posArr);
         const structDepts = structureDeptTag(posArr);
-        const {deptIds,hosIds,paramHos,paramDept} = structDepts;console.log('选中:',checkedDepts)
+        const {deptIds,hosIds,paramHos,paramDept} = structDepts;
         let deptIdsArr=[...deptIds];
         let deptArr=[...paramDept];
         let hosIdsArr=[...hosIds];
-        let hosArr=[...paramHos];
+        let hosArr=[...paramHos];console.log('树选中:',hosIdsArr)
         setCheckedDepts(hosArr.concat(deptArr));        //显示的排序可能需要再考虑一下
         setCheckedDeptIds(deptIdsArr);
         setCheckedHosIds(hosIdsArr);
@@ -328,7 +334,7 @@ function AddData(props) {
         }
     }
 
-  const onFinish = value => {
+  const onFinish = () => {
       console.log(form.getFieldsValue());
     save(form.getFieldsValue())
   };
@@ -390,9 +396,7 @@ function AddData(props) {
                             </Form.Item>
                           </TabPane>
                           <TabPane tab="可看科室" key="1" forceRender={isEdit && form.getFieldValue().softwareVOS[i] ? true : false}>
-                            <Form.Item
-                              name={['softwareVOS', i, 'softwareMenuIds']}
-                            >
+                            <Form.Item>
                               <MyDeptStruct checkeds={checkedTreeItems} checkEv={handleCheckDept} />
                             </Form.Item>
                           </TabPane>

+ 1 - 1
src/components/DataManager/doctorList.js

@@ -15,7 +15,7 @@ function DoctorList(props) {
     getHospitalTree()
   }, []);
 
-  const { checkeds, checkDoct } = props;console.log("选中:",checkeds)
+  const { checkeds, checkDoct } = props;
   const [form] = Form.useForm();
   const [doctorList, setDoctorList] = useState([]);
   const [name, setName] = useState("");

+ 6 - 2
src/components/DataManager/index.js

@@ -126,7 +126,7 @@ function DataManager() {
             const {id,name,roles,dataAuthDetail,dataType} = software;
             const {depts,doctors,hospitals} = dataAuthDetail||{};
             tempArr = [...depts||[],...doctors||[],...hospitals||[]];
-            checkedsObj[i] = dataAuthDetail;
+            checkedsObj[i] = fullfillVals(dataAuthDetail);
             authArr[i] = {
                 id,name,dataType:(dataType||'')+''||'7',roles:filterIds(roles||[]),dataAuthDetails:dataType==='7'?tempArr:null
             };
@@ -210,7 +210,11 @@ function DataManager() {
         setFormData(formObj)    //表单数据
         setaddVisible(true);
     }
-
+  function fullfillVals(data){
+    data.map((it)=>{
+      return Object.assign(it,{dataType:'7',detailId:it.id});
+    })
+  }
   //保存
   function addData(formData) {
     let url = api.addAuth;

+ 8 - 3
src/utils/index.js

@@ -67,12 +67,17 @@ function getValueFromEvent(e) {
     return e.target.value.replace(/(^\s*)|(\s*$)/g, '');
 }
 //从对象数组中遍历出id
-function filterIds(arr,str){    //arr需遍历的数组,str需拼接的字段
+function filterIds(arr,str){    //arr需遍历的数组;str需拼接的字段数组
+    let tempStr = '',temp='';
     return arr.map((it)=>{
         if(str){
-            return it.id+'-'+it[str];
+            str.map((t,i)=>{
+                temp = it[t]||'';
+                tempStr = i===0?temp:(tempStr +(tempStr?"-"+temp:temp));
+            });
+            return tempStr;
         }
-        return it.id
+        return it.id+''
     })
 }
 const obj = {