From 60c5fba4299ee7a29f282f59b1511ef402a53cad Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期四, 27 六月 2024 10:03:44 +0800
Subject: [PATCH] 优化

---
 src/assets/methods/examination.js |   69 +++++++++++++++++++++++-----------
 1 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/src/assets/methods/examination.js b/src/assets/methods/examination.js
index dd275f7..0da5175 100644
--- a/src/assets/methods/examination.js
+++ b/src/assets/methods/examination.js
@@ -1,7 +1,16 @@
-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: "鍗曢�夐",
@@ -29,9 +38,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 +62,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,11 +88,12 @@
         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, // 鏌ョ湅瑙f瀽
         isRight: null, // 鏄惁姝g‘
         isComplete: false,
@@ -137,7 +154,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 +168,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");
         });
       }
       // 瑙f瀽瀵屾枃鏈鐞�
@@ -178,9 +195,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 +207,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 +220,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;

--
Gitblit v1.9.1