1
QYF-GitLab1
2024-12-26 54d141532c864200b19404848ae5a8110535c6ed
src/assets/methods/examination.js
@@ -1,7 +1,20 @@
import { activeBook } from "@/assets/js/config";
import MG from "@/assets/js/middleGround/WebMiddleGroundApi";
import {tokenKey} from '@/assets/js/config'
import getPublicImage from "@/assets/js/middleGround/tool";
const getQuestionList = async (oldList,questionList) => {
// 获取题目列表
const getQuestionList = async (page, questionList, activeBook) => {
const token = localStorage.getItem(tokenKey)
let collectList = []
if(token)  collectList = await getCollectList(activeBook)
  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 +42,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,10 +66,11 @@
      },
    };
    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)
      let oldObj = {};
      if (oldList) {
        oldObj = oldList.find((item) => item.id == qitem);
      }
      const questionObj = {
        number: index + 1, // 题号
@@ -76,15 +92,16 @@
        difficulty: item.Embedded_QuestionBank_Difficulty
          ? 4 - item.Embedded_QuestionBank_Difficulty
          : 0, // 难度等级
        userAnswer:oldObj ? oldObj.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格式
@@ -141,7 +158,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 (
@@ -155,7 +172,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");
        });
      }
      // 解析富文本处理
@@ -182,9 +199,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") {
@@ -196,11 +211,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++) {
@@ -208,25 +224,62 @@
      citem.number = cindex + 1;
    }
  }
  return cardList.filter(item=>item.infoList.length > 0);
  return cardList.filter((item) => item.infoList.length > 0);
};
const getQuestionData = async (chapter,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('获取收藏报错');
  })
  console.log('收藏数据',allCollect.find(item => item.type == 'bits').collectList)
  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]
  const oldAnswerData = localStorage.getItem("oldAnswerData");
  const oldData = oldAnswerData ? JSON.parse(oldAnswerData) : {};
  let oldChapterData;
  if (oldData) {
    oldChapterData = oldData[chapter];
  }
  for (let key in chapterData) {
    let oldList = []
    if(oldChapterData) {
      oldList = oldChapterData[key]
    let oldList = [];
    if (oldChapterData) {
      oldList = oldChapterData[key];
    }
    data[key] = await getQuestionList(oldList,chapterData[key]);
    data[key] = await getQuestionList(oldList, chapterData[key], activeBook);
  }
  return data;
};
export default getQuestionData;
export default getQuestionList;