SelectPreview.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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
  9. v-if="isEnable(data.property.is_enable_description)"
  10. class="description rich-text"
  11. v-html="sanitizeHTML(data.description)"
  12. ></div>
  13. <div v-if="isEnable(data.property.is_option_subdivision)" class="option-subdivision">
  14. <ul v-for="(item, i) in data.option_list" :key="i" class="option-subdivision-list">
  15. <span class="serial-number">{{ computeOptionMethods[data.option_number_show_mode](i) }} </span>
  16. <li
  17. v-for="{ content, mark } in item"
  18. :key="mark"
  19. :style="{ cursor: disabled ? 'not-allowed' : 'pointer' }"
  20. :class="['option-item', { active: isAnswer(mark, i) }, ...computedAnswerClass(mark, i)]"
  21. @click="selectAnswer(mark, i)"
  22. >
  23. <span class="selectionbox"></span>
  24. <span class="content rich-text" v-html="sanitizeHTML(content)"></span>
  25. </li>
  26. </ul>
  27. </div>
  28. <ul v-else class="option-list">
  29. <li
  30. v-for="({ content, mark }, i) in data.option_list"
  31. :key="mark"
  32. :style="{ cursor: disabled ? 'not-allowed' : 'pointer' }"
  33. :class="['option-item', { active: isAnswer(mark) }, ...computedAnswerClass(mark)]"
  34. @click="selectAnswer(mark)"
  35. >
  36. <span class="selectionbox"></span>
  37. <span class="serial-number">{{ computeOptionMethods[data.option_number_show_mode](i) }} </span>
  38. <span class="content rich-text" v-html="sanitizeHTML(content)"></span>
  39. </li>
  40. </ul>
  41. </div>
  42. </template>
  43. <script>
  44. import { computeOptionMethods, isEnable, selectTypeList } from '@/views/exercise_questions/data/common';
  45. import PreviewMixin from './components/PreviewMixin';
  46. export default {
  47. name: 'SelectPreview',
  48. mixins: [PreviewMixin],
  49. data() {
  50. return {
  51. computeOptionMethods,
  52. };
  53. },
  54. computed: {
  55. isSubdivision() {
  56. return isEnable(this.data.property.is_option_subdivision);
  57. },
  58. },
  59. created() {
  60. if (isEnable(this.data.property.is_option_subdivision)) {
  61. this.answer.answer_list = this.data.option_list.map(() => []);
  62. }
  63. },
  64. methods: {
  65. isAnswer(mark, i) {
  66. if (isEnable(this.data.property.is_option_subdivision)) {
  67. return this.answer.answer_list?.[i]?.includes(mark);
  68. }
  69. return this.answer.answer_list.includes(mark);
  70. },
  71. selectAnswer(mark, i) {
  72. if (this.disabled) return;
  73. let answer_list = this.isSubdivision ? this.answer.answer_list[i] : this.answer.answer_list;
  74. let index = answer_list.indexOf(mark);
  75. if (this.data.property.select_type === selectTypeList[0].value) {
  76. if (this.isSubdivision) {
  77. this.$set(this.answer.answer_list, i, [mark]);
  78. } else {
  79. this.$set(this.answer, 'answer_list', [mark]);
  80. }
  81. }
  82. if (this.data.property.select_type === selectTypeList[1].value) {
  83. if (index === -1) {
  84. answer_list.push(mark);
  85. } else {
  86. answer_list.splice(index, 1);
  87. }
  88. }
  89. },
  90. computedAnswerClass(mark, i) {
  91. if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
  92. return [];
  93. }
  94. let isHas = this.isSubdivision
  95. ? this.answer.answer_list[i].includes(mark)
  96. : this.answer.answer_list.includes(mark); // 是否已选中的选项
  97. if (!isHas && this.isShowRightAnswer) {
  98. let isRight = this.isSubdivision
  99. ? this.data.answer.answer_list[i].includes(mark)
  100. : this.data.answer.answer_list.includes(mark); // 是否是正确答案
  101. return isRight ? ['answer-right'] : [];
  102. }
  103. // 判断是否是正确答案
  104. if (this.isJudgingRightWrong) {
  105. let isRight = this.isSubdivision
  106. ? this.data.answer.answer_list[i].includes(mark)
  107. : this.data.answer.answer_list.includes(mark); // 是否是正确答案
  108. return isRight ? ['right'] : ['wrong'];
  109. }
  110. return [];
  111. },
  112. },
  113. };
  114. </script>
  115. <style lang="scss" scoped>
  116. @use '@/styles/mixin.scss' as *;
  117. .select-preview {
  118. @include preview;
  119. %option-list,
  120. .option-list {
  121. display: flex;
  122. flex-direction: column;
  123. row-gap: 16px;
  124. .option-item {
  125. display: flex;
  126. column-gap: 8px;
  127. align-items: center;
  128. padding: 12px 24px;
  129. color: #706f78;
  130. cursor: pointer;
  131. background-color: $content-color;
  132. border-radius: 40px;
  133. .selectionbox {
  134. width: 14px;
  135. min-width: 14px;
  136. height: 14px;
  137. min-height: 14px;
  138. margin-right: 8px;
  139. border: 2px solid #dcdbdd;
  140. border-radius: 50%;
  141. }
  142. .serial-number {
  143. font-size: 16pt;
  144. }
  145. .content {
  146. flex: 1;
  147. }
  148. &.answer-right {
  149. background-color: #e8f7f2;
  150. &::after {
  151. font-size: 14px;
  152. color: $right-color;
  153. content: '正确答案';
  154. }
  155. }
  156. &.active {
  157. color: #34343a;
  158. background-color: $main-active-color;
  159. .selectionbox {
  160. border-color: $light-main-color;
  161. border-width: 4px;
  162. }
  163. &.right {
  164. background-color: $content-color;
  165. border: 1px solid $right-color;
  166. &::after {
  167. font-size: 14px;
  168. color: $right-color;
  169. content: '已选';
  170. }
  171. }
  172. &.wrong {
  173. background-color: $content-color;
  174. box-shadow: 0 0 0 1px $error-color;
  175. &::after {
  176. font-size: 14px;
  177. color: #a09fa6;
  178. content: '已选';
  179. }
  180. }
  181. }
  182. }
  183. }
  184. .option-subdivision {
  185. display: flex;
  186. flex-direction: column;
  187. row-gap: 24px;
  188. &-list {
  189. @extend %option-list;
  190. .serial-number {
  191. font-size: 16pt;
  192. }
  193. flex-direction: row;
  194. column-gap: 24px;
  195. align-items: center;
  196. .option-item {
  197. flex: 1;
  198. }
  199. :deep p {
  200. margin: 0;
  201. }
  202. }
  203. }
  204. }
  205. </style>