From 1a20a2c7a9e1ba9a0ffb83fb3d09ee7215d260c4 Mon Sep 17 00:00:00 2001
From: ZhangXianQiang <1135831638@qq.com>
Date: 星期三, 19 六月 2024 09:55:24 +0800
Subject: [PATCH] chore(考试store):简化数据获取

---
 src/store/modules/exam.js |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/store/modules/exam.js b/src/store/modules/exam.js
index fb33503..4622a95 100644
--- a/src/store/modules/exam.js
+++ b/src/store/modules/exam.js
@@ -1,4 +1,4 @@
-import { ref,computed } from 'vue';
+import { ref, computed } from 'vue';
 import { defineStore } from 'pinia';
 export const useExamStore = defineStore('exam', () => {
   const examInfo = ref({
@@ -47,7 +47,7 @@
             }
           ],
           "analyze": "闂皬鏈嬪弸",
-          "correct": "B",
+          "correct": "",
           "score": "",
           "difficult": 5
         },
@@ -76,7 +76,7 @@
             }
           ],
           "analyze": "闂皬鏈嬪弸",
-          "correct": "B",
+          "correct": "",
           "score": "",
           "difficult": 5
         }
@@ -110,7 +110,7 @@
             }
           ],
           "analyze": "闂皬鏈嬪弸",
-          "correct": "B",
+          "correct": "",
           "score": "",
           "difficult": 5
         },
@@ -139,7 +139,7 @@
             }
           ],
           "analyze": "闂皬鏈嬪弸",
-          "correct": "B",
+          "correct": "",
           "score": "",
           "difficult": 5
         }
@@ -148,6 +148,14 @@
   ]);
 
   const activeQuestion = ref(null);
+
+
+  const getActiveQuestion = computed(() => {
+    const temp = examDetail.value.find(item => item.questionType === currentType.value);
+    if(temp) {
+      return temp.questionList[currentIndex.value];
+    }
+  })
 
   const setExamInfo = (info) => {
     examInfo.value = info;
@@ -161,6 +169,14 @@
     activeQuestion.value = detail;
   };
 
+  const setQuestionAnswer = (type, index, answer) => {
+    const temp = examDetail.value.find(item => item.questionType === type);
+    if(temp) {
+      temp.questionList[index].correct = answer;
+    }
+  };
+
+
   return {
     examInfo,
     examDetail,
@@ -168,8 +184,10 @@
     activeQuestion,
     currentType,
     currentIndex,
+    getActiveQuestion,
     setExamInfo,
     setExamDetail,
-    setActiveQuestion
+    setActiveQuestion,
+    setQuestionAnswer
   };
 });

--
Gitblit v1.8.0