Browse Source

试卷预览bugfix

zhangjie 3 years ago
parent
commit
65fd27e93f
1 changed files with 13 additions and 3 deletions
  1. 13 3
      src/features/examwork/StudentExamDetail/PreviewPaperDialog.vue

+ 13 - 3
src/features/examwork/StudentExamDetail/PreviewPaperDialog.vue

@@ -105,6 +105,9 @@ export default {
       // console.log(answerJson);
       // console.log(examStudentAnswerJson);
 
+      const isEmpty = (cont) =>
+        cont === undefined || cont === null || cont === "";
+
       const answerMap = {};
       answerJson.details.forEach((detail) => {
         detail.questions.forEach((question) => {
@@ -142,7 +145,7 @@ export default {
           if (question.subQuestions) {
             question.subQuestions.forEach((sq) => {
               const sqk = `${k}-${sq.number}`;
-              sq.answer = answerMap[sqk];
+              sq.answer = isEmpty(answerMap[sqk]) ? null : answerMap[sqk];
               const stdAns = studentAnsMap[sqk] || {
                 answer: null,
                 score: null,
@@ -151,7 +154,7 @@ export default {
               sq.studentScore = stdAns.score;
             });
           } else {
-            question.answer = answerMap[k];
+            question.answer = isEmpty(answerMap[k]) ? null : answerMap[k];
             const stdAns = studentAnsMap[k] || { answer: null, score: null };
             question.studentAnswer = stdAns.answer;
             question.studentScore = stdAns.score;
@@ -236,6 +239,7 @@ export default {
       // }
 
       if (question.answer !== null) {
+        // console.log(question.answer);
         contents.push({
           cls: "topic-answer",
           type: "json",
@@ -248,6 +252,7 @@ export default {
       }
 
       if (question.studentAnswer !== null) {
+        // console.log(question.studentAnswer);
         // 简答题的特殊处理,解决上传的大图无法分页问题。文字内容不受影响。
         if (question.structType === STRUCT_TYPES.TEXT) {
           // console.log(question.studentAnswer);
@@ -307,6 +312,7 @@ export default {
     },
     getRichJsonImgUrls(richJson) {
       let urls = [];
+      if (!richJson) return urls;
       richJson.sections.forEach((section) => {
         section.blocks.forEach((elem) => {
           if (elem.type === "image") {
@@ -325,7 +331,11 @@ export default {
           return;
         }
         // 简答题才可能会有图片
-        if (item.cls.indexOf("answer") && item.content.structType === 5) {
+        if (
+          item.cls.indexOf("answer") &&
+          item.content.structType === STRUCT_TYPES.TEXT &&
+          item.content.body
+        ) {
           item.content.body.forEach((body) => {
             imgUrls.push(...this.getRichJsonImgUrls(body));
           });