From f165c79ce81b7f96cf5a0881671a8e0f36ce1f59 Mon Sep 17 00:00:00 2001
From: litian <2804272236@qq.com>
Date: 星期五, 24 一月 2025 10:51:33 +0800
Subject: [PATCH] Merge branch 'master' of http://182.92.203.7:2001/r/testbookLayout

---
 src/assets/methods/examination.js |  114 ++++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 80 insertions(+), 34 deletions(-)

diff --git a/src/assets/methods/examination.js b/src/assets/methods/examination.js
index a1dffd6..742e446 100644
--- a/src/assets/methods/examination.js
+++ b/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, // 鏌ョ湅瑙f瀽
         isRight: null, // 鏄惁姝g‘
         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");
         });
       }
       // 瑙f瀽瀵屾枃鏈鐞�
@@ -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,55 @@
       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: [],
+    },
+  ];
+  const res = await MG.identity.getUserKey({
+    domain: "collectData",
+    keys: [activeBook.bookId],
+  });
+  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("鏆傛棤鏁版嵁");
+  }
+  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;

--
Gitblit v1.9.1