JudgePreview.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="judge-preview">
  4. <div class="stem">
  5. <span class="question-number">{{ data.property.question_number }}.</span>
  6. <span v-html="sanitizeHTML(data.stem)"></span>
  7. </div>
  8. <AudioPlay
  9. v-if="isEnable(data.property.is_enable_listening) && data.file_id_list.length > 0"
  10. :file-id="data.file_id_list[0]"
  11. />
  12. <ul class="option-list">
  13. <li
  14. v-for="({ content, mark }, i) in data.option_list"
  15. :key="mark"
  16. :class="['option-item', { active: isAnswer(mark) }]"
  17. >
  18. <div :class="['option-content', computedIsJudgeRight(mark)]">
  19. <span class="serial-number">{{ computedQuestionNumber(i, data.option_number_show_mode) }}</span>
  20. <div v-html="sanitizeHTML(content)"></div>
  21. </div>
  22. <div class="option-type">
  23. <div
  24. v-for="option_type in data.property.option_type_list"
  25. :key="option_type"
  26. :style="{ cursor: isJudgingRightWrong || isShowRightAnswer ? 'not-allowed' : 'pointer' }"
  27. :class="[
  28. 'option-type-item',
  29. {
  30. active: isAnswer(mark, option_type),
  31. },
  32. computedIsShowRightAnswer(mark, option_type),
  33. ]"
  34. @click="selectAnswer(mark, option_type)"
  35. >
  36. <SvgIcon v-if="option_type === option_type_list[0].value" icon-class="check-mark" width="17" height="12" />
  37. <SvgIcon v-if="option_type === option_type_list[1].value" icon-class="cross" size="12" />
  38. <SvgIcon v-if="option_type === option_type_list[2].value" icon-class="circle" size="20" />
  39. </div>
  40. </div>
  41. </li>
  42. </ul>
  43. </div>
  44. </template>
  45. <script>
  46. import { option_type_list } from '@/views/exercise_questions/data/judge';
  47. import { computedQuestionNumber } from '@/views/exercise_questions/data/common';
  48. import PreviewMixin from './components/PreviewMixin';
  49. export default {
  50. name: 'JudgePreview',
  51. mixins: [PreviewMixin],
  52. data() {
  53. return {
  54. computedQuestionNumber,
  55. option_type_list,
  56. };
  57. },
  58. methods: {
  59. isAnswer(mark, option_type) {
  60. return this.answer.answer_list.some((li) => li.mark === mark && li.option_type === option_type);
  61. },
  62. selectAnswer(mark, option_type) {
  63. if (this.isJudgingRightWrong || this.isShowRightAnswer) return;
  64. const index = this.answer.answer_list.findIndex((li) => li.mark === mark);
  65. if (index === -1) {
  66. this.answer.answer_list.push({ mark, option_type });
  67. } else {
  68. this.answer.answer_list[index].option_type = option_type;
  69. }
  70. },
  71. /**
  72. * 计算是否显示正确答案的样式
  73. * @param {string} mark 选项标识
  74. * @param {string} option_type 选项类型
  75. */
  76. computedIsShowRightAnswer(mark, option_type) {
  77. if (!this.isShowRightAnswer) return '';
  78. let selectOption = this.answer.answer_list.find((item) => item.mark === mark); // 查找是否已选中的选项
  79. if (!selectOption) return '';
  80. return this.data.answer.answer_list.find((item) => item.mark === mark).option_type === option_type &&
  81. !(selectOption.option_type === option_type)
  82. ? 'answer-right'
  83. : '';
  84. },
  85. /**
  86. * 计算判断题题干的样式
  87. * @param {string} mark 选项标识
  88. */
  89. computedIsJudgeRight(mark) {
  90. if (!this.isJudgingRightWrong) return '';
  91. let selectOption = this.answer.answer_list.find((item) => item.mark === mark); // 查找是否已选中的选项
  92. if (!selectOption) return 'wrong';
  93. return this.data.answer.answer_list.find((item) => item.mark === mark).option_type === selectOption.option_type
  94. ? 'right'
  95. : 'wrong';
  96. },
  97. },
  98. };
  99. </script>
  100. <style lang="scss" scoped>
  101. @use '@/styles/mixin.scss' as *;
  102. .judge-preview {
  103. @include preview;
  104. .option-list {
  105. display: flex;
  106. flex-direction: column;
  107. row-gap: 16px;
  108. .option-item {
  109. display: flex;
  110. column-gap: 16px;
  111. .option-content {
  112. display: flex;
  113. flex: 1;
  114. column-gap: 24px;
  115. align-items: center;
  116. padding: 12px 24px;
  117. background-color: $content-color;
  118. border-radius: 40px;
  119. &.right {
  120. background-color: $right-bc-color;
  121. }
  122. &.wrong {
  123. box-shadow: 0 0 0 1px $error-color;
  124. }
  125. .serial-number {
  126. color: #000;
  127. }
  128. }
  129. .option-type {
  130. display: flex;
  131. column-gap: 8px;
  132. align-items: center;
  133. &-item {
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. width: 48px;
  138. height: 48px;
  139. color: #000;
  140. cursor: pointer;
  141. background-color: $content-color;
  142. border-radius: 50%;
  143. &.active {
  144. color: #fff;
  145. background-color: $light-main-color;
  146. }
  147. &.answer-right {
  148. color: $right-color;
  149. border: 1px solid $right-color;
  150. }
  151. }
  152. }
  153. }
  154. }
  155. }
  156. </style>