闫增涛
2024-05-28 a47e8ae08413b99a7fcd4195a535687234b0160f
src/assets/methods/examination.js
@@ -1,28 +1,37 @@
import { activeBook } from "@/assets/js/config";
import MG from "@/assets/js/middleGround/WebMiddleGroundApi";
import getPublicImage from "@/assets/js/middleGround/tool";
const getQuestionList = async (questionList) => {
const getQuestionList = async (page, questionList,activeBook) => {
  console.log('page',page);
  const oldAnswerData = localStorage.getItem(activeBook.name + 'oldAnswerData')
  let oldData = null
  let oldList = []
  if(oldAnswerData) {
    oldData = JSON.parse(oldAnswerData)
  }
 if(oldData && oldData[page]) {
  oldList = oldData[page]
 }
  let cardList = [
    {
      catalogName: "单选题",
      infoList: [],
      infoList: []
    },
    {
      catalogName: "判断题",
      infoList: [],
      infoList: []
    },
    {
      catalogName: "多选题",
      infoList: [],
      infoList: []
    },
    {
      catalogName: "填空题",
      infoList: [],
      infoList: []
    },
    {
      catalogName: "简答题",
      infoList: [],
    },
      infoList: []
    }
  ];
  let singleChoiceArr = []; // 单选
  let judgeArr = []; // 判断
@@ -32,6 +41,7 @@
  for (let qindex = 0; qindex < questionList.length; qindex++) {
    const qitem = questionList[qindex];
    let query = {
      storeInfo: activeBook.storeRefcode,
      path: "*",
      cmsPath: activeBook.rootCmsItemId,
      cmsType: "*",
@@ -47,11 +57,16 @@
        Embedded_QuestionBank_StemStyle: [],
        Embedded_QuestionBank_OptionStyle: [],
        Embedded_QuestionBank_KnowledgePoint: [],
        Embedded_QuestionBank_Difficulty: [],
      },
        Embedded_QuestionBank_Difficulty: []
      }
    };
    const res = await MG.store.getProductDetail(query);
    if(!res.datas) return false
    res.datas.cmsDatas[0].datas.forEach((item, index) => {
      let oldObj = {};
      if (oldList) {
        oldObj = oldList.find((item) => item.id == qitem);
      }
      const questionObj = {
        number: index + 1, // 题号
        id: item.id,
@@ -72,16 +87,17 @@
        difficulty: item.Embedded_QuestionBank_Difficulty
          ? 4 - item.Embedded_QuestionBank_Difficulty
          : 0, // 难度等级
        userAnswer:
          item.Embedded_QuestionBank_QuestionType == "completion" ||
          item.Embedded_QuestionBank_QuestionType == "multipleChoice"
            ? []
            : "",
        userAnswer: oldObj
          ? oldObj.userAnswer
          : item.Embedded_QuestionBank_QuestionType == "completion" ||
            item.Embedded_QuestionBank_QuestionType == "multipleChoice"
          ? []
          : "",
        isSubmit: false, // 查看解析
        isRight: null, // 是否正确
        isComplete: false,
        isCollect: true,
        isUnfold: "",
        isUnfold: ""
      };
      // 多选和填空答案肯为数组,要转换JSON格式
      if (
@@ -102,7 +118,7 @@
          if (item == "input") {
            questionObj.stem[i] = {
              num: index,
              data: "input",
              data: "input"
            };
            questionObj.userAnswer[index] = "";
            index++;
@@ -137,7 +153,7 @@
            '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
          )
          .replace(/\<p/gi, '<p class="stem-rich-p"')
          .replace("../file", app.config.requestCtx + "/file");
          .replace("../file", process.env.VUE_APP_API_URL + "/file");
      }
      // 选项富文本处理
      if (
@@ -151,7 +167,7 @@
            item.txt = item.txt
              .replace(/\<img/gi, '<img class="option-rich-img"')
              .replace(/\<p/gi, '<p class="stem-rich-p"')
              .replace("../file", app.config.requestCtx + "/file");
              .replace("../file", process.env.VUE_APP_API_URL + "/file");
        });
      }
      // 解析富文本处理
@@ -178,9 +194,7 @@
      } else if (item.Embedded_QuestionBank_QuestionType == "singleChoice") {
        questionObj.type = "单选题";
        singleChoiceArr.push(questionObj);
      } else if (
        item.Embedded_QuestionBank_QuestionType == "multipleChoice"
      ) {
      } else if (item.Embedded_QuestionBank_QuestionType == "multipleChoice") {
        questionObj.type = "多选题";
        multipleChoiceArr.push(questionObj);
      } else if (item.Embedded_QuestionBank_QuestionType == "completion") {
@@ -192,11 +206,11 @@
      }
    });
  }
  cardList[0].infoList = singleChoiceArr,
  cardList[1].infoList = judgeArr
  cardList[2].infoList = multipleChoiceArr
  cardList[3].infoList = completionArr
  cardList[4].infoList = shortArr
  cardList[0].infoList = singleChoiceArr;
  cardList[1].infoList = judgeArr;
  cardList[2].infoList = multipleChoiceArr;
  cardList[3].infoList = completionArr;
  cardList[4].infoList = shortArr;
  for (let index = 0; index < cardList.length; index++) {
    const item = cardList[index];
    for (let cindex = 0; cindex < item.infoList.length; cindex++) {
@@ -204,16 +218,25 @@
      citem.number = cindex + 1;
    }
  }
  console.log(cardList.filter(item=>item.infoList.length > 0),"cardList.filter(item=>item.infoList.length > 0)");
  return cardList.filter(item=>item.infoList.length > 0);
  return cardList.filter((item) => item.infoList.length > 0);
};
const getQuestionData = async (chapterData) => {
const getQuestionData = async (chapter, chapterData,activeBook) => {
  const data = { ...chapterData };
  const oldAnswerData = localStorage.getItem("oldAnswerData");
  const oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {};
  let oldChapterData;
  if (oldData) {
    oldChapterData = oldData[chapter];
  }
  for (let key in chapterData) {
    data[key] = await getQuestionList(chapterData[key]);
    let oldList = [];
    if (oldChapterData) {
      oldList = oldChapterData[key];
    }
    data[key] = await getQuestionList(oldList, chapterData[key],activeBook);
  }
  return data;
};
export default getQuestionData;
export default getQuestionList;