SelectPreview.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="select-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. <div v-if="isEnable(data.property.is_enable_description)" class="description">{{ data.description }}</div>
  9. <AudioPlay
  10. v-if="isEnable(data.property.is_enable_listening) && data.file_id_list.length > 0"
  11. :file-id="data.file_id_list[0]"
  12. />
  13. <ul class="option-list">
  14. <li
  15. v-for="({ content, mark }, i) in data.option_list"
  16. :key="mark"
  17. :class="['option-item', { active: isAnswer(mark) }, ...computedAnswerClass(mark)]"
  18. @click="selectAnswer(mark)"
  19. >
  20. <span class="selectionbox"></span>
  21. <span>{{ computeOptionMethods[data.option_number_show_mode](i) }} </span>
  22. <span class="content" v-html="sanitizeHTML(content)"></span>
  23. </li>
  24. </ul>
  25. </div>
  26. </template>
  27. <script>
  28. import { computeOptionMethods, selectTypeList } from '@/views/exercise_questions/data/common';
  29. import PreviewMixin from './components/PreviewMixin';
  30. export default {
  31. name: 'SelectPreview',
  32. mixins: [PreviewMixin],
  33. data() {
  34. return {
  35. computeOptionMethods,
  36. };
  37. },
  38. methods: {
  39. isAnswer(mark) {
  40. return this.answer.answer_list.includes(mark);
  41. },
  42. selectAnswer(mark) {
  43. const index = this.answer.answer_list.indexOf(mark);
  44. if (this.data.property.select_type === selectTypeList[0].value) {
  45. this.answer.answer_list = [mark];
  46. }
  47. if (this.data.property.select_type === selectTypeList[1].value) {
  48. if (index === -1) {
  49. this.answer.answer_list.push(mark);
  50. } else {
  51. this.answer.answer_list.splice(index, 1);
  52. }
  53. }
  54. },
  55. computedAnswerClass(mark) {
  56. if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
  57. return [];
  58. }
  59. let isHas = this.answer.answer_list.includes(mark);
  60. if (!isHas) {
  61. return [];
  62. }
  63. let isRight = this.data.answer.answer_list.includes(mark) && this.isJudgingRightWrong;
  64. return isRight ? ['right'] : ['wrong'];
  65. },
  66. },
  67. };
  68. </script>
  69. <style lang="scss" scoped>
  70. @use '@/styles/mixin.scss' as *;
  71. .select-preview {
  72. @include preview;
  73. .option-list {
  74. display: flex;
  75. flex-direction: column;
  76. row-gap: 16px;
  77. .option-item {
  78. display: flex;
  79. column-gap: 8px;
  80. align-items: center;
  81. padding: 12px 24px;
  82. color: #706f78;
  83. cursor: pointer;
  84. background-color: $content-color;
  85. border-radius: 40px;
  86. .selectionbox {
  87. width: 14px;
  88. height: 14px;
  89. margin-right: 8px;
  90. border: 2px solid #dcdbdd;
  91. border-radius: 50%;
  92. }
  93. .content {
  94. flex: 1;
  95. }
  96. &.active {
  97. color: #34343a;
  98. background-color: #e7eeff;
  99. .selectionbox {
  100. border-color: $light-main-color;
  101. border-width: 4px;
  102. }
  103. &.right {
  104. background-color: $content-color;
  105. border: 1px solid #30a47d;
  106. &::after {
  107. font-size: 14px;
  108. color: #30a47d;
  109. content: '已选';
  110. }
  111. }
  112. &.wrong {
  113. background-color: $content-color;
  114. border: 1px solid #f2555a;
  115. &::after {
  116. font-size: 14px;
  117. color: #f2555a;
  118. content: '已选';
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. </style>