SelectPreview.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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="convertText(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. <PreviewOperation @showAnswerAnalysis="showAnswerAnalysis" @retry="retry" />
  41. <AnswerCorrect
  42. :answer-correct="data?.answer_correct"
  43. :visible.sync="visibleAnswerCorrect"
  44. @closeAnswerCorrect="closeAnswerCorrect"
  45. />
  46. <AnswerAnalysis
  47. :visible.sync="visibleAnswerAnalysis"
  48. :answer-list="data.answer_list"
  49. :analysis-list="data.analysis_list"
  50. @closeAnswerAnalysis="closeAnswerAnalysis"
  51. >
  52. <ul
  53. slot="right-answer"
  54. class="option-list"
  55. :style="{ flexDirection: data.property.arrange_type === arrangeTypeList[0].value ? 'row' : 'column' }"
  56. >
  57. <li
  58. v-for="({ content, mark, multilingual, paragraph_list }, i) in data.option_list"
  59. :key="mark"
  60. :style="{ cursor: disabled ? 'not-allowed' : 'pointer', borderColor: data.unified_attrib?.topic_color }"
  61. :class="['option-item', { active: isAnswer(mark) }, ...computedAnswerClass(mark, 'answer-analysis')]"
  62. @click="selectAnswer(mark)"
  63. >
  64. <span :class="[isSingle ? 'radio' : 'checkbox']">
  65. <SvgIcon icon-class="check-mark" width="10" height="7" />
  66. </span>
  67. <span class="serial-number"> {{ computedOptionNumber(i) }}. </span>
  68. <PinyinText
  69. v-if="isEnable(data.property.view_pinyin)"
  70. class="content"
  71. :paragraph-list="paragraph_list"
  72. :pinyin-position="data.property.pinyin_position"
  73. :is-preview="true"
  74. />
  75. <span
  76. v-else
  77. class="content rich-text"
  78. :style="{ fontSize: type === typeList[0] ? '12pt' : '' }"
  79. v-html="convertText(sanitizeHTML(content))"
  80. ></span>
  81. <div v-if="showLang" class="lang">
  82. {{ multilingual.find((item) => item.type === getLang())?.translation }}
  83. </div>
  84. </li>
  85. </ul>
  86. </AnswerAnalysis>
  87. </div>
  88. </template>
  89. <script>
  90. import PreviewMixin from '../common/PreviewMixin';
  91. import { getSelectData, arrangeTypeList, selectTypeList } from '@/views/book/courseware/data/select';
  92. import { serialNumberTypeList, computeOptionMethods } from '@/views/book/courseware/data/common';
  93. export default {
  94. name: 'SelectPreview',
  95. mixins: [PreviewMixin],
  96. data() {
  97. return {
  98. data: getSelectData(),
  99. arrangeTypeList,
  100. };
  101. },
  102. computed: {
  103. isSingle() {
  104. return this.data.property?.select_type === selectTypeList[0].value;
  105. },
  106. },
  107. watch: {
  108. 'answer.answer_list': {
  109. handler(val) {
  110. if (val.length === 0) {
  111. this.answer.is_right = false;
  112. return;
  113. }
  114. if (val.length !== this.data.answer.answer_list.length) {
  115. this.answer.is_right = false;
  116. return;
  117. }
  118. this.answer.is_right = val.every((item) => this.data.answer.answer_list.includes(item));
  119. },
  120. deep: true,
  121. },
  122. },
  123. methods: {
  124. computedOptionNumber(number) {
  125. let type = serialNumberTypeList.find((item) => item.value === this.data.property.option_serial_type)?.value;
  126. if (!type) return number + 1;
  127. return computeOptionMethods[type](number);
  128. },
  129. /**
  130. * 判断选项是否被选中
  131. * @param {string} mark - 选项的标识
  132. */
  133. isAnswer(mark) {
  134. return this.answer.answer_list.includes(mark);
  135. },
  136. selectAnswer(mark) {
  137. if (this.disabled) return;
  138. const list = this.answer.answer_list || [];
  139. const isSelected = list.includes(mark);
  140. if (this.isSingle) {
  141. this.answer.answer_list = isSelected ? [] : [mark];
  142. return;
  143. }
  144. this.answer.answer_list = isSelected ? list.filter((item) => item !== mark) : list.concat(mark);
  145. },
  146. /**
  147. * 计算选项的类名
  148. * @param {string} mark - 选项的标识
  149. * @param {string} type - 计算类名的类型,默认为 'default',可选值为 'answer-analysis'
  150. * @returns {Array} - 选项的类名数组
  151. */
  152. computedAnswerClass(mark, type = 'default') {
  153. if (!this.isJudgingRightWrong && !this.isShowRightAnswer) {
  154. return [];
  155. }
  156. let isHas = this.answer.answer_list.includes(mark); // 用户是否已选中
  157. let isRight = this.data.answer.answer_list.includes(mark); // 是否是正确答案
  158. let answerClass = [];
  159. if (!isHas && this.isShowRightAnswer && type === 'answer-analysis') {
  160. answerClass = isRight ? ['answer-right'] : [];
  161. }
  162. // 判断是否是正确答案
  163. if (isHas && this.isJudgingRightWrong) {
  164. answerClass = isRight ? ['answer-right'] : ['wrong'];
  165. }
  166. return answerClass;
  167. },
  168. retry() {
  169. this.answer.answer_list = [];
  170. },
  171. },
  172. };
  173. </script>
  174. <style lang="scss" scoped>
  175. @use '@/styles/mixin.scss' as *;
  176. .select-preview {
  177. @include preview-base;
  178. .option-list {
  179. display: flex;
  180. flex-flow: column wrap;
  181. gap: 16px;
  182. .option-item {
  183. display: flex;
  184. flex: 1;
  185. flex-wrap: wrap;
  186. column-gap: 8px;
  187. align-items: center;
  188. padding: 12px 24px;
  189. color: #706f78;
  190. cursor: pointer;
  191. background-color: $content-color;
  192. border: 1px solid $content-color;
  193. border-radius: 4px;
  194. .lang {
  195. // width: 100%;
  196. padding-left: 52px;
  197. }
  198. .radio,
  199. .checkbox {
  200. display: flex;
  201. align-items: center;
  202. justify-content: center;
  203. width: 14px;
  204. height: 14px;
  205. margin-right: 8px;
  206. cursor: pointer;
  207. background-color: #fff;
  208. border: 1px solid #dcdfe6;
  209. border-radius: 2px;
  210. .svg-icon {
  211. display: none;
  212. }
  213. }
  214. .radio {
  215. border-radius: 50%;
  216. }
  217. .serial-number {
  218. font-size: 16pt;
  219. }
  220. .content {
  221. flex: 1;
  222. }
  223. &.active {
  224. color: #34343a;
  225. background-color: $main-active-color;
  226. .checkbox {
  227. color: #fff;
  228. background-color: $light-main-color;
  229. .svg-icon {
  230. display: block;
  231. }
  232. }
  233. .radio {
  234. background-color: #fff;
  235. box-shadow: inset 0 0 0 4px $light-main-color;
  236. }
  237. }
  238. &.answer-right {
  239. background-color: #e8f7f2;
  240. &::after {
  241. font-size: 14px;
  242. color: $right-color;
  243. white-space: nowrap;
  244. content: '正确答案';
  245. }
  246. }
  247. &.wrong {
  248. margin: 1px 0;
  249. background-color: $content-color;
  250. box-shadow: 0 0 0 1px $error-color;
  251. &::after {
  252. font-size: 14px;
  253. color: #a09fa6;
  254. white-space: nowrap;
  255. content: '已选';
  256. }
  257. }
  258. }
  259. }
  260. }
  261. </style>