ZhangXianQiang
2024-07-05 98f494cf633e3acf5c20f3e9de0d708f2a6c2045
src/store/modules/exam.js
@@ -1,153 +1,47 @@
import { ref,computed } from 'vue';
import { ref, computed } from 'vue';
import { defineStore } from 'pinia';
export const useExamStore = defineStore('exam', () => {
  const examInfo = ref({
    examId: 1,
    examName: '考试名称',
    examType: '考试类型',
    examStatus: '考试状态',
    examStartTime: '2021-01-01',
    examEndTime: '2021-01-01',
  });
  const examInfo = ref(null);
  const examDetail = ref([]);
  const examType = ref({
    1: '单选题',
    2: '多选题'
    2: '多选题',
    3: '判断题',
    4: '填空题',
    5: '简答题',
    6: '语音题',
    7: '计算题',
    8: '分析题',
  });
  const currentType = ref(1);
  const currentIndex = ref(0);
  const examDetail = ref([
    {
      questionType: 1,
      questionList: [
        {
          "id": null,
          "questionType": 1,
          "gradeLevel": null,
          "subjectId": 2,
          "title": "1+1=?123",
          "items": [
            {
              "prefix": "A",
              "content": "1"
            },
            {
              "prefix": "B",
              "content": "2"
            },
            {
              "prefix": "C",
              "content": "3"
            },
            {
              "prefix": "D",
              "content": "4"
            }
          ],
          "analyze": "问小朋友",
          "correct": "B",
          "score": "",
          "difficult": 5
        },
        {
          "id": null,
          "questionType": 1,
          "gradeLevel": null,
          "subjectId": 2,
          "title": "1+1=?",
          "items": [
            {
              "prefix": "A",
              "content": "1"
            },
            {
              "prefix": "B",
              "content": "2"
            },
            {
              "prefix": "C",
              "content": "3"
            },
            {
              "prefix": "D",
              "content": "4"
            }
          ],
          "analyze": "问小朋友",
          "correct": "B",
          "score": "",
          "difficult": 5
        }
      ]
    },
    {
      questionType: 2,
      questionList: [
        {
          "id": null,
          "questionType": 1,
          "gradeLevel": null,
          "subjectId": 2,
          "title": "1+1=?",
          "items": [
            {
              "prefix": "A",
              "content": "1"
            },
            {
              "prefix": "B",
              "content": "2"
            },
            {
              "prefix": "C",
              "content": "3"
            },
            {
              "prefix": "D",
              "content": "4"
            }
          ],
          "analyze": "问小朋友",
          "correct": "B",
          "score": "",
          "difficult": 5
        },
        {
          "id": null,
          "questionType": 1,
          "gradeLevel": null,
          "subjectId": 2,
          "title": "1+1=?",
          "items": [
            {
              "prefix": "A",
              "content": "1"
            },
            {
              "prefix": "B",
              "content": "2"
            },
            {
              "prefix": "C",
              "content": "3"
            },
            {
              "prefix": "D",
              "content": "4"
            }
          ],
          "analyze": "问小朋友",
          "correct": "B",
          "score": "",
          "difficult": 5
        }
      ]
    }
  ]);
  const answerProgress = ref(0);
  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 getAnswerInfo = computed(() => {
    let total = 0;
    let grade = 0;
    examDetail.value.forEach(item => {
      total += item.questionList.length;
      item.questionList.forEach(question => {
        grade += Number(question.questionScore);
      });
    });
    return {
      total,
      grade,
    };
  });
  const setExamInfo = (info) => {
    examInfo.value = info;
@@ -157,19 +51,49 @@
    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].answer = answer;
    }
  };
  const setQuestionAnswerList = (type, index, answer) => {
    const temp = examDetail.value.find(item => item.questionType === type);
    if (temp) {
      temp.questionList[index].answerList = answer;
    }
  }
  const setProgress = (progress) => {
    answerProgress.value = progress;
  };
  const initExam = () => {
    answerProgress.value = 0;
    currentIndex.value = 0;
    currentType.value = 1;
  }
  return {
    examInfo,
    examDetail,
    examType,
    activeQuestion,
    currentType,
    currentIndex,
    answerProgress,
    getActiveQuestion,
    getAnswerInfo,
    initExam,
    setExamInfo,
    setExamDetail,
    setActiveQuestion
    setQuestionAnswer,
    setQuestionAnswerList,
    setProgress
  };
});