From 4756ebe5cd7f236eac6d45dbe7a609f6a8f14d68 Mon Sep 17 00:00:00 2001
From: ZhangXianQiang <1135831638@qq.com>
Date: 星期三, 19 六月 2024 11:05:18 +0800
Subject: [PATCH] fix(考试):修改单选取消选择

---
 src/views/exam/components/answer-main/answer-single/index.vue |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/views/exam/components/answer-main/answer-single/index.vue b/src/views/exam/components/answer-main/answer-single/index.vue
index b67815a..b58b59f 100644
--- a/src/views/exam/components/answer-main/answer-single/index.vue
+++ b/src/views/exam/components/answer-main/answer-single/index.vue
@@ -17,20 +17,25 @@
 
 <script setup>
 import { ref } from 'vue';
-import {storeToRefs} from 'pinia';
+import { storeToRefs } from 'pinia';
 import ExamInfo from '@/components/ExamInfo/index.vue';
-import {useExamStore} from '@/store/index.js';
+import { useExamStore } from '@/store/index.js';
 const examStore = useExamStore();
 
-const {currentType,currentIndex} = storeToRefs(examStore);
+const { currentType, currentIndex } = storeToRefs(examStore);
 
 const activeQuestion = ref(examStore.getActiveQuestion);
 
 const answerClick = (item) => {
-  if(item) {
-    resetAnswer();
-    item.isActive = true;
-    examStore.setQuestionAnswer(currentType.value, currentIndex.value, item.prefix);
+  if (item) {
+    if (item.isActive) {
+      item.isActive = !item.isActive;
+    } else {
+      resetAnswer();
+      item.isActive = true;
+    }
+    const answerList = filterAnswer();
+    examStore.setQuestionAnswer(currentType.value, currentIndex.value, answerList.join(','));
   }
 };
 
@@ -38,10 +43,14 @@
   return {
     active: item.isActive
   };
-}
+};
 
 const resetAnswer = () => {
   activeQuestion.value.items.forEach(item => item.isActive = false);
+};
+
+const filterAnswer = () => {
+  return activeQuestion.value.items.filter(item => item.isActive);
 }
 
 
@@ -85,6 +94,7 @@
 
 .active {
   border-color: #409EFF !important;
+
   .answer-icon {
     color: #ffffff !important;
     border-color: #409EFF !important;

--
Gitblit v1.8.0