SelectPreview.vue 4.9 KB

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