danxuan.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view v-if="question" class="phone-danxuan-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="danxuan-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 } = 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 == index,
  71. showError:
  72. props.question.reply == index && props.question.result != index,
  73. };
  74. } else {
  75. if (props.question.reply === "" || props.question.reply === null) {
  76. return {
  77. active: false,
  78. };
  79. }
  80. return {
  81. active: props.question.reply == index,
  82. };
  83. }
  84. }
  85. function formatData(val) {
  86. if (val) {
  87. console.log("val", val);
  88. data.name = val.name;
  89. data.answer = val.answer;
  90. data.score = val.score;
  91. if (val.reply && val.reply.trim() !== "") {
  92. data.reply = getLetterByIndex(val.reply);
  93. } else {
  94. data.reply = "未答";
  95. }
  96. if (val.result) {
  97. data.result = getLetterByIndex(val.result);
  98. } else {
  99. data.result = "无答案";
  100. }
  101. data.contents = val.content.map((item, index) => {
  102. return {
  103. label: item,
  104. number: getLetterByIndex(index),
  105. };
  106. });
  107. console.log("data.contents", data.contents);
  108. }
  109. }
  110. function onSelect(index) {
  111. if (props.showError) {
  112. return;
  113. }
  114. props.question.reply = index;
  115. }
  116. </script>