duoxuan.vue 2.8 KB

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