panduan.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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="phone-line-title">答案解析</view>
  21. <view class="btdf-row">本题得分:<text>{{data.score}}</text>分</view>
  22. <view class="zqda-row">正确答案:<text>{{data.result}}</text></view>
  23. <view class="ndda-row">您的答案:<text>{{data.reply}}</text></view>
  24. <view class="dajx-row">答案解析:
  25. <rich-text :nodes="data.answer"></rich-text>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. <script setup>
  31. import {
  32. ref,
  33. reactive,
  34. watch
  35. } from 'vue';
  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. })
  52. watch(() => props.question, (val) => formatData(val), {
  53. immediate: true
  54. })
  55. function formatData(val) {
  56. console.log('val',val);
  57. if (val) {
  58. data.name = val.name;
  59. if (val.reply === '') {
  60. data.reply = '未答'
  61. } else if (val.reply == 0) {
  62. data.reply = '错误'
  63. } else if (val.reply == 1) {
  64. data.reply = '正确'
  65. }
  66. if (val.result == 0) {
  67. data.result = '错误'
  68. } else if (val.result == 1) {
  69. data.result = '正确'
  70. }
  71. data.answer = val.answer;
  72. data.score = val.score;
  73. }
  74. }
  75. function radioChange(e) {
  76. if (props.showError) {
  77. return;
  78. }
  79. props.question.reply = e.detail.value;
  80. }
  81. function formatClass(index) {
  82. if (props.showError) {
  83. return {
  84. active_right: props.question.result == index,
  85. showError: props.question.reply == index && props.question.result != index
  86. }
  87. } else {
  88. return {
  89. active: props.question.reply == index
  90. }
  91. }
  92. }
  93. </script>