duoxuan.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view v-if="question" class="phone-duoxuan-box">
  3. <view class="phone-shiti-question">
  4. <view class="question-num">{{ question.onlyNum }}、</view>
  5. <!-- 题干区域 -->
  6. <rich-text :nodes="data.name"></rich-text>
  7. </view>
  8. <!-- 选项区域 -->
  9. <view
  10. v-for="(item, index) in data.contents"
  11. class="duoxuan-option-box"
  12. :class="formatClass(index)"
  13. :key="index"
  14. >
  15. <text class="option-change" @click="onSelect(index)">{{
  16. item.number
  17. }}</text>
  18. <rich-text :nodes="item.label" class="option-question"></rich-text>
  19. </view>
  20. <view class="phone-question-answer-box">
  21. <view class="phone-line-title">答案解析</view>
  22. <view class="btdf-row"
  23. >本题得分:<text>{{ data.score }}</text
  24. >分</view
  25. >
  26. <view class="zqda-row"
  27. >正确答案:<text>{{ data.result }}</text></view
  28. >
  29. <view class="ndda-row"
  30. >您的答案:<text>{{ data.reply }}</text></view
  31. >
  32. <view class="dajx-row"
  33. >答案解析:
  34. <rich-text :nodes="data.answer"></rich-text>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script setup>
  40. import { ref, reactive, watch } from "vue";
  41. import { useQuestionTools } from "@/utils/useQuestionTools.js";
  42. const { getLetterByIndex, haveSameElements } = useQuestionTools();
  43. const props = defineProps({
  44. question: {
  45. type: Object,
  46. },
  47. showError: {
  48. type: Boolean,
  49. default: false,
  50. },
  51. });
  52. const data = reactive({
  53. name: "", //题干数据
  54. score: "",
  55. result: "",
  56. reply: "",
  57. answer: "",
  58. contents: [], // 选项数据
  59. });
  60. watch(
  61. () => props.question,
  62. (val) => formatData(val),
  63. {
  64. immediate: true,
  65. }
  66. );
  67. function formatClass(index) {
  68. if (props.showError) {
  69. return {
  70. active_right: props.question.result.some((item) => item == index),
  71. showError: !props.question.result.some((item) => item == index),
  72. };
  73. } else {
  74. return {
  75. active: props.question.reply.some((item) => item == index),
  76. };
  77. }
  78. }
  79. function formatData(val) {
  80. if (val) {
  81. data.name = val.name;
  82. if (val.reply && val.reply.length) {
  83. data.reply = val.reply
  84. .map((item) => {
  85. if (item.trim()) {
  86. return getLetterByIndex(item.trim());
  87. }
  88. })
  89. .join(",");
  90. } else {
  91. data.reply = "未答";
  92. }
  93. if (val.result) {
  94. data.result = val.result
  95. .map((item) => {
  96. if (item.trim()) {
  97. return getLetterByIndex(item.trim());
  98. }
  99. })
  100. .join(",");
  101. } else {
  102. data.result = "无答案";
  103. }
  104. data.answer = val.answer;
  105. data.score = val.score;
  106. data.contents = val.content.map((item, index) => {
  107. return {
  108. label: item,
  109. number: getLetterByIndex(index),
  110. };
  111. });
  112. }
  113. }
  114. function onSelect(index) {
  115. if (props.showError) {
  116. return;
  117. }
  118. if (props.question.reply) {
  119. if (props.question.reply.some((item) => item == index)) {
  120. props.question.reply = props.question.reply.filter(
  121. (item) => item != index
  122. );
  123. } else {
  124. props.question.reply.push(index);
  125. }
  126. }
  127. }
  128. </script>