duoxuan.vue 2.7 KB

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