Browse Source

修改填空题

aaa 3 years ago
parent
commit
821b765d3f

+ 9 - 4
src/views/home/answer/page-answer-recruit.vue

@@ -352,9 +352,11 @@ export default {
     },
     // 方法:过滤试题的类型,添加用户作答的字段
     setPersonDataFun(httpResultDataItme) {
+      console.log("-setPersonDataFun--" + httpResultDataItme);
       let results = this.formatQuestionType(
         httpResultDataItme.type,
-        httpResultDataItme.content
+        httpResultDataItme.content,
+        httpResultDataItme.finalAnswer
       );
       httpResultDataItme.typeTxt = results.typeTxt;
       httpResultDataItme.questionContent = results.questionContent;
@@ -363,7 +365,7 @@ export default {
       return httpResultDataItme;
     },
     // 方法:过滤试题的类型、填空题的题目、填空题的回答框个数
-    formatQuestionType(type, content) {
+    formatQuestionType(type, content, finalAnswer) {
       let typeTxt = "";
       let questionContent = "";
       let questionInputNum = 0;
@@ -376,7 +378,7 @@ export default {
           break;
         case this.questionType.gapFilling:
           typeTxt = "填空题";
-          questionInputNum = this.getPlaceholderCount(content);
+          questionInputNum = this.getPlaceholderCount(content, finalAnswer);
           questionContent = content.replace("$PH$", "()");
           break;
         case this.questionType.TrueOrFalse:
@@ -392,13 +394,16 @@ export default {
       };
     },
     // 方法:统计字符串中包含的特定字符个数
-    getPlaceholderCount(strSource) {
+    getPlaceholderCount(strSource, finalAnswer) {
       // 统计字符串中包含{}或{xxXX}的个数
       let countNum = 0;
       strSource.replace("$PH$", function(m, i) {
         // m为找到的{xx}元素、i为索引
         countNum++;
       });
+      if (!countNum) {
+        countNum = finalAnswer.length;
+      }
       return countNum;
     },
     // 方法:过滤正确答案的选项的编号

+ 11 - 7
src/views/home/exam/page-exam-item-doing.vue

@@ -282,7 +282,8 @@ export default {
     setPersonDataFun(httpResultDataItme) {
       let results = this.formatQuestionType(
         httpResultDataItme.type,
-        httpResultDataItme.content
+        httpResultDataItme.content,
+        httpResultDataItme.finalAnswer
       );
       httpResultDataItme.typeTxt = results.typeTxt;
       httpResultDataItme.questionContent = results.questionContent;
@@ -385,7 +386,7 @@ export default {
       }, 1000);
     },
     // 方法:过滤试题的类型、填空题的题目、填空题的回答框个数
-    formatQuestionType(type, content) {
+    formatQuestionType(type, content, finalAnswer) {
       let typeTxt = "";
       let questionContent = "";
       let questionInputNum = 0;
@@ -398,7 +399,7 @@ export default {
           break;
         case this.questionType.gapFilling:
           typeTxt = "填空题";
-          questionInputNum = this.getPlaceholderCount(content);
+          questionInputNum = this.getPlaceholderCount(content, finalAnswer);
           questionContent = content.replace("$PH$", "()");
           break;
         case this.questionType.TrueOrFalse:
@@ -414,14 +415,17 @@ export default {
       };
     },
     // 方法:统计字符串中包含的特定字符个数
-    getPlaceholderCount(strSource) {
+    getPlaceholderCount(strSource, finalAnswer) {
       // 统计字符串中包含{}或{xxXX}的个数
-      let thisCount = 0;
+      let countNum = 0;
       strSource.replace("$PH$", function(m, i) {
         // m为找到的{xx}元素、i为索引
-        thisCount++;
+        countNum++;
       });
-      return thisCount;
+      if (!countNum) {
+        countNum = finalAnswer.length;
+      }
+      return countNum;
     },
     // 操作:点击了某个题序
     handleExamQuestionItemFun(item, index) {