Ver código fonte

代码简化

liucf 6 anos atrás
pai
commit
68eb8d0701
3 arquivos alterados com 66 adições e 123 exclusões
  1. 62 90
      src/store/actions/currentIll.js
  2. 2 31
      src/store/actions/mainSuit.js
  3. 2 2
      src/utils/config.js

+ 62 - 90
src/store/actions/currentIll.js

@@ -110,7 +110,6 @@ export const setData = (state,action) =>{
   res.symptomIds = JSON.parse(JSON.stringify(mainIds));
   const num = action.info.num;//点击了几次添加病情变化
   const symptomFeature = action.info.symptomFeature;//分词
-  const isChronic = action.info.isChronic;//慢病标识
   let useEmpty,mainData;
   let mainModleData = JSON.parse(JSON.stringify(action.info.mainData));//主诉模板数据
   let moduleData = JSON.parse(JSON.stringify(res.moduleData));//现病史模板
@@ -147,7 +146,6 @@ export const setData = (state,action) =>{
   }
   
   if (useEmpty) {
-    // res.data = res.emptyData;
     res.data = res.emptyData&&res.emptyData.length>0?JSON.parse(JSON.stringify(res.emptyData)):moduleData;
   } else {
     if(mainData&&mainData.length>0){//主诉使用模板
@@ -156,104 +154,85 @@ export const setData = (state,action) =>{
       let main = [];//主症状
       let withs = [];//伴随
       let firstT = 0;
-      for(let i=0; i<mainData.length; i++){
-          if(mainData[i].id==config.tongYId && !mainData[i].pos){//第一个通用特征描述
-            if(mainData[i].value){
-              tongYong = mainData[i].value;
-            }
-          }       
-          else if(mainData[i].exist){
-            mainData[i].exist==1?main.push(mainData[i]):withs.push(mainData[i])
-          }
-          
-          // 处理时间和主诉通用症状--现病史模板无“主诉通用症状” 1-7
-          for(let j=0; j<current.length; j++){
-            if(mainData[i].id==current[j].id && mainData[i].controlType==5){//处理时间,避免手动输入的值
-              firstT++
-              if(mainData[i].value && firstT==1){
-                current[j] = {id:mainData[i].id,name:mainData[i].value,value:mainData[i].value,tagType:config.tagType}
-              }
-            }  
-          }
-        }
+      mainData.map((v,i)=>{
+        // 主诉通用症状描述
+        if(v.id==config.tongYId && v.value && !v.pos){tongYong = v.value;}
+        if(v.exist){v.exist==1?main.push(v):withs.push(v)}
+        // 时间单位
+        if(v.controlType==5&&v.value){
+          firstT++;
+          current.map((it,ii)=>{
+            if(it.id==v.id&& firstT==1){it.value=v.value}
+          })
+        } 
+      })
       
       // 主症状添加tongYong标签选中文字
-      let tongYText = tongYong?{name:tongYong,value:tongYong,tagType:config.tagType}:'';
       let mainCopy = JSON.parse(JSON.stringify(main));
       let manInput = [];
       // 去掉主诉添加的顿号 
-      for(let j=0; j<mainCopy.length; j++){
-        if(tongYText){
-          mainCopy[j].name = tongYong + (mainCopy[j].name).replace('、',"");
-          mainCopy[j].value = tongYong + (mainCopy[j].value).replace('、',"");
+      mainCopy.map((ele,ind)=>{
+        if(tongYong){
+          ele.name = tongYong + (ele.name).replace('、',"");
+          ele.value = tongYong + (ele.value).replace('、',"");
         }else{
-          mainCopy[j].name = (mainCopy[j].name).replace('、',"");
-          mainCopy[j].value = (mainCopy[j].value).replace('、',"");
-        }  
+          ele.name = (ele.name).replace('、',"");
+          ele.value = (ele.value).replace('、',"");
+        }
         //查询是否有手动输入--输入的内容放到最后(3-27)
-        if(mainCopy[j].name != mainCopy[j].value){
-          const inputText = mainCopy[j].value.replace(mainCopy[j].name,"");
+        if(ele.name != ele.value){
+          const inputText = ele.value.replace(ele.name,"");
           const textObj = Object.assign({},JSON.parse(config.textLabel),{name:inputText});
           if(config.textReg.test(inputText)){//包含中英文或数字->即不全是标点符号才插入
              manInput.push(textObj);
           }
-          mainCopy[j].value = mainCopy[j].name;
+          ele.value = ele.name;
         }
-      }
+      })
 
        // 将ids接口获取到的模板匹配到对应主症状后面
       // 主症状
       let newMainCopy = JSON.parse(JSON.stringify(mainCopy));
       let ind = 0;
       let insertInd = 0;
-      // let preLength = 0;
       let lengArr=[];
-      for(let k=0; k <mainCopy.length;k++){
-          mainLabelModuleArr.map((v,i)=>{
-            if(mainCopy[k].id==v.id){
-              ind++;
-              let items = v.questionMapping.filter((item)=>{
-                              return item.symptomType==0||item.symptomType==1;
-                            })          
-              lengArr[k] = items.length;  //每一个主诉尾巴长度 
-              
-              if(items.length==0){//没有尾巴时给症状后加逗号(3.5)
-                for(let j=0; j<newMainCopy.length; j++){
-                  if(newMainCopy[j].id==mainCopy[k].id){
-                    // newMainCopy[j].value = newMainCopy[j].name = mainCopy[k].value+',';
-                    newMainCopy[j].value = newMainCopy[j].name = mainCopy[k].value||mainCopy[k].name+',';
-                  }
+      mainCopy.map((it,ii)=>{
+        mainLabelModuleArr.map((v,i)=>{
+          if(it.id==v.id){
+            ind++;
+            let items = v.questionMapping.filter((item)=>{
+                            return item.symptomType==0||item.symptomType==1;
+                          })          
+            lengArr[ii] = items.length;  //每一个主诉尾巴长度            
+            if(items.length==0){//没有尾巴时给症状后加逗号(3.5)
+              newMainCopy.map((el,ind)=>{
+                if(el.id==it.id){
+                  el.value = el.name = (it.value||it.name)+',';
                 }
-              }       
-              /*if(ind==1){
-                preLength = items.length;
-              }else{
-                insertInd += preLength;
-              }*/
-              if(ind>1){
-                insertInd += lengArr[k-1];
-              }
-              newMainCopy.splice(k+insertInd+1,0,...items);
-            }
+              })
+            } 
+            if(ind>1){  insertInd += lengArr[ii-1]; }
+            newMainCopy.splice(ii+insertInd+1,0,...items);
+          }
         })
-      }
+      })
       // 伴随
       // 去掉顿号
       let newWiths = [];
       let manWithInput = [];
       if(withs.length>0){
-        for(let b=0; b<withs.length; b++){
-          withs[b].name = withs[b].name.replace('、',"");
-          withs[b].value = withs[b].value.replace('、',"");
-          if(withs[b].name != withs[b].value){
-            const inputText = withs[b].value.replace(withs[b].name,"");
+        withs.map((v,i)=>{
+          v.name = v.name.replace('、',"");
+          v.value = v.value.replace('、',"");
+          if(v.name != v.value){
+            const inputText = v.value.replace(v.name,"");
             const textObj = Object.assign({},JSON.parse(config.textLabel),{name:inputText});
             if(config.textReg.test(inputText)){//包含中英文或数字->即不全是标点符号才插入
               manWithInput.push(textObj);
             }           
-            withs[b].value = withs[b].name;  
+            v.value = v.name;  
           }
-        }
+        })
         newWiths = JSON.parse(JSON.stringify(withs));
         let withInd = 0;
         let withInsertInd = 0;
@@ -265,19 +244,13 @@ export const setData = (state,action) =>{
               let items = v.questionMapping.filter((item)=>{
                               return item.symptomType==0||item.symptomType==2;
                             })
-              /*if(withInd==1){
-                withPreLength = items.length;
-              }else{
-                withInsertInd += withPreLength;
-              }*/
               withLengArr[d] = items.length;
               if(items.length==0){//没有尾巴时给症状后加逗号(3.5)
-                for(let j=0; j<newWiths.length; j++){
-                  if(newWiths[j].id==withs[d].id){
-                    // newWiths[j].value = newWiths[j].name = withs[d].value+',';
-                    newWiths[j].value = newWiths[j].name = withs[d].value||withs[d].name+',';
+                newWiths.map((it,ind)=>{
+                  if(it.id==withs[d].id){
+                    it.value = it.name = (withs[d].value||withs[d].name)+',';
                   }
-                }
+                })
               }
               if(withInd>1){
                 withInsertInd += withLengArr[d-1];
@@ -292,11 +265,11 @@ export const setData = (state,action) =>{
       let newSymptomArr = formatContinueDots(JSON.parse(JSON.stringify(symptomArr)));   //过来连续标点
       //组装好的主症状和伴随症状插入现病史模板(flag=4前)
       let insertIdx = null;
-      for(let j=0; j<current.length; j++){
-          if(current[j].flag && current[j].flag==4){
-            insertIdx = j;  
-          }
+      current.map((item,i)=>{
+        if(item.flag&& item.flag==4){
+          insertIdx = i;
         }
+      })
    
       for(let k=0; k<newSymptomArr.length; k++){
         let pos = insertIdx+k;
@@ -314,17 +287,17 @@ export const setData = (state,action) =>{
           mainLabelModuleArr.map((v,i)=>{
             if(symptomFeature[k].id==v.id){
               ind++;
-              let items = v.questionMapping.filter((item)=>{
+              let items = v.questionMapping&&v.questionMapping.filter((item)=>{
                               return item.symptomType==0||item.symptomType==1;
                             })          
               lengArr[k] = items.length;  //每一个主诉尾巴长度 
               
-              if(items.length==0){//没有尾巴时给症状后加逗号(3.5)
-                for(let j=0; j<featureData.length; j++){
-                  if(featureData[j].id==symptomFeature[k].id){
-                    featureData[j].value = featureData[j].name = symptomFeature[k].value||symptomFeature[k].name+',';
+              if(items&&items.length==0){//没有尾巴时给症状后加逗号(3.5)
+                featureData.map((ele,ind)=>{
+                  if(ele.id==symptomFeature[k].id){
+                    ele.value = ele.name = (symptomFeature[k].value||symptomFeature[k].name)+',';
                   }
-                }
+                })
               }
               if(ind>1){
                 insertInd += lengArr[k-1];
@@ -388,7 +361,6 @@ export const confirm = (state,action) =>{
     // for(let i in withs){
     for(let i=0;i<withs.length; i++){
       withsArr.splice(parseInt(ikey)+length,0,banText,getLabel(withs[i].id,withs[i].questionMapping && withs[i].questionMapping.length==0?(withs[i].name+','):(withs[i].name)),...(withs[i].questionMapping&&withs[i].questionMapping.length>0?withs[i].questionMapping.filter((item)=>{return item.symptomType==0||item.symptomType==2;}):[]));
-      /*withsArr.splice(parseInt(ikey)+length,0,getLabel(withs[i].id,withs[i].questionMapping && withs[i].questionMapping.length==0?(ban.name+withs[i].name+','):(ban.name+withs[i].name)),...(withs[i].questionMapping && withs[i].questionMapping.filter((item)=>{return item.symptomType==0||item.symptomType==2;})));*/
     }
   }
 

+ 2 - 31
src/store/actions/mainSuit.js

@@ -303,9 +303,7 @@ export const confirm = (state,action) =>{
         }
       }
     }
-  }
-
-    
+  }    
     res.data = arr;
     res.saveText = fullfillText(arr).saveText;
     res.update=Math.random();
@@ -360,43 +358,18 @@ export const insertSearch = (state,action)=>{
       }
     })
     // flag=1前是文本标签就替换,否则插入
-    // const iftext = moduleData[inserIndx-1].tagType;
     const iftext = inserIndx&&moduleData[inserIndx-1]&&moduleData[inserIndx-1].tagType;
     if(iftext==config.tagType){
        moduleData.splice(inserIndx-1,1,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1});
      }else{
        moduleData.splice(inserIndx,0,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1});
-     }
-    // moduleData.splice(inserIndx,0,{id:id,name:searchData,value:searchData,tagType:config.tagType,exist:1},emptySpan);   
+     }  
     res.saveText = [];//将手动输入的值清掉
     res.data = moduleData;
-    // res.saveText[inserIndx] = searchData;
     res.saveText = fullfillText(res.data).saveText;
-    // res.saveText[inserIndx] = searchData;
     res.mainIds.push(id);
     res.editClear = false;//主诉框编辑状态
   }else{
-    // 替换
-    /*span.current.innerText = '';
-    res.data.splice(focusIndex,1,text);
-    res.saveText[focusIndex] = searchData;
-    res.mainIds.push(id);*/
-    // 追加--前or后?searchStr
-    /*const searchStr = res.searchStr;
-    let innerText = span.current.innerText;
-    let index = innerText.indexOf(searchStr);
-    let value;
-    if(index <= 1){//前
-      value = innerText.replace(searchStr,searchData);
-    }else{
-      let temp = innerText.substring(0,innerText.lastIndexOf(searchStr));
-      value = temp + searchData;
-    }
-    // let value = innerText + searchData;
-    span.current.innerText = value;
-    res.data[focusIndex].value = value;
-    res.saveText[focusIndex] = value;*/
-
     /*******************第一病程搜索结果也移植到现病史修改(2-18)********************/
     // 位置判断-第一病程-主症状还是伴随 前一个标签存在 并且没有pos;
     // 判断在伴的前面还是后面:前exist=1(主),后exist=2(伴)
@@ -417,7 +390,6 @@ export const insertSearch = (state,action)=>{
       }
     }
     
-
     // 从新插入一个span标签
     const searchStr = res.searchStr;
     let innerText = span.current.innerText || span.current.innerHTML;
@@ -441,7 +413,6 @@ export const insertSearch = (state,action)=>{
     span.current.innerText?(span.current.innerText = value):(span.current.innerHTML=value);
     res.mainIds.push(id);
   }
-  // console.log(456,res,action);
   res.update=Math.random();
   return res;
 }

+ 2 - 2
src/utils/config.js

@@ -1,7 +1,7 @@
 // const host='http://192.168.3.1:5050';//赵
 // const host='http://192.168.3.100:5050';//王峰
-const host='http://192.168.2.241:5050';//后端接口访问地址
-// const host='http://192.168.2.236:5050';//后端接口访问地址
+// const host='http://192.168.2.241:5050';//后端接口访问地址
+const host='http://192.168.2.236:5050';//后端接口访问地址
 // const host='http://192.168.3.11:5050';//王宇
 //const host='http://192.168.2.164:8080';
 // const host='http://192.168.3.117:5050'; //周铁刚