소스 검색

推送数据异常处理

zhouna 5 년 전
부모
커밋
1d65d03c1b
3개의 변경된 파일53개의 추가작업 그리고 14개의 파일을 삭제
  1. 48 12
      src/common/PushSymptom.vue
  2. 1 1
      src/store.js
  3. 4 1
      src/utils/tools.js

+ 48 - 12
src/common/PushSymptom.vue

@@ -86,7 +86,11 @@
           const result = res.data;
           if (result.code == 0&&result.data) {
             const syms = result.data.symptom;
-            const none={
+            if((!syms||syms.length===0)&&this.extSyms.length===0){
+              this.$emit('warning',"数据异常,请退出重新进入~");
+              return;
+            }
+            /*const none={
               conceptId: 0,
               name: "没有了",
               tagName: "没有了",
@@ -97,11 +101,11 @@
               exclusion:1,
               hasExplain: 0,
               explains: null,
-            };
+            };*/
             //没有了与其他互斥
-            const hasNone = symptoms.indexOf("没有了")!==-1;
+            //const hasNone = symptoms.indexOf("没有了")!==-1;
             const selecteds = this.selecteds;
-            const exts=JSON.parse(JSON.stringify(this.extSyms));
+            const exts=this.getPushExts();
             const newSyms = delResymptoms(exts,syms);
             const newSymsCopy=JSON.parse(JSON.stringify(newSyms));
             const newExt =selecteds.length>0?newSymsCopy.reduce((total,it)=>{
@@ -110,19 +114,51 @@
                 }
               return total;
             },[]):newSyms;
-            if(hasNone){
+            //if(hasNone){
               this.symptoms = [...newExt];
-            }else{
+            /*}else{
               this.symptoms = [none,...newExt];
-            }
+            }*/
             this.symptoms.length=this.symptoms.length>10?10:this.symptoms.length;
-            //this.getSymptomLisCom(result)
           }else{
-            //this.getSymptomLisCom()
+            this.setErrorSymps();
           }
         }).catch((err)=>{
-
-        })
+         this.setErrorSymps();
+        });
+      },
+      setErrorSymps(){
+          const symps = this.getPushExts();
+          const selecteds = this.selecteds;
+          const newExt1 =selecteds.length>0?symps.reduce((total,it)=>{
+            if(selecteds.findIndex((i)=>i.name===it.name)===-1){
+              total.push(it);
+            }
+            return total;
+          },[]):symps;
+        this.symptoms = newExt1;
+        this.symptoms.length=this.symptoms.length>10?10:this.symptoms.length;
+      },
+      getPushExts(){
+        let syms = [];
+        const none={
+          conceptId: 0,
+          name: "没有了",
+          tagName: "没有了",
+          libType: 1,
+          id: 0,
+          type: 1,
+          description: "",
+          exclusion:1,
+          hasExplain: 0,
+          explains: null,
+        };
+        const exts=JSON.parse(JSON.stringify(this.extSyms));
+        if(exts.length===0){
+          return [none];
+        }
+        syms = [none,...exts];
+        return syms;
       },
       showExplain(it){
         if(it.explains){
@@ -208,7 +244,7 @@
       }
     },
     components:{
-      Tiptoast
+      Tiptoast,
     }
   };
 </script>

+ 1 - 1
src/store.js

@@ -148,7 +148,7 @@ const store = new Vuex.Store({
       const temp = formatSymptomData(data);
       state.symptom.origin = temp.newArr;
       state.symptom.datas = JSON.parse(JSON.stringify(temp.newArr));
-      state.extPushSymptom = temp.extSymptoms;
+      state.extPushSymptom = temp.extSymptoms||[];
     },
     setUsualSymptom(state,data){
       const arr = [...data];

+ 4 - 1
src/utils/tools.js

@@ -448,7 +448,10 @@ function getNSum(arr){
 //2数组去重
 function delResymptoms(arr,arr1){
   let idx = -1;
-  const newArr = arr1.reduce((total,it)=>{
+  if(!arr1||arr1.length===0){
+    return arr;
+  }
+  let newArr = arr1.reduce((total,it)=>{
     idx = arr.findIndex((t)=>t.name===it.name);
     if(idx===-1){
       total.push(it);