panduan.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <view class="phone-panduan-box">
  3. <view class="phone-shiti-question">
  4. <view class="question-num">{{question.onlyNum}}、</view>
  5. <!-- 题干区域 -->
  6. <rich-text :nodes="question.name"></rich-text>
  7. </view>
  8. <!-- 选项区域 -->
  9. <radio-group @change="radioChange" class="panduan-option-box">
  10. <label class="option-question" :class="formatClass('1')">
  11. <radio value="1" :disabled="showError" :checked="question.reply == '1'"/>
  12. <view>正确</view>
  13. </label>
  14. <label class="option-question" :class="formatClass('0')">
  15. <radio value="0" :disabled="showError" :checked="question.reply == '0'"/>
  16. <view>错误</view>
  17. </label>
  18. </radio-group>
  19. <view class="phone-question-answer-box">
  20. <view class="zqda-row">正确答案:<text>{{data.result}}</text></view>
  21. <view class="ndda-row">您的答案:<text>{{data.reply}}</text></view>
  22. <view class="btdf-row">本题得分:<text>{{data.score}}</text>分</view>
  23. <view class="dajx-row">答案解析:
  24. <rich-text :nodes="data.answer"></rich-text>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script setup>
  30. import {
  31. ref,
  32. reactive,
  33. watch
  34. } from 'vue';
  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. })
  51. watch(() => props.question, (val) => formatData(val), {
  52. immediate: true
  53. })
  54. function formatData(val) {
  55. console.log('val',val);
  56. if (val) {
  57. data.name = val.name;
  58. if (val.reply === '') {
  59. data.reply = '未答'
  60. } else if (val.reply == 0) {
  61. data.reply = '错误'
  62. } else if (val.reply == 1) {
  63. data.reply = '正确'
  64. }
  65. if (val.result == 0) {
  66. data.result = '错误'
  67. } else if (val.result == 1) {
  68. data.result = '正确'
  69. }
  70. data.answer = val.answer;
  71. data.score = val.score;
  72. }
  73. }
  74. function radioChange(e) {
  75. if (props.showError) {
  76. return;
  77. }
  78. props.question.reply = e.detail.value;
  79. }
  80. function formatClass(index) {
  81. if (props.showError) {
  82. return {
  83. active_right: props.question.result == index,
  84. showError: props.question.reply == index && props.question.result != index
  85. }
  86. } else {
  87. return {
  88. active: props.question.reply == index
  89. }
  90. }
  91. }
  92. </script>