Questions.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view
  3. class="question-item"
  4. :class="{
  5. 'question-item-correct': isSelected && isCorrect,
  6. 'question-item-wrong': isSelected && !isCorrect,
  7. }"
  8. @tap="handleClick"
  9. >
  10. <view
  11. class="option-label"
  12. :class="{
  13. 'option-label-correct': isSelected && isCorrect,
  14. 'option-label-wrong': isSelected && !isCorrect,
  15. }"
  16. >
  17. {{ TopicMapList[index] }}
  18. </view>
  19. <view class="option-text">{{ question.label }}</view>
  20. </view>
  21. </template>
  22. <script setup>
  23. import { ref, computed } from "vue";
  24. const TopicMapList = ["A", "B", "C", "D", "E"];
  25. // Props 定义
  26. const props = defineProps({
  27. answerList: {
  28. type: Array,
  29. default: () => [],
  30. },
  31. index: {
  32. type: Number,
  33. required: true,
  34. },
  35. selectCount: {
  36. type: Array,
  37. default: () => [],
  38. },
  39. question: {
  40. type: Object,
  41. required: true,
  42. default: () => ({
  43. label: "",
  44. value: 0,
  45. }),
  46. },
  47. parindex: {
  48. type: Number,
  49. required: true,
  50. },
  51. });
  52. // Emits 定义
  53. const emit = defineEmits(["select", "showAnswer"]);
  54. // 计算属性
  55. const isSelected = computed(() =>
  56. props.selectCount.includes(props.question.value)
  57. );
  58. const isCorrect = computed(() =>
  59. props.answerList.includes(props.question.value)
  60. );
  61. // 方法
  62. const handleClick = () => {
  63. if (
  64. isSelected.value ||
  65. props.selectCount.length === props.answerList.length
  66. ) {
  67. return;
  68. }
  69. if (props.answerList.length - 1 === props.selectCount.length) {
  70. emit("showAnswer", true);
  71. }
  72. emit("select", props.question.value, props.parindex);
  73. };
  74. </script>
  75. <style lang="scss" scoped>
  76. @import "@/uni.scss";
  77. .question-item {
  78. display: flex;
  79. padding: 16px;
  80. border: 1px solid #ccc;
  81. border-radius: 8px;
  82. background-color: #f5f5f5;
  83. gap: 12px;
  84. align-items: center;
  85. color: #333;
  86. }
  87. .question-item-correct {
  88. border-color: $success;
  89. background-color: #e8f5e9;
  90. }
  91. .question-item-wrong {
  92. border-color: $error;
  93. background-color: #ffebee;
  94. }
  95. .option-label {
  96. border: 1px solid #ccc;
  97. border-radius: 50%;
  98. padding: 0 4px;
  99. }
  100. .option-label-correct {
  101. border-color: $success;
  102. background-color: $success;
  103. color: #fff;
  104. }
  105. .option-label-wrong {
  106. border-color: $error;
  107. background-color: $error;
  108. color: #fff;
  109. }
  110. .option-text {
  111. flex: 1;
  112. }
  113. </style>