ソースを参照

feat: 增加answer异常判断

whh 4 ヶ月 前
コミット
27513a61ac
1 ファイル変更116 行追加50 行削除
  1. 116 50
      src/views/analyse/WaterView.vue

+ 116 - 50
src/views/analyse/WaterView.vue

@@ -78,72 +78,138 @@ const handleOpenContent = async ({ id, category, reason:title }) => {
   flowParams.simulate = '{}';
 
   answerLoading.value = false;
+  
+  answerResult.value = [];
 
   const { data } = await waterApi.getWaringDetails(id);
-
-  const answer = JSON.parse(data.answer);
   const showVal = JSON.parse(data.showVal);
   const { basic, jsData, csData } = showVal;
- 
-  cancelFetch();
 
-  answerResult.value = [];
+  try {
+    const answer = JSON.parse(data.answer);
+    const reportList = [];
+    const alertList = [];
+    let simulateObj = null;
+  
+    answer.map(item => {
+      const answerObjItem = JSON.parse(item);
+      switch(answerObjItem.biz) {
+        case "DECISION_REPORT":
+          reportList.push(answerObjItem.message);
+          break
+        case "DECISION_ALERT":
+          alertList.push(answerObjItem);
+          break
+        case "DECISION_SIMULATE":
+          console.log( "DECISION_SIMULATE", answerObjItem.message );
+          if (warningActive.value === 1) return; 
+          const { off, on, pred } = JSON.parse(answerObjItem.message);
+          simulateObj = {
+            biz: 'DECISION_SIMULATE',
+            off,
+            on,
+            pred,
+            isDisable: false
+          }
+          modalData.value = simulateObj;
+      }
+    })
 
-  const reportList = [];
-  const alertList = [];
-  let simulateObj = null;
- 
-  answer.map(item => {
-    const answerObjItem = JSON.parse(item);
-    switch(answerObjItem.biz) {
-      case "DECISION_REPORT":
-        reportList.push(answerObjItem.message);
-        break
-      case "DECISION_ALERT":
-        alertList.push(answerObjItem);
-        break
-      case "DECISION_SIMULATE":
-        console.log( "DECISION_SIMULATE", answerObjItem.message );
-        if (warningActive.value === 1) return; 
-        const { off, on, pred } = JSON.parse(answerObjItem.message);
-        console.log( JSON.parse(answerObjItem.message) );
-        simulateObj = {
-          biz: 'DECISION_SIMULATE',
-          off,
-          on,
-          pred,
-          isDisable: false
-        }
-        modalData.value = simulateObj;
+    if ( reportList.length ) {
+      answerResult.value.push({
+        biz: 'DECISION_REPORT',
+        answer: reportList.join(""),
+        loading: false,
+        delayLoading: false
+      })
+    }
+
+    if ( alertList.length ) {
+      const [ parseAnswer ] = alertList.map(item => {
+        item.message = Object.keys(item.message).map(key => ({ ...item.message[key], isActive: null }));
+        return item;
+      })
+      answerResult.value.push({
+        biz: 'DECISION_ALERT',
+        loading: false,
+        delayLoading: false,
+        isAllSelect: false,
+        list: parseAnswer?.message
+      })
     }
-  })
 
-  if ( reportList.length ) {
+    if (simulateObj) {
+      answerResult.value.push(simulateObj);
+    }
+    
+  } catch (error) {
     answerResult.value.push({
       biz: 'DECISION_REPORT',
-      answer: reportList.join(""),
+      answer: data.answer,
       loading: false,
       delayLoading: false
     })
+    console.log("error", error);
   }
 
-  if ( alertList.length ) {
-    const [ parseAnswer ] = alertList.map(item => {
-      item.message = Object.keys(item.message).map(key => ({ ...item.message[key], isActive: null }));
-      return item;
-    })
-    answerResult.value.push({
-      biz: 'DECISION_ALERT',
-      loading: false,
-      delayLoading: false,
-      isAllSelect: false,
-      list: parseAnswer?.message
-    })
-  }
+  cancelFetch();
 
-  if (simulateObj) {
-    answerResult.value.push(simulateObj);
-  }
+  // answerResult.value = [];
+
+  // const reportList = [];
+  // const alertList = [];
+  // let simulateObj = null;
+ 
+  // answer.map(item => {
+  //   const answerObjItem = JSON.parse(item);
+  //   switch(answerObjItem.biz) {
+  //     case "DECISION_REPORT":
+  //       reportList.push(answerObjItem.message);
+  //       break
+  //     case "DECISION_ALERT":
+  //       alertList.push(answerObjItem);
+  //       break
+  //     case "DECISION_SIMULATE":
+  //       console.log( "DECISION_SIMULATE", answerObjItem.message );
+  //       if (warningActive.value === 1) return; 
+  //       const { off, on, pred } = JSON.parse(answerObjItem.message);
+  //       simulateObj = {
+  //         biz: 'DECISION_SIMULATE',
+  //         off,
+  //         on,
+  //         pred,
+  //         isDisable: false
+  //       }
+  //       modalData.value = simulateObj;
+  //   }
+  // })
+
+  // if ( reportList.length ) {
+  //   answerResult.value.push({
+  //     biz: 'DECISION_REPORT',
+  //     answer: reportList.join(""),
+  //     loading: false,
+  //     delayLoading: false
+  //   })
+  // }
+
+  // if ( alertList.length ) {
+  //   const [ parseAnswer ] = alertList.map(item => {
+  //     item.message = Object.keys(item.message).map(key => ({ ...item.message[key], isActive: null }));
+  //     return item;
+  //   })
+  //   answerResult.value.push({
+  //     biz: 'DECISION_ALERT',
+  //     loading: false,
+  //     delayLoading: false,
+  //     isAllSelect: false,
+  //     list: parseAnswer?.message
+  //   })
+  // }
+
+  // if (simulateObj) {
+  //   answerResult.value.push(simulateObj);
+  // }
 
   basic.title = title;
   textDataSources.value = formatToData(basic, '报警值');