SelectPreview.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="select-preview" :style="[getAreaStyle(), getComponentStyle()]">
  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="[isSingle ? 'radio' : '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, selectTypeList } 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. computed: {
  56. isSingle() {
  57. return this.data.property?.select_type === selectTypeList[0].value;
  58. },
  59. },
  60. watch: {
  61. 'answer.answer_list': {
  62. handler(val) {
  63. if (val.length === 0) {
  64. this.answer.is_right = false;
  65. return;
  66. }
  67. if (val.length !== this.data.answer.answer_list.length) {
  68. this.answer.is_right = false;
  69. return;
  70. }
  71. this.answer.is_right = val.every((item) => this.data.answer.answer_list.includes(item));
  72. },
  73. deep: true,
  74. },
  75. },
  76. methods: {
  77. computedOptionNumber(number) {
  78. let type = serialNumberTypeList.find((item) => item.value === this.data.property.option_serial_type)?.value;
  79. if (!type) return number + 1;
  80. return computeOptionMethods[type](number);
  81. },
  82. isAnswer(mark) {
  83. return this.answer.answer_list.includes(mark);
  84. },
  85. selectAnswer(mark) {
  86. if (this.disabled) return;
  87. const list = this.answer.answer_list || [];
  88. const isSelected = list.includes(mark);
  89. if (this.isSingle) {
  90. this.answer.answer_list = isSelected ? [] : [mark];
  91. return;
  92. }
  93. this.answer.answer_list = isSelected ? list.filter((item) => item !== mark) : list.concat(mark);
  94. },
  95. computedAnswerClass(mark) {
  96. if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
  97. return [];
  98. }
  99. let isHas = this.answer.answer_list.includes(mark); // 用户是否已选中
  100. let isRight = this.data.answer.answer_list.includes(mark); // 是否是正确答案
  101. let answerClass = [];
  102. if (!isHas && this.isShowRightAnswer) {
  103. answerClass = isRight ? ['answer-right'] : [];
  104. }
  105. // 判断是否是正确答案
  106. if (isHas && this.isJudgingRightWrong) {
  107. answerClass = isRight ? ['answer-right'] : ['wrong'];
  108. }
  109. return answerClass;
  110. },
  111. },
  112. };
  113. </script>
  114. <style lang="scss" scoped>
  115. @use '@/styles/mixin.scss' as *;
  116. .select-preview {
  117. @include preview-base;
  118. .option-list {
  119. display: flex;
  120. flex-flow: column wrap;
  121. gap: 16px;
  122. .option-item {
  123. display: flex;
  124. flex: 1;
  125. flex-wrap: wrap;
  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: 1px solid $content-color;
  133. border-radius: 4px;
  134. .lang {
  135. // width: 100%;
  136. padding-left: 52px;
  137. }
  138. .radio,
  139. .checkbox {
  140. display: flex;
  141. align-items: center;
  142. justify-content: center;
  143. width: 14px;
  144. height: 14px;
  145. margin-right: 8px;
  146. cursor: pointer;
  147. background-color: #fff;
  148. border: 1px solid #dcdfe6;
  149. border-radius: 2px;
  150. .svg-icon {
  151. display: none;
  152. }
  153. }
  154. .radio {
  155. border-radius: 50%;
  156. }
  157. .serial-number {
  158. font-size: 16pt;
  159. }
  160. .content {
  161. flex: 1;
  162. }
  163. &.active {
  164. color: #34343a;
  165. background-color: $main-active-color;
  166. .checkbox {
  167. color: #fff;
  168. background-color: $light-main-color;
  169. .svg-icon {
  170. display: block;
  171. }
  172. }
  173. .radio {
  174. background-color: #fff;
  175. box-shadow: inset 0 0 0 4px $light-main-color;
  176. }
  177. }
  178. &.answer-right {
  179. background-color: #e8f7f2;
  180. &::after {
  181. font-size: 14px;
  182. color: $right-color;
  183. white-space: nowrap;
  184. content: '正确答案';
  185. }
  186. }
  187. &.wrong {
  188. margin: 1px 0;
  189. background-color: $content-color;
  190. box-shadow: 0 0 0 1px $error-color;
  191. &::after {
  192. font-size: 14px;
  193. color: #a09fa6;
  194. white-space: nowrap;
  195. content: '已选';
  196. }
  197. }
  198. }
  199. }
  200. }
  201. </style>