Sfoglia il codice sorgente

套题答案bugfix

zhangjie 2 anni fa
parent
commit
ccea2cafd3
1 ha cambiato i file con 28 aggiunte e 7 eliminazioni
  1. 28 7
      src/modules/question/components/QuestionImportEdit.vue

+ 28 - 7
src/modules/question/components/QuestionImportEdit.vue

@@ -220,9 +220,9 @@ export default {
     getCachePaperInfo(paperData, cacheFields = []) {
       let cachePaperInfo = {};
       paperData.forEach((detail, dIndex) => {
-        detail.questionInfo.forEach((question) => {
+        detail.questionInfo.forEach((question, qIndex) => {
           let info = {};
-          let k = `${dIndex + 1}_${question.number}`;
+          let k = `${dIndex + 1}_${qIndex + 1}`;
           if (cacheFields.length) {
             cacheFields.forEach((field) => {
               info[field] = question[field];
@@ -232,6 +232,22 @@ export default {
           }
 
           cachePaperInfo[k] = info;
+
+          if (question.subQuestions && question.subQuestions.length) {
+            question.subQuestions.forEach((subq, subqIndex) => {
+              let info = {};
+              let k = `${dIndex + 1}_${qIndex + 1}_${subqIndex + 1}`;
+              if (cacheFields.length) {
+                cacheFields.forEach((field) => {
+                  info[field] = subq[field];
+                });
+              } else {
+                info = { ...subq };
+              }
+
+              cachePaperInfo[k] = info;
+            });
+          }
         });
       });
       // console.log(cachePaperInfo);
@@ -239,11 +255,16 @@ export default {
     },
     assignCachePaperData(paperData, cacheData) {
       return paperData.map((detail, dIndex) => {
-        detail.questions = detail.questions.map((question) => {
-          return this.mergeObjData(
-            question,
-            cacheData[`${dIndex + 1}_${question.number}`] || {}
-          );
+        detail.questions = detail.questions.map((question, qIndex) => {
+          let k = `${dIndex + 1}_${qIndex + 1}`;
+          let nq = this.mergeObjData(question, cacheData[k] || {});
+          if (question.subQuestions && question.subQuestions.length) {
+            nq.subQuestions = question.subQuestions.map((subq, subqIndex) => {
+              let k = `${dIndex + 1}_${qIndex + 1}_${subqIndex + 1}`;
+              return this.mergeObjData(subq, cacheData[k] || {});
+            });
+          }
+          return nq;
         });
         return detail;
       });