ExamQuestionsInfo.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div>
  3. <div v-for="question in examQuestions" :key="question.id">
  4. <v-divider class="my-5"></v-divider>
  5. <v-row>
  6. <v-col class="d-flex justify-center align-center" cols="1">
  7. <v-chip label v-if="!analysis">
  8. {{ examQuestions.indexOf(question) + 1 }}
  9. </v-chip>
  10. <v-chip
  11. v-else
  12. :color="
  13. submitAnswers.get(question.id) ===
  14. question.answer.replace(/[;]/gi, '')
  15. ? 'success'
  16. : 'error'
  17. "
  18. label
  19. >
  20. {{ examQuestions.indexOf(question) + 1 }}
  21. </v-chip>
  22. </v-col>
  23. <v-col class="flex-grow-0 flex-shrink-0" cols="9">
  24. <markdown-text
  25. :raw="question.stem + mergeOptions(question.options)"
  26. style="height: 100%;width: 100%"
  27. ></markdown-text>
  28. </v-col>
  29. <v-col class="flex-shrink-1" cols="2">
  30. <v-card-text v-if="question.keyPoints">
  31. 关键词: {{ question.keyPoints }}
  32. </v-card-text>
  33. </v-col>
  34. </v-row>
  35. <v-row class="px-10 d-block" v-if="analysis && question.type !== 'code'">
  36. <v-col class="grey lighten-3 py-1">
  37. <markdown-text
  38. :raw="question.analysis"
  39. style="height: 100%;width: 100%"
  40. ></markdown-text>
  41. </v-col>
  42. <v-col
  43. class="d-flex align-center justify-end"
  44. v-if="question.type !== 'short_answer'"
  45. >
  46. 我的答案:
  47. <v-chip
  48. label
  49. :color="
  50. submitAnswers.get(question.id) ===
  51. question.answer.replace(/[;]/gi, '')
  52. ? 'success'
  53. : 'error'
  54. "
  55. class="ml-2 mr-4"
  56. v-if="submitAnswers.size > 0"
  57. >
  58. {{ submitAnswers.get(question.id) }}
  59. </v-chip>
  60. 正确答案:
  61. <v-chip label color="success" class="ml-2">
  62. {{ question.answer.replace(/[;]/gi, '') }}
  63. </v-chip>
  64. <!-- 简答题解析即为答案 -->
  65. </v-col>
  66. </v-row>
  67. </div>
  68. </div>
  69. </template>
  70. <script lang="ts">
  71. import Vue, { PropType } from 'vue'
  72. import { TeacherQuestionSerializer, OptionSerializer, ID } from '@/api/types'
  73. import MarkdownText from '@/views/exam/components/MarkdownText.vue'
  74. import { getExamSubmitRecordsByUserId } from '@/api/record'
  75. export default Vue.extend({
  76. name: 'ExamQuestionsInfo',
  77. props: {
  78. examQuestions: {
  79. type: Array as PropType<Array<TeacherQuestionSerializer>>,
  80. required: true
  81. },
  82. analysis: {
  83. type: Boolean,
  84. default: false
  85. }
  86. },
  87. components: {
  88. MarkdownText
  89. },
  90. data() {
  91. return {
  92. submitAnswers: {} as Map<ID, string>
  93. }
  94. },
  95. methods: {
  96. mergeOptions(options: OptionSerializer): string {
  97. if (!options) {
  98. return ''
  99. }
  100. let keys = Object.keys(options)
  101. let values = Object.values(options)
  102. let entries = []
  103. for (let i = 0; i < keys.length; i++) {
  104. entries.push(keys[i] + ' : ' + values[i])
  105. }
  106. return '\n' + entries.join(' ')
  107. },
  108. async fetchAnswers() {
  109. const examId = this.$route.params.examId
  110. getExamSubmitRecordsByUserId(examId).then(({ data }) => {
  111. let records = data.result
  112. if (records && records.length > 0) {
  113. this.submitAnswers = new Map()
  114. records.forEach((val) => {
  115. this.submitAnswers.set(
  116. val.questionId,
  117. val.submitAnswer === ''
  118. ? '无'
  119. : val.submitAnswer === 't'
  120. ? 'true'
  121. : val.submitAnswer === 'f'
  122. ? 'false'
  123. : val.submitAnswer.replace(/[;]/gi, '')
  124. )
  125. })
  126. } else {
  127. this.submitAnswers = new Map()
  128. this.examQuestions.forEach((val) => {
  129. this.submitAnswers.set(val.id, '无')
  130. })
  131. }
  132. })
  133. }
  134. },
  135. mounted() {
  136. if (this.analysis) {
  137. this.fetchAnswers()
  138. }
  139. }
  140. })
  141. </script>
  142. <style scoped></style>