user1
2024-06-28 c7b33fe92cf6d4449ca5919353c15611ae9ad410
src/assets/methods/examination.js
@@ -1,7 +1,18 @@
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) => {
const collectList = await getCollectList(activeBook)
console.log('收藏列表',collectList);
  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: "单选题",
@@ -29,9 +40,11 @@
  let shortArr = []; // 简答
  let multipleChoiceArr = []; // 多选
  let completionArr = []; // 填空
  // 11
  for (let qindex = 0; qindex < questionList.length; qindex++) {
    const qitem = questionList[qindex];
    let query = {
      storeInfo: activeBook.storeRefcode,
      path: "*",
      cmsPath: activeBook.rootCmsItemId,
      cmsType: "*",
@@ -51,7 +64,12 @@
      },
    };
    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,15 +90,16 @@
        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,
        isCollect: collectList.indexOf(qitem) > -1 ? true : false,
        isUnfold: "",
      };
      // 多选和填空答案肯为数组,要转换JSON格式
@@ -137,7 +156,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 +170,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 +197,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 +209,12 @@
      }
    });
  }
  cardList[0].infoList = singleChoiceArr,
  cardList[1].infoList = judgeArr
  cardList[2].infoList = multipleChoiceArr
  cardList[3].infoList = completionArr
  cardList[4].infoList = shortArr
  // 22
  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 +222,61 @@
      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 getCollectList = async(activeBook) => {
  const allCollect = [
    {
      type:'bits',
      collectList:[]
    },
    {
      type:'json',
      collectList:[]
    },
  ]
  await MG.identity
  .getUserKey({
    domain: 'collectData',
    keys: [activeBook.bookId]
  })
  .then((res) => {
    try {
      const collect = JSON.parse(res[0].value)
      if (collect.length) {
        allCollect[0].collectList = collect.find(
          (citem) => citem.type == 'bits'
        ).collectList
        allCollect[1].collectList = collect.find(
          (citem) => citem.type == 'json'
        ).collectList
      }
    } catch (error) {
      console.log('暂无数据')
    }
  })
  .catch(() => {
    console.log('获取收藏报错');
  })
  return allCollect.find(item => item.type == 'bits').collectList
}
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;