Просмотр исходного кода

成绩报告页面显示提交的答案

ChengYuXuan 5 лет назад
Родитель
Сommit
7be7d148b5
2 измененных файлов с 28 добавлено и 7 удалено
  1. 3 3
      src/api/types.d.ts
  2. 25 4
      src/views/components/ExamQuestionsInfo.vue

+ 3 - 3
src/api/types.d.ts

@@ -126,9 +126,9 @@ export interface CodeQuestionSerializer extends QuestionSerializer {
 }
 
 export interface TeacherQuestionSerializer extends QuestionSerializer {
-  answer?: string
-  analysis?: string
-  lastModifiedTime?: LocalDateTime
+  answer: string
+  analysis: string
+  lastModifiedTime: LocalDateTime
 }
 
 export type ChoiceAnswer = string

+ 25 - 4
src/views/components/ExamQuestionsInfo.vue

@@ -31,22 +31,26 @@
           class="d-flex align-center justify-end"
           v-if="question.type !== 'short_answer'"
         >
-          答案:
+          我的答案:
+          <v-chip label color="info" class="ml-2 mr-4">
+            {{ submitAnswers.get(question.id) }}
+          </v-chip>
+          正确答案:
           <v-chip label color="success" class="ml-2">
             {{ question.answer }}
           </v-chip>
           <!--  简答题解析即为答案        -->
         </v-col>
       </v-row>
-      <v-row class="pl-10"> </v-row>
     </div>
   </div>
 </template>
 
 <script lang="ts">
 import Vue, { PropType } from 'vue'
-import { TeacherQuestionSerializer, OptionSerializer } from '@/api/types'
+import { TeacherQuestionSerializer, OptionSerializer, ID } from '@/api/types'
 import MarkdownText from '@/views/exam/components/MarkdownText.vue'
+import { getExamSubmitRecords } from '@/api/record'
 
 export default Vue.extend({
   name: 'ExamQuestionsInfo',
@@ -65,7 +69,9 @@ export default Vue.extend({
   },
 
   data() {
-    return {}
+    return {
+      submitAnswers: {} as Map<ID, string>
+    }
   },
   methods: {
     mergeOptions(options: OptionSerializer): string {
@@ -81,6 +87,21 @@ export default Vue.extend({
         entries.push(keys[i] + ' : ' + values[i])
       }
       return '\n' + entries.join(' ')
+    },
+    async fetchAnswers() {
+      const examId = this.$route.params.examId
+      getExamSubmitRecords(examId).then(({ data }) => {
+        let records = data.result
+        this.submitAnswers = new Map()
+        records.forEach((val) => {
+          this.submitAnswers.set(val.questionId, val.submitAnswer)
+        })
+      })
+    }
+  },
+  mounted() {
+    if (this.analysis) {
+      this.fetchAnswers()
     }
   }
 })