123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <template>
- <view
- class="question-item"
- :class="{
- 'question-item-correct': mode === 'practice' && isSelected && isCorrect,
- 'question-item-wrong': mode === 'practice' && isSelected && !isCorrect,
- 'question-item-selected': mode === 'exam' && isSelected
- }"
- @tap="handleClick"
- >
- <view
- class="option-label"
- :class="{
- 'option-label-correct': mode === 'practice' && isSelected && isCorrect,
- 'option-label-wrong': mode === 'practice' && isSelected && !isCorrect,
- 'option-label-selected': mode === 'exam' && isSelected
- }"
- >
- {{ TopicMapList[index] }}
- </view>
- <view class="option-text">{{ question.label }}</view>
- </view>
- </template>
- <script setup>
- import { 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,
- },
- mode: {
- type: String,
- default: "exam", // practice: 练习模式, exam: 考试模式
- },
- });
- // 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) {
- emit("select", props.question.value, props.parindex);
- return;
- }
- // 如果是练习模式,且已经达到答案数量,则不允许继续选择
- if (props.mode === 'practice' && props.selectCount.length === props.answerList.length) {
- return;
- }
- // 如果是练习模式,且即将完成所有选择,则显示答案
- if (props.mode === 'practice' && 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;
- }
- .question-item-selected {
- border-color: $uni-primary;
- background-color: #e3f2fd;
- }
- .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-label-selected {
- border-color: $uni-primary;
- background-color: $uni-primary;
- color: #fff;
- }
- .option-text {
- flex: 1;
- }
- </style>
|