ZhangXianQiang
2024-06-19 0a45ebd0372b7209d5b84156ef540d5b0e68c248
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({
@@ -12,7 +12,7 @@
  const examType = ref({
    1: '单选题',
    2: '多选题'
    2: '多选题',
  });
  const currentType = ref(1);
@@ -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
        }
@@ -149,6 +149,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;
  };
@@ -157,9 +165,13 @@
    examDetail.value = detail;
  };
  const setActiveQuestion = (detail) => {
    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,
@@ -168,8 +180,9 @@
    activeQuestion,
    currentType,
    currentIndex,
    getActiveQuestion,
    setExamInfo,
    setExamDetail,
    setActiveQuestion
    setQuestionAnswer
  };
});