panduan.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view>
  3. <!-- 标题区域 -->
  4. <view>判断题:</view>
  5. <!-- 题干区域 -->
  6. <rich-text :nodes="question.name"></rich-text>
  7. <!-- 选项区域 -->
  8. <view>
  9. <radio-group @change="radioChange">
  10. <label :class="formatClass('1')">
  11. <view>
  12. <radio value="1" :checked="question.reply == '1'" />
  13. </view>
  14. <view>正确</view>
  15. </label>
  16. <label :class="formatClass('0')">
  17. <view>
  18. <radio value="0" :checked="question.reply == '0'" />
  19. </view>
  20. <view>错误</view>
  21. </label>
  22. </radio-group>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup>
  27. const props = defineProps({
  28. question: {
  29. type: Object,
  30. },
  31. showError: {
  32. type: Boolean,
  33. default: false
  34. }
  35. })
  36. function radioChange(e) {
  37. if (props.showError) {
  38. return;
  39. }
  40. props.question.reply = e.detail.value;
  41. }
  42. function formatClass(index) {
  43. if (props.showError) {
  44. return {
  45. active_right: props.question.result == index,
  46. showError: props.question.reply == index && props.question.result != index
  47. }
  48. } else {
  49. return {
  50. active: props.question.reply == index
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .active {
  57. background-color: blue; // 判断题选中的颜色
  58. }
  59. .showError {
  60. background-color: red; // 判断错误选中颜色
  61. }
  62. .active_right {
  63. background-color: green; // 答案解析:单选正确颜色
  64. }
  65. </style>