danxuan.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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="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. } = useQuestionTools();
  35. const props = defineProps({
  36. question: {
  37. type: Object,
  38. },
  39. showError: {
  40. type: Boolean,
  41. default: false
  42. }
  43. })
  44. const data = reactive({
  45. name: '', //题干数据
  46. score: '',
  47. result: '',
  48. reply: '',
  49. answer: '',
  50. contents: [], // 选项数据
  51. })
  52. watch(() => props.question, (val) => formatData(val), {
  53. immediate: true
  54. })
  55. function formatClass(index) {
  56. if (props.showError) {
  57. return {
  58. active_right: props.question.result == index,
  59. showError: props.question.reply == index && props.question.result != index
  60. }
  61. } else {
  62. if (props.question.reply === ''||props.question.reply === null ) {
  63. return {
  64. active: false
  65. }
  66. }
  67. return {
  68. active: props.question.reply == index
  69. }
  70. }
  71. }
  72. function formatData(val) {
  73. if (val) {
  74. console.log('val',val);
  75. data.name = val.name;
  76. data.answer = val.answer;
  77. data.score = val.score;
  78. if (val.reply && val.reply.trim() !== '') {
  79. data.reply = getLetterByIndex(val.reply) ;
  80. } else {
  81. data.reply = '未答'
  82. }
  83. if (val.result) {
  84. data.result = getLetterByIndex(val.result);
  85. } else {
  86. data.result = '无答案'
  87. }
  88. data.contents = val.content.map((item, index) => {
  89. return {
  90. label: item,
  91. number: getLetterByIndex(index)
  92. }
  93. })
  94. console.log('data.contents',data.contents);
  95. }
  96. }
  97. function onSelect(index) {
  98. if (props.showError) {
  99. return;
  100. }
  101. props.question.reply = index;
  102. }
  103. </script>