danxuan.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 v-for="(item,index) in data.contents" class="danxuan-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. } = 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 == index,
  60. showError: props.question.reply == index && props.question.result != index
  61. }
  62. } else {
  63. if (props.question.reply === ''||props.question.reply === null ) {
  64. return {
  65. active: false
  66. }
  67. }
  68. return {
  69. active: props.question.reply == index
  70. }
  71. }
  72. }
  73. function formatData(val) {
  74. if (val) {
  75. console.log('val',val);
  76. data.name = val.name;
  77. data.answer = val.answer;
  78. data.score = val.score;
  79. if (val.reply && val.reply.trim() !== '') {
  80. data.reply = getLetterByIndex(val.reply) ;
  81. } else {
  82. reply = '未答'
  83. }
  84. if (val.result) {
  85. data.result = getLetterByIndex(val.result);
  86. } else {
  87. result = '无答案'
  88. }
  89. data.contents = val.content.map((item, index) => {
  90. return {
  91. label: item,
  92. number: getLetterByIndex(index)
  93. }
  94. })
  95. console.log('data.contents',data.contents);
  96. }
  97. }
  98. function onSelect(index) {
  99. if (props.showError) {
  100. return;
  101. }
  102. props.question.reply = index;
  103. }
  104. </script>