JudgePreview.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="judge-preview" :style="getAreaStyle()">
  4. <SerialNumberPosition v-if="isEnable(data.property.sn_display_mode)" :property="data.property" />
  5. <div class="main">
  6. <ul class="option-list">
  7. <li
  8. v-for="({ content, mark, paragraph_list }, i) in data.option_list"
  9. :key="mark"
  10. :style="{ cursor: disabled ? 'not-allowed' : 'pointer' }"
  11. :class="['option-item', { active: isAnswer(mark) }]"
  12. >
  13. <div
  14. :style="{ borderColor: data.unified_attrib?.topic_color }"
  15. :class="['option-content', computedIsJudgeRight(mark)]"
  16. >
  17. <span class="serial-number">{{ computedOptionNumber(i) }}.</span>
  18. <PinyinText
  19. v-if="isEnable(data.property.view_pinyin)"
  20. class="content"
  21. :paragraph-list="paragraph_list"
  22. :pinyin-position="data.property.pinyin_position"
  23. :is-preview="true"
  24. />
  25. <div
  26. v-else
  27. class="rich-text"
  28. :style="{ fontSize: type === typeList[0] ? '12pt' : '' }"
  29. v-html="sanitizeHTML(content)"
  30. ></div>
  31. </div>
  32. <div class="option-type">
  33. <div
  34. v-for="option_type in incertitudeList"
  35. :key="option_type"
  36. :style="{ cursor: disabled ? 'not-allowed' : 'pointer' }"
  37. :class="[
  38. 'option-type-item',
  39. {
  40. active: isAnswer(mark, option_type),
  41. },
  42. computedIsShowRightAnswer(mark, option_type),
  43. ]"
  44. @click="selectAnswer(mark, option_type)"
  45. >
  46. <SvgIcon
  47. v-if="option_type === option_type_list[0].value"
  48. icon-class="check-mark"
  49. width="17"
  50. height="12"
  51. />
  52. <SvgIcon v-if="option_type === option_type_list[1].value" icon-class="cross" size="12" />
  53. <SvgIcon v-if="option_type === option_type_list[2].value" icon-class="circle" size="16" />
  54. </div>
  55. </div>
  56. </li>
  57. </ul>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import PreviewMixin from '../common/PreviewMixin';
  63. import { getJudgeData, option_type_list, isEnable } from '@/views/book/courseware/data/judge';
  64. import { serialNumberTypeList, computeOptionMethods } from '@/views/book/courseware/data/common';
  65. export default {
  66. name: 'JudgePreview',
  67. mixins: [PreviewMixin],
  68. data() {
  69. return {
  70. data: getJudgeData(),
  71. option_type_list,
  72. isEnable,
  73. };
  74. },
  75. computed: {
  76. incertitudeList() {
  77. let _option_type_list = this.data.property.option_type_list;
  78. if (isEnable(this.data.property.is_view_incertitude)) {
  79. return _option_type_list;
  80. }
  81. // 返回不包含第三个元素的新数组
  82. return [..._option_type_list.slice(0, 2), ..._option_type_list.slice(3)];
  83. },
  84. },
  85. watch: {
  86. 'answer.answer_list': {
  87. handler(val) {
  88. if (val.length === 0) {
  89. this.answer.is_right = false;
  90. return;
  91. }
  92. if (val.length !== this.data.answer.answer_list.length) {
  93. this.answer.is_right = false;
  94. return;
  95. }
  96. this.answer.is_right = val.every((item) =>
  97. this.data.answer.answer_list.some(
  98. (answerItem) => answerItem.mark === item.mark && answerItem.option_type === item.option_type,
  99. ),
  100. );
  101. },
  102. deep: true,
  103. },
  104. },
  105. methods: {
  106. computedOptionNumber(number) {
  107. let type = serialNumberTypeList.find((item) => item.value === this.data.property.option_serial_type)?.value;
  108. if (!type) return number + 1;
  109. return computeOptionMethods[type](number);
  110. },
  111. isAnswer(mark, option_type) {
  112. return this.answer.answer_list.some((li) => li.mark === mark && li.option_type === option_type);
  113. },
  114. // 选择答案
  115. selectAnswer(mark, option_type) {
  116. if (this.disabled) return;
  117. const index = this.answer.answer_list.findIndex((li) => li.mark === mark);
  118. if (index === -1) {
  119. this.answer.answer_list.push({ mark, option_type });
  120. } else {
  121. this.answer.answer_list[index].option_type = option_type;
  122. }
  123. },
  124. // 计算判断题小题题目样式
  125. computedIsJudgeRight(mark) {
  126. if (!this.isJudgingRightWrong) return '';
  127. let selectOption = this.answer.answer_list.find((item) => item.mark === mark); // 查找是否已选中的选项
  128. if (!selectOption) return 'wrong';
  129. return this.data.answer.answer_list.find((item) => item.mark === mark)?.option_type === selectOption.option_type
  130. ? 'right'
  131. : 'wrong';
  132. },
  133. // 计算是否显示正确答案的样式
  134. computedIsShowRightAnswer(mark, option_type) {
  135. if (!this.isShowRightAnswer) return '';
  136. let selectOption = this.answer.answer_list.find((item) => item.mark === mark); // 查找是否已选中的选项
  137. // 是否是正确的选项类型
  138. let isCorrectType = this.data.answer.answer_list.find((item) => item.mark === mark)?.option_type === option_type;
  139. if (!selectOption) {
  140. return isCorrectType ? 'answer-right' : '';
  141. }
  142. return isCorrectType && !(selectOption.option_type === option_type) ? 'answer-right' : '';
  143. },
  144. },
  145. };
  146. </script>
  147. <style lang="scss" scoped>
  148. @use '@/styles/mixin.scss' as *;
  149. .judge-preview {
  150. @include preview-base;
  151. .option-list {
  152. display: flex;
  153. flex-direction: column;
  154. row-gap: 16px;
  155. .option-item {
  156. display: flex;
  157. column-gap: 16px;
  158. .option-content {
  159. display: flex;
  160. flex: 1;
  161. column-gap: 8px;
  162. align-items: center;
  163. padding: 12px 24px;
  164. background-color: $content-color;
  165. border-style: solid;
  166. border-width: 1px;
  167. border-radius: 40px;
  168. &.right {
  169. background-color: $right-bc-color;
  170. }
  171. &.wrong {
  172. box-shadow: 0 0 0 1px $error-color;
  173. }
  174. .serial-number {
  175. font-size: 16pt;
  176. color: #000;
  177. }
  178. }
  179. .option-type {
  180. display: flex;
  181. column-gap: 8px;
  182. align-items: center;
  183. &-item {
  184. display: flex;
  185. align-items: center;
  186. justify-content: center;
  187. width: 36px;
  188. height: 36px;
  189. color: #000;
  190. cursor: pointer;
  191. background-color: $content-color;
  192. border-radius: 50%;
  193. &.active {
  194. color: #fff;
  195. background-color: $light-main-color;
  196. }
  197. &.answer-right {
  198. color: $right-color;
  199. border: 1px solid $right-color;
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. </style>