Matching.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <ModuleBase :type="data.type">
  3. <template #content>
  4. <ul class="option-list">
  5. <li v-for="(li, i) in data.option_list" :key="i" class="option-item">
  6. <div v-for="(item, j) in li" :key="item.mark" class="option">
  7. <span class="serial-number">{{ computeOptionMethods[data.property.serial_number_type_list[j]](i) }}</span>
  8. <el-input v-model="item.content" placeholder="请输入" />
  9. </div>
  10. </li>
  11. </ul>
  12. <div class="answer-tips">答案:</div>
  13. <ul class="answer-list">
  14. <li v-for="(li, i) in data.answer.answer_list" :key="i" class="answer-item">
  15. <template v-for="(item, j) in li">
  16. <span v-if="j === 0" :key="`${j}-${item.mark}`">
  17. {{ computeOptionMethods[data.property.serial_number_type_list[j]](i) }}
  18. </span>
  19. <el-select v-else :key="`${j}-${item.mark}`" v-model="item.mark" placeholder="请选择">
  20. <el-option
  21. v-for="answer in answerList[j - 1]"
  22. :key="answer.value"
  23. :label="answer.label"
  24. :value="answer.value"
  25. />
  26. </el-select>
  27. </template>
  28. </li>
  29. </ul>
  30. </template>
  31. </ModuleBase>
  32. </template>
  33. <script>
  34. import ModuleMixin from '../../common/ModuleMixin';
  35. import { getMatchingData, getOption, getOptionItem } from '@/views/book/courseware/data/matching';
  36. import { computeOptionMethods, serialNumberTypeList } from '@/views/book/courseware/data/common';
  37. export default {
  38. name: 'MatchingPage',
  39. mixins: [ModuleMixin],
  40. data() {
  41. return {
  42. data: getMatchingData(),
  43. computeOptionMethods,
  44. serialNumberTypeList,
  45. };
  46. },
  47. computed: {
  48. answerList() {
  49. let list = Array.from({ length: this.data.property.column_num - 1 }, () => []);
  50. for (let i = 0; i < this.data.option_list.length; i++) {
  51. for (let j = 1; j < this.data.option_list[i].length; j++) {
  52. list[j - 1].push({
  53. label: computeOptionMethods[this.data.property.serial_number_type_list[j]](i),
  54. value: this.data.option_list[i][j].mark,
  55. });
  56. }
  57. }
  58. return list;
  59. },
  60. },
  61. watch: {
  62. 'data.property.column_num': {
  63. handler(val) {
  64. let optionNum = this.data.option_list[0].length;
  65. if (val > optionNum) {
  66. // 修改序号类型列表
  67. this.data.property.serial_number_type_list.push(
  68. serialNumberTypeList[val]?.value || serialNumberTypeList[0].value,
  69. );
  70. // 增加选项
  71. for (let i = 0; i < this.data.option_list.length; i++) {
  72. this.data.option_list[i].push(getOptionItem());
  73. }
  74. // 修改答案列表
  75. this.data.answer.answer_list.forEach((li) => {
  76. li.push({ mark: '' });
  77. });
  78. return;
  79. }
  80. if (val < optionNum) {
  81. this.data.property.serial_number_type_list.splice(-1, 1);
  82. this.data.option_list.forEach((li) => {
  83. li.splice(-1, 1);
  84. });
  85. // 修改答案列表
  86. this.data.answer.answer_list.forEach((li) => {
  87. li.splice(-1, 1);
  88. });
  89. }
  90. },
  91. },
  92. 'data.property.row_num': {
  93. handler(val) {
  94. let optionNum = this.data.option_list.length;
  95. if (val > optionNum) {
  96. for (let i = 0; i < val - optionNum; i++) {
  97. this.data.option_list.push(getOption(this.data.property.column_num));
  98. }
  99. // 增加答案列表
  100. this.data.answer.answer_list.push(Array(this.data.property.column_num).fill(''));
  101. // 将答案列表最后一项的第一个元素设置进答案列表第一项
  102. this.data.answer.answer_list[this.data.answer.answer_list.length - 1][0] = {
  103. mark: this.data.option_list[this.data.option_list.length - 1][0].mark,
  104. };
  105. return;
  106. }
  107. if (val < optionNum) {
  108. this.data.option_list.splice(val);
  109. this.data.answer.answer_list.splice(val);
  110. }
  111. },
  112. },
  113. },
  114. methods: {},
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. @use '@/styles/mixin.scss' as *;
  119. .option-list {
  120. display: flex;
  121. flex-direction: column;
  122. row-gap: 16px;
  123. .option-item {
  124. display: flex;
  125. column-gap: 16px;
  126. .option {
  127. display: flex;
  128. flex: 1;
  129. column-gap: 4px;
  130. align-items: center;
  131. .serial-number {
  132. @include serial-number(32px);
  133. }
  134. }
  135. }
  136. }
  137. .answer-tips {
  138. margin: 16px 0;
  139. }
  140. .answer-list {
  141. display: flex;
  142. flex-direction: column;
  143. row-gap: 16px;
  144. .answer-item {
  145. display: flex;
  146. column-gap: 16px;
  147. span:first-child {
  148. width: 70px;
  149. height: 32px;
  150. padding: 4px 8px;
  151. color: #c9cdd4;
  152. background-color: $fill-color;
  153. }
  154. .el-select {
  155. flex: 1;
  156. }
  157. }
  158. }
  159. </style>