123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <template>
- <view
- class="question-item"
- :class="{
- 'question-item-correct': isSelected && isCorrect,
- 'question-item-wrong': isSelected && !isCorrect,
- }"
- @tap="handleClick"
- >
- <view
- class="option-label"
- :class="{
- 'option-label-correct': isSelected && isCorrect,
- 'option-label-wrong': isSelected && !isCorrect,
- }"
- >
- {{ TopicMapList[index] }}
- </view>
- <view class="option-text">{{ question.label }}</view>
- </view>
- </template>
- <script setup>
- import { ref, computed } from "vue";
- const TopicMapList = ["A", "B", "C", "D", "E"];
- // Props 定义
- const props = defineProps({
- answerList: {
- type: Array,
- default: () => [],
- },
- index: {
- type: Number,
- required: true,
- },
- selectCount: {
- type: Array,
- default: () => [],
- },
- question: {
- type: Object,
- required: true,
- default: () => ({
- label: "",
- value: 0,
- }),
- },
- parindex: {
- type: Number,
- required: true,
- },
- });
- // Emits 定义
- const emit = defineEmits(["select", "showAnswer"]);
- // 计算属性
- const isSelected = computed(() =>
- props.selectCount.includes(props.question.value)
- );
- const isCorrect = computed(() =>
- props.answerList.includes(props.question.value)
- );
- // 方法
- const handleClick = () => {
- if (
- isSelected.value ||
- props.selectCount.length === props.answerList.length
- ) {
- return;
- }
- if (props.answerList.length - 1 === props.selectCount.length) {
- emit("showAnswer", true);
- }
- emit("select", props.question.value, props.parindex);
- };
- </script>
- <style lang="scss" scoped>
- @import "@/uni.scss";
- .question-item {
- display: flex;
- padding: 16px;
- border: 1px solid #ccc;
- border-radius: 8px;
- background-color: #f5f5f5;
- gap: 12px;
- align-items: center;
- color: #333;
- }
- .question-item-correct {
- border-color: $success;
- background-color: #e8f5e9;
- }
- .question-item-wrong {
- border-color: $error;
- background-color: #ffebee;
- }
- .option-label {
- border: 1px solid #ccc;
- border-radius: 50%;
- padding: 0 4px;
- }
- .option-label-correct {
- border-color: $success;
- background-color: $success;
- color: #fff;
- }
- .option-label-wrong {
- border-color: $error;
- background-color: $error;
- color: #fff;
- }
- .option-text {
- flex: 1;
- }
- </style>
|