Browse Source

显示模式下的分数修改

dusenyao 1 năm trước cách đây
mục cha
commit
89ace7a2cd
1 tập tin đã thay đổi với 29 bổ sung3 xóa
  1. 29 3
      src/views/exercise_questions/answer/index.vue

+ 29 - 3
src/views/exercise_questions/answer/index.vue

@@ -187,9 +187,7 @@
         </template>
       </div>
 
-      <div v-if="isShow && !isAnnotations" class="show-score_type">
-        本题 {{ `${currentQuestion.property.score} 分` }}
-      </div>
+      <div v-if="isShow && !isAnnotations" class="show-score_type">本题 {{ `${showScore} 分` }}</div>
 
       <div v-if="isAnnotations" class="score_type">
         本题分数:{{
@@ -315,6 +313,7 @@ export default {
       user_answer: {
         answer_status: 0,
       },
+      showScore: 0, // 显示模式下的分数
     };
   },
   computed: {
@@ -542,6 +541,7 @@ export default {
         let content = JSON.parse(question.content);
         content.file_id_list = file_id_list;
         this.currentQuestion = content;
+        this.computedShowScore();
       });
     },
     // 得到答题记录题目信息
@@ -720,6 +720,32 @@ export default {
         return this.exerciseNames[question_type];
       }
     },
+    // 计算显示模式下显示的分数
+    computedShowScore() {
+      const curQuestion = this.currentQuestion;
+      if (!('type' in curQuestion)) return 0;
+      if (curQuestion.type === 'read') {
+        const promises = curQuestion.question_list.map(({ id }) =>
+          GetQuestionInfo({ question_id: id }).then(({ question: { content } }) => JSON.parse(content)),
+        );
+        Promise.all(promises).then((list) => {
+          let score = list.reduce((acc, { property }) => {
+            return (
+              acc +
+              (property.score_type === scoreTypeList[0].value
+                ? property.score
+                : property.score * (property?.option_number ?? 1))
+            );
+          }, 0);
+          this.showScore = score;
+        });
+      } else {
+        this.showScore =
+          curQuestion.property.score_type === scoreTypeList[0].value
+            ? curQuestion.property.score
+            : curQuestion.property.score * (curQuestion.property?.option_number ?? 1);
+      }
+    },
   },
 };
 </script>