SelectPreview.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="select-preview" :style="getAreaStyle()">
  4. <SerialNumberPosition v-if="isEnable(data.property.sn_display_mode)" :property="data.property" />
  5. <div class="main">
  6. <ul
  7. class="option-list"
  8. :style="{ flexDirection: data.property.arrange_type === arrangeTypeList[0].value ? 'row' : 'column' }"
  9. >
  10. <li
  11. v-for="({ content, mark, multilingual, paragraph_list }, i) in data.option_list"
  12. :key="mark"
  13. :style="{ cursor: disabled ? 'not-allowed' : 'pointer', borderColor: data.unified_attrib?.topic_color }"
  14. :class="['option-item', { active: isAnswer(mark) }, ...computedAnswerClass(mark)]"
  15. @click="selectAnswer(mark)"
  16. >
  17. <span class="checkbox">
  18. <SvgIcon icon-class="check-mark" width="10" height="7" />
  19. </span>
  20. <span class="serial-number"> {{ computedOptionNumber(i) }}. </span>
  21. <PinyinText
  22. v-if="isEnable(data.property.view_pinyin)"
  23. class="content"
  24. :paragraph-list="paragraph_list"
  25. :pinyin-position="data.property.pinyin_position"
  26. :is-preview="true"
  27. />
  28. <span
  29. v-else
  30. class="content rich-text"
  31. :style="{ fontSize: type === typeList[0] ? '12pt' : '' }"
  32. v-html="sanitizeHTML(content)"
  33. ></span>
  34. <div v-if="showLang" class="lang">
  35. {{ multilingual.find((item) => item.type === getLang())?.translation }}
  36. </div>
  37. </li>
  38. </ul>
  39. </div>
  40. </div>
  41. </template>
  42. <script>
  43. import PreviewMixin from '../common/PreviewMixin';
  44. import { getSelectData, arrangeTypeList } from '@/views/book/courseware/data/select';
  45. import { serialNumberTypeList, computeOptionMethods } from '@/views/book/courseware/data/common';
  46. export default {
  47. name: 'SelectPreview',
  48. mixins: [PreviewMixin],
  49. data() {
  50. return {
  51. data: getSelectData(),
  52. arrangeTypeList,
  53. };
  54. },
  55. watch: {
  56. 'answer.answer_list': {
  57. handler(val) {
  58. if (val.length === 0) {
  59. this.answer.is_right = false;
  60. return;
  61. }
  62. if (val.length !== this.data.answer.answer_list.length) {
  63. this.answer.is_right = false;
  64. return;
  65. }
  66. this.answer.is_right = val.every((item) => this.data.answer.answer_list.includes(item));
  67. },
  68. deep: true,
  69. },
  70. },
  71. methods: {
  72. computedOptionNumber(number) {
  73. let type = serialNumberTypeList.find((item) => item.value === this.data.property.option_serial_type)?.value;
  74. if (!type) return number + 1;
  75. return computeOptionMethods[type](number);
  76. },
  77. isAnswer(mark) {
  78. return this.answer.answer_list.includes(mark);
  79. },
  80. selectAnswer(mark) {
  81. if (this.disabled) return;
  82. const index = this.answer.answer_list.indexOf(mark);
  83. if (index === -1) {
  84. this.answer.answer_list.push(mark);
  85. } else {
  86. this.answer.answer_list.splice(index, 1);
  87. }
  88. },
  89. computedAnswerClass(mark) {
  90. if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
  91. return [];
  92. }
  93. let isHas = this.answer.answer_list.includes(mark); // 用户是否已选中
  94. let isRight = this.data.answer.answer_list.includes(mark); // 是否是正确答案
  95. let answerClass = [];
  96. if (!isHas && this.isShowRightAnswer) {
  97. answerClass = isRight ? ['answer-right'] : [];
  98. }
  99. // 判断是否是正确答案
  100. if (isHas && this.isJudgingRightWrong) {
  101. answerClass = isRight ? ['right'] : ['wrong'];
  102. }
  103. return answerClass;
  104. },
  105. },
  106. };
  107. </script>
  108. <style lang="scss" scoped>
  109. @use '@/styles/mixin.scss' as *;
  110. .select-preview {
  111. @include preview-base;
  112. .option-list {
  113. display: flex;
  114. flex-flow: column wrap;
  115. gap: 16px;
  116. .option-item {
  117. display: flex;
  118. flex: 1;
  119. flex-wrap: wrap;
  120. column-gap: 8px;
  121. align-items: center;
  122. padding: 12px 24px;
  123. color: #706f78;
  124. cursor: pointer;
  125. background-color: $content-color;
  126. border: 1px solid $content-color;
  127. border-radius: 40px;
  128. .lang {
  129. // width: 100%;
  130. padding-left: 52px;
  131. }
  132. .checkbox {
  133. display: flex;
  134. align-items: center;
  135. justify-content: center;
  136. width: 14px;
  137. height: 14px;
  138. margin-right: 8px;
  139. cursor: pointer;
  140. background-color: #fff;
  141. border: 1px solid #dcdfe6;
  142. border-radius: 2px;
  143. .svg-icon {
  144. display: none;
  145. }
  146. }
  147. .serial-number {
  148. font-size: 16pt;
  149. }
  150. .content {
  151. flex: 1;
  152. }
  153. &.active {
  154. color: #34343a;
  155. background-color: $main-active-color;
  156. .checkbox {
  157. color: #fff;
  158. background-color: $light-main-color;
  159. .svg-icon {
  160. display: block;
  161. }
  162. }
  163. }
  164. &.answer-right {
  165. background-color: #e8f7f2;
  166. &::after {
  167. font-size: 14px;
  168. color: $right-color;
  169. white-space: nowrap;
  170. content: '正确答案';
  171. }
  172. }
  173. &.wrong {
  174. background-color: $content-color;
  175. box-shadow: 0 0 0 1px $error-color;
  176. &::after {
  177. font-size: 14px;
  178. color: #a09fa6;
  179. white-space: nowrap;
  180. content: '已选';
  181. }
  182. }
  183. }
  184. }
  185. }
  186. </style>