From aef06b129be7a3a12ac097db8e372b0cb33c6c42 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期二, 02 四月 2024 09:15:19 +0800
Subject: [PATCH] 我的建议,笔记bug修改

---
 packageBookService/pages/bookServices/examination/examination.js | 1289 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 998 insertions(+), 291 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js
index a880c26..83953d8 100644
--- a/packageBookService/pages/bookServices/examination/examination.js
+++ b/packageBookService/pages/bookServices/examination/examination.js
@@ -1,4 +1,6 @@
-import { getPublicImage } from '../../../../assets/js/middleGround/tool'
+import {
+  getPublicImage
+} from '../../../../assets/js/middleGround/tool'
 const app = getApp()
 Page({
 
@@ -9,32 +11,55 @@
     barHeight: "",
     navBarHeight: "",
     loading: false,
-    answerTitle: "",  // 瀵艰埅鏍忔爣棰�
-    countdownInterval: null,   // 璁℃椂鍣�
+    answerTitle: "", // 瀵艰埅鏍忔爣棰�
+    countdownInterval: null, // 璁℃椂鍣�
     isCountdownRunning: true, // 鏄惁鍊掕鏃�
-    countdownTime: 0,  // 鍊掕鏃舵椂闂�
+    countdownTime: 0, // 鍊掕鏃舵椂闂�
     bookId: "",
     productLinkPath: "",
     rootCmsItemId: "",
-    idPathList: [],  // 棰樼洰鍒楄〃
-    answerType: "",  // 绛旈妯″紡
-    submitStatus: false,  // 鎻愪氦鐘舵��
+    idPathList: [], // 棰樼洰鍒楄〃
+    answerType: "", // 绛旈妯″紡
+    submitStatus: false, // 鎻愪氦鐘舵��
     currentIndex: 0, // 褰撳墠鏄剧ず鐨勯鍙�
-    collectList: [],   //  鏀惰棌棰樼洰鍒楄〃 
-    errorList: [],  // 閿欓鍒楄〃
-    subjectiveTotal: 0,  // 瀹㈣棰樻�绘暟
+    collectList: [], //  鏀惰棌棰樼洰鍒楄〃 
+    errorList: [], // 閿欓鍒楄〃
+    subjectiveTotal: 0, // 瀹㈣棰樻�绘暟
     subjectiveNum: 0, // 瀹㈣棰樺緱鍒�
     subjectiveGrade: 0, // 瀹㈣棰樻�诲垎
-    correctNum: 0,  // 姝g‘棰樼洰鏁伴噺
-    total: 0,   // 棰樼洰鎬绘暟
-    cardList: [],  // 鎻愪氦椤�,
-    questionDataList: [],  // 鏄剧ず棰樼洰鍒楄〃
+    correctNum: 0, // 姝g‘棰樼洰鏁伴噺
+    total: 0, // 棰樼洰鎬绘暟
+    cardList: [], // 鎻愪氦椤�,
+    questionDataList: [], // 鏄剧ず棰樼洰鍒楄〃
+    mockid: 0,
+    uuid: 0,
+    mockData: {
+      // 缁勫嵎淇℃伅
+      state: '0',
+      score: 0, // 鎬诲垎
+      sumTime: 0,
+      time: 0, // 绛旈鍓╀綑鏃堕棿
+      datas: [], // 鎵�鏈夋ā鑰冭褰曟暟鎹�(棰樼洰鍒楄〃锛岀敤鎴风瓟棰橈紝鑰冭瘯鎶ュ憡)
+      answer: []
+    },
+    saveTime: 20,
+    isNight: false,
+    sliderValue: 0, // 瀛椾綋婊戝潡
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad(options) {
+    // wx.enableAlertBeforeUnload({
+    //   message: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰橈紵",
+    //   success: function (res) {
+    //     console.log('纭畾', res);
+    //   },
+    //   fail: function (err) {
+    //     console.log("澶辫触锛�", err);
+    //   },
+    // });
     const systInfo = wx.getSystemInfoSync();
     const menu = wx.getMenuButtonBoundingClientRect(); // 鑳跺泭淇℃伅
     const navBarHeight = (menu.top - systInfo.statusBarHeight) * 2 + menu.height; // 瀵艰埅鏍忛珮搴�
@@ -46,8 +71,14 @@
       productLinkPath: options.productLinkPath ? options.productLinkPath : '',
       rootCmsItemId: options.rootCmsItemId,
       idPathList: options.idPathList ? JSON.parse(options.idPathList) : [],
-      answerType: options.answerType
+      answerType: options.answerType,
     });
+    if (this.data.answerType == 'mock') {
+      this.setData({
+        uuid: options.uuid,
+        mockid: options.mockid
+      })
+    }
     this.init()
     console.log('浼犲弬', options);
   },
@@ -55,28 +86,48 @@
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍒濇娓叉煋瀹屾垚
    */
-  onReady() {
-
-  },
+  onReady() {},
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず
    */
   onShow() {
-
+    if (this.data.answerType != 'mock') {
+      if (wx.timer) {
+        clearInterval(wx.timer)
+      }
+    }
+    if (this.data.answerType == 'mock') {
+      if (wx.timer) {
+        clearInterval(wx.timer)
+      }
+      wx.timer = setInterval(() => {
+        this.setData({
+          saveTime: this.data.saveTime - 1
+        })
+        if (this.data.saveTime == 0) {
+          this.saveMockData()
+        }
+      }, 1000)
+    }
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰闅愯棌
    */
   onHide() {
-
+    if (wx.timer) {
+      clearInterval(wx.timer)
+    }
   },
 
   /**
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍗歌浇
    */
-  onUnload() {
+  onUnload(e) {
+    if (wx.timer) {
+      clearInterval(wx.timer)
+    }
     if (this.data.countdownInterval !== null) {
       clearInterval(this.data.countdownInterval)
     }
@@ -99,13 +150,43 @@
   /**
    * 鐢ㄦ埛鐐瑰嚮鍙充笂瑙掑垎浜�
    */
-  onShareAppMessage() {
+  onShareAppMessage() {},
+
+  // 鐩戝惉watch
+  watch(context, variableName, callback) {
+    let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊�
+
+    // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter
+    Object.defineProperty(context.data, variableName, {
+      configurable: true, // 鍙厤缃�
+      enumerable: true, // 鍙灇涓�
+      get: function () {
+        return value; // 杩斿洖灞炴�х殑褰撳墠鍊�
+      },
+      set: function (newVal) {
+        const oldVal = value; // 璁板綍灞炴�х殑鏃у��
+        value = newVal; // 鏇存柊灞炴�х殑鍊�
+        callback.call(context, newVal, oldVal); // 璋冪敤鍥炶皟鍑芥暟锛屼紶閫掓柊鍊煎拰鏃у��
+      }
+    });
+  },
+  onChangeSlider(e) {
+    this.setData({
+      sliderValue: e.detail.value
+    })
+    console.log(e.detail.value);
   },
   // 杩斿洖
   goBack() {
+    console.log(this.data.submitStatus);
     wx.navigateBack();
   },
-
+  //璁剧疆鑳屾櫙鑹�
+  changeBGColor(e) {
+    this.setData({
+      isNight: e.detail.value
+    })
+  },
   // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂�
   getSavedTime() {
     const savedTime = wx.getStorageSync('countdownTime')
@@ -166,13 +247,21 @@
       currentIndex: e.detail.index
     })
     let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
-    let flag = this.isHaveAnswer(this.data.questionDataList[index].userAnswer)
-    if (flag) this.handleQuestion(e.detail.index)
-
+    const item = this.data.questionDataList[index]
+    if ((this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
+      let flag = this.isHaveAnswer(item.userAnswer)
+      if (flag) this.handleQuestion(index)
+    }
+  },
+  // 鎴戠殑閿欓锛屾敹钘忔煡鐪嬭В鏋愭寜閽�
+  viewParsing() {
+    if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') {
+      const item = this.data.questionDataList[this.data.currentIndex]
+      if (!item.isComplete) this.handleQuestion(this.data.currentIndex)
+    }
   },
   // 鐐瑰嚮绛旈鍗¤烦杞鐩�
   goQuestion(e) {
-    console.log(e);
     const id = e.detail.id
     this.data.questionDataList.forEach((item, index) => {
       if (item.id == id) {
@@ -188,31 +277,86 @@
     const id = e.detail.value.currentTarget.dataset.id
     const radioChecked = e.detail.value.detail.value
     const questionList = this.data.questionDataList
-    questionList.forEach(item => {
-      if (item.id == id) {
+    // 鎴戠殑閿欓鍜屾垜鐨勬敹钘忔ā寮忎笅锛屽崟閫夐閫夋嫨浜嗙洿鎺ユ壒鏀�
+    for (let index = 0; index < questionList.length; index++) {
+      const item = questionList[index];
+      if (item.id == id && !item.isComplete) {
         item.userAnswer = radioChecked
+        item.isUserAnswer = this.isHaveAnswer(radioChecked)
+        if ((item.questionType == 'singleChoice' || item.questionType == 'judge') && (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
+          this.handleQuestion(this.data.currentIndex)
+        }
       }
-    })
+    }
+    // questionList.forEach(item => {
+    //   if (item.id == id && !item.isComplete) {
+    //     item.userAnswer = radioChecked
+    //     item.isUserAnswer = this.isHaveAnswer(radioChecked)
+    //     if ((item.questionType == 'singleChoice' || item.questionType == 'judge') && (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') && !item.isComplete) {
+    //       this.handleQuestion(this.data.currentIndex)
+    //     }
+    //   }
+    // })
+    const cardListUpdata = this.data.cardList
+    for (let index = 0; index < cardListUpdata.length; index++) {
+      const item = cardListUpdata[index];
+      for (let cindex = 0; cindex < item.infoList.length; cindex++) {
+        const citem = item.infoList[cindex];
+        if (citem.id == id && !citem.isComplete) {
+          citem.userAnswer = radioChecked
+          citem.isUserAnswer = this.isHaveAnswer(radioChecked)
+        }
+      }
+    }
+    // cardListUpdata.forEach(item => {
+    //   item.infoList.forEach(citem => {
+    //     if (citem.id == id && !citem.isComplete) {
+    //       citem.userAnswer = radioChecked
+    //       citem.isUserAnswer = this.isHaveAnswer(radioChecked)
+    //     }
+    //   })
+    // })
     this.setData({
-      questionDataList: questionList
+      questionDataList: questionList,
+      cardList: cardListUpdata
     })
-    console.log(this.data.questionDataList);
+    if (this.data.answerType == 'mock') {
+      this.setData({
+        saveTime: 20
+      })
+    }
   },
   // 杈撳叆妗嗚Е鍙�
   onChangeInput(e) {
     const inputData = e.detail.value.detail.value
     const id = e.detail.value.currentTarget.dataset.id
-    const index = e.detail.value.currentTarget.dataset.index
+    const index = Number(e.detail.value.currentTarget.dataset.index)
+    console.log(index);
     const questionList = this.data.questionDataList
     questionList.forEach(item => {
       if (item.id == id) {
         item.userAnswer[index] = inputData
+        return item.isUserAnswer = this.isHaveAnswer(inputData)
       }
     })
-    this.setData({
-      questionDataList: questionList
+    const cardListUpdata = this.data.cardList
+    cardListUpdata.forEach(item => {
+      item.infoList.forEach(citem => {
+        if (citem.id == id) {
+          citem.userAnswer[index] = inputData
+          return citem.isUserAnswer = this.isHaveAnswer(inputData)
+        }
+      })
     })
-    console.log(this.data.questionDataList);
+    this.setData({
+      questionDataList: questionList,
+      cardList: cardListUpdata,
+    })
+    if (this.data.answerType == 'mock') {
+      this.setData({
+        saveTime: 20
+      })
+    }
   },
   // 鏁扮粍杞负瀛楃涓叉柟娉�
   arrayToString(data) {
@@ -237,39 +381,82 @@
       } else {
         return false
       }
-    } else {
+    } else if (typeof data == 'object') {
       const answer = data.find((item) => item.length > 0)
       if (answer) {
         return true
       } else {
         return false
       }
+    } else {
+      return false
     }
   },
   // 鎻愪氦閫昏緫
   submitPaper() {
+    // 鍏抽棴閫�鍑洪〉闈㈢洃鍚�
+    wx.disableAlertBeforeUnload()
     this.setData({
-      submitStatus: true
+      submitStatus: true,
+      loading: true
     })
+    const child = this.selectComponent('#question-options')
+    if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion' || this.data.answerType == 'mock') {
+      // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀�
+      const qustionList = this.data.questionDataList
+      for (let index = 0; index < qustionList.length; index++) {
+        const item = qustionList[index];
+        if (!item.isComplete) this.handleQuestion(index)
+      }
+    }
     if (this.data.answerType == 'option') {
       this.toggleCountdown()
-      const child = this.selectComponent('#question-options')
-      if (this.data.answerType == 'option' || this.data.answerType == 'errorQuestion') {
-        // 鍏堥亶鍘嗘墍鏈夐鐩紝灏嗘湭鎵规敼鐨勯鐩壒鏀�
-        const qustionList = this.data.questionDataList
-        for (let index = 0; index < qustionList.length; index++) {
-          const item = qustionList[index];
-          if (!item.isComplete) this.handleQuestion(index + 1)
-        }
-      }
-      if (this.data.answerType == 'option') {
-        this.recordAnswerData()
-        child.openTestReportDialog()
-      }
+      this.recordAnswerData()
+      child.openTestReportDialog()
     } else if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') {
       this.goBack()
+    } else if (this.data.answerType == 'mock') {
+      this.toggleCountdown()
+      // 璁剧疆妯¤�冪姸鎬佷负宸插畬鎴�
+      const mockData = this.data.mockData
+      mockData.datas.forEach((item) => {
+        if (item.id == this.data.uuid) {
+          item.state = '3'
+          item.report = {
+            userScore: this.data.subjectiveNum
+          }
+        }
+      })
+      this.setData({
+        mockData: mockData,
+        submitStatus: true
+      })
+      this.setMockInfo(mockData.datas)
+      // 璁板綍鐢ㄦ埛绛旈鏁版嵁
+      let saveData = []
+      for (let index = 0; index < this.data.questionDataList.length; index++) {
+        const item = this.data.questionDataList[index];
+        saveData.push({
+          id: item.id,
+          answer: item.userAnswer,
+          isRight: item.isRight
+        })
+      }
+      app.MG.identity.setUserKey({
+        setKeyRequests: [{
+          domain: 'mockAnswerData',
+          key: this.data.uuid,
+          value: JSON.stringify({
+            time: this.data.countdownTime,
+            answerData: saveData
+          })
+        }]
+      })
+      child.openTestReportDialog()
     }
-
+    this.setData({
+      loading: false
+    })
   },
   // 鍒濆鍖栧嚱鏁�
   async init() {
@@ -281,21 +468,69 @@
     })
     if (this.data.answerType == 'option') {
       if (this.data)
-        this.startCountdown()
-      this.setData({
-        countdownTime: 2 * 60 * 60 * 1000
-      })
+        // this.startCountdown()
+        this.setData({
+          countdownTime: 2 * 60 * 60 * 1000
+        })
       // 娴嬭瘯绛旈
       await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃
-      await this.getErrorList()   // 鑾峰彇閿欓id鍒楄〃
+      await this.getErrorList() // 鑾峰彇閿欓id鍒楄〃
     } else if (this.data.answerType == 'collectQuestion') {
+      this.setData({
+        submitStatus: true
+      })
       // 鎴戠殑鏀惰棌
       await this.getcollectId() // 鑾峰彇鏀惰棌棰樼洰
     } else if (this.data.answerType == 'errorQuestion') {
+      this.setData({
+        submitStatus: true
+      })
       // 鎴戠殑閿欓
       // loadings.value = true
       await this.getErrorIdList()
       await this.getCollectIdList() // 鑾峰彇鏀惰棌id鍒楄〃
+    } else if (this.data.answerType == 'mock') {
+      this.getErrorList()
+      this.getCollectIdList()
+      this.getMockInfo(async (res) => {
+        let mocklist
+        try {
+          mocklist = JSON.parse(res[0].value)
+        } catch (error) {
+          mocklist = []
+        }
+        if (mocklist.length && this.data.uuid) {
+          const oldMockData = mocklist.find((mockItem) => mockItem.id == this.data.uuid)
+          this.setData({
+            'mockData.state': oldMockData.state,
+            'mockData.score': oldMockData.score,
+            'mockData.datas': mocklist,
+          })
+          if (oldMockData.state == '0') {
+            // 缁勫嵎璐拱浜嗭紝浣嗘湭杩涘叆椤甸潰
+            await this.getEduQuizConfig()
+          } else if (oldMockData.state == '1' || oldMockData.state == '2' || oldMockData.state == '3') {
+            // 缁勫嵎鍚庤繘鍏ヨ繃椤甸潰锛屼絾鏄湭绛旇繃棰�
+            let oldQuestionList = []
+            oldQuestionList = await this.getMockQuestionList()
+            const userAnswerList = await this.getMockAnswer()
+            this.setData({
+              'mockData.sumTime': oldMockData.time,
+              cardList: oldQuestionList
+            })
+            await this.getMockDataList(oldQuestionList, userAnswerList)
+          }
+          if (oldMockData.state == '0' || oldMockData.state == '1' || oldMockData.state == '2') {
+            this.startCountdown()
+          }
+          if (oldMockData.state == '3') {
+            this.setData({
+              submitStatus: true,
+              subjectiveNum: oldMockData.report.userScore
+            })
+          }
+        }
+      })
     }
   },
   async restart() {
@@ -324,16 +559,14 @@
       // 缁勫嵎妯″紡
       // 娓呯┖绛旈璁板綍
       await app.MG.identity.setUserKey({
-        setKeyRequests: [
-          {
-            domain: 'mockAnswerData',
-            key: route.query.uuid,
-            value: JSON.stringify({
-              time: countDownRef.value.countdownTime,
-              answerData: []
-            })
-          }
-        ]
+        setKeyRequests: [{
+          domain: 'mockAnswerData',
+          key: this.data.uuid,
+          value: JSON.stringify({
+            time: this.data.countdownTime,
+            answerData: []
+          })
+        }]
       })
       this.init()
     } else {
@@ -356,8 +589,7 @@
           this.setData({
             collectList: JSON.parse(res[0].value)
           })
-        } catch (error) {
-        }
+        } catch (error) {}
         if (this.data.answerType == 'option') {
           // 鍏堣幏鍙栫敤鎴风瓟棰樿褰�
           this.getAnswerInfo(async (res) => {
@@ -369,6 +601,7 @@
               let value = JSON.parse(res[0].value)
               // 鏈夌瓟棰樿褰曪紝寰楀垎璧嬪��
               if (value) {
+                wx.disableAlertBeforeUnload()
                 this.setData({
                   submitStatus: true
                 })
@@ -382,6 +615,7 @@
               this.setData({
                 currentIndex: value.currentIndex
               })
+              console.log(this.data.submitStatus);
               // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰
               await this.getQuestionList(value.dataList)
             } else {
@@ -403,20 +637,19 @@
           this.setData({
             errorList: JSON.parse(res[0].value)
           })
-        } catch (error) {
-
-        }
+        } catch (error) {}
       })
   },
   // 鑾峰彇棰樺簱棰樼洰
-  getQuestionList(oldData) {
+  async getQuestionList(oldData) {
     // 娓呯┖姝g‘棰樻暟璁板綍
     this.setData({
       cardList: [],
       correctNum: 0,
     })
     let flag = 0
-    this.data.idPathList.forEach((pathitem) => {
+    for (let index = 0; index < this.data.idPathList.length; index++) {
+      const pathitem = this.data.idPathList[index];
       const pathList = this.data.cardList
       pathList.push({
         path: pathitem.productLinkPath,
@@ -449,7 +682,7 @@
           size: 999
         }
       }
-      app.MG.store.getProductDetail(query).then((res) => {
+      await app.MG.store.getProductDetail(query).then((res) => {
         this.setData({
           total: res.datas.cmsDatas[0].datas.length
         })
@@ -469,29 +702,23 @@
             // num: index, // 棰樺彿
             id: item.id,
             type: pathitem.name,
-            stem:
-              item.Embedded_QuestionBank_QuestionType == 'completion'
-                ? JSON.parse(item.Embedded_QuestionBank_Stem)
-                  .stemTxt.replaceAll('<vacancy>', ',input,')
-                  .split(',')
-                : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
+            stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
+              JSON.parse(item.Embedded_QuestionBank_Stem)
+              .stemTxt.replaceAll('<vacancy>', ',input,')
+              .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
             answer: item.Embedded_QuestionBank_Answer, // 绛旀
-            option: item.Embedded_QuestionBank_Option
-              ? JSON.parse(item.Embedded_QuestionBank_Option)
-              : '', // 閫夋嫨棰橀�夐」
+            option: item.Embedded_QuestionBank_Option ?
+              JSON.parse(item.Embedded_QuestionBank_Option) : '', // 閫夋嫨棰橀�夐」
             analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽
             questionType: item.Embedded_QuestionBank_QuestionType, // 棰樺瀷
             optionStyle: item.Embedded_QuestionBank_OptionStyle, // 閫夐」鏄剧ず绫诲瀷
             stemStyle: item.Embedded_QuestionBank_StemStyle, // 棰樺共鏄剧ず绫诲瀷
-            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'
-                ? []
-                : '',
+            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' ? [] : '',
+            isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
             isRight: oldObj ? oldObj.isRight : null,
             isComplete: oldObj ? oldObj.isComplete : false,
             isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
@@ -524,6 +751,18 @@
                 index++
               }
             }
+          }
+          // 棰樺共瀵屾枃鏈鐞�
+          if (questionObj.stemStyle == 'RichText') {
+            // questionObj.option.txt = ''
+            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ').replace(/\<p/gi, '<p class="stem-rich-p"')
+
+          }
+          // 閫夐」瀵屾枃鏈鐞�
+          if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
+            questionObj.option.forEach(item => {
+              if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"')
+            })
           }
           // 鑾峰彇鍥剧墖
           if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
@@ -573,24 +812,25 @@
             aitem.infoList.forEach((bitem, bindex) => {
               questionList.push(bitem)
               bitem.number = bindex + 1
-              bitem.grade = 2
+              bitem.score = 2
             })
           })
           this.setData({
             questionDataList: questionList,
-            cardList: cardUpdatedList
+            cardList: cardUpdatedList,
           })
         })
       })
-    })
+    }
+    // 鏈夐鐩啀寮�濮嬪�掕鏃�
+    if (this.data.questionDataList.length) this.startCountdown()
     this.setData({
-      loading: false,
+      loading: false
     })
   },
-  // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘忥級
-  handleQuestion(num) {
+  // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級
+  handleQuestion(index) {
     const questionList = this.data.questionDataList
-    const index = num - 1 >= 0 ? num - 1 : 0
     if (questionList[index].isComplete) {
       // 棰樼洰宸插畬鎴愶紝璺宠繃
       return true
@@ -618,7 +858,17 @@
       // 绠�绛� 缈昏瘧
       questionList[index].isRight = null
     } else if (item.questionType == 'completion') {
-      // 濉┖
+      if (item.answer == 'string') {
+        item.isRight = item.answer == item.userAnswer[0]
+      } else {
+        if (item.answer.length != item.userAnswer.length) {
+          item.isRight = false
+        } else {
+          item.isRight = item.answer.every(
+            (value, index) => value === item.userAnswer[index]
+          )
+        }
+      }
       // subjectiveGrade.value += item.score
       if (typeof item.answer == 'string') {
         questionList[index].isRight = item.answer == item.userAnswer[0]
@@ -635,13 +885,13 @@
     if (item.questionType != 'shortAnswer') {
       this.setData({
         subjectiveTotal: this.data.subjectiveTotal + 1,
-        subjectiveGrade: this.data.subjectiveGrade + item.grade
+        subjectiveGrade: this.data.subjectiveGrade + item.score
       })
     }
     if (questionList[index].isRight && item.questionType != 'shortAnswer') {
       // 瀹㈣棰樺洖绛旀纭�
       this.setData({
-        subjectiveNum: this.data.subjectiveNum + item.grade,
+        subjectiveNum: this.data.subjectiveNum + item.score,
         correctNum: this.data.correctNum + 1
       })
     }
@@ -663,18 +913,17 @@
       // 璁板綍閿欓
       app.MG.identity
         .setUserKey({
-          setKeyRequests: [
-            {
-              domain: 'errorData',
-              key: this.data.rootCmsItemId,
-              value: JSON.stringify(this.data.errorList)
-            }
-          ]
+          setKeyRequests: [{
+            domain: 'errorData',
+            key: this.data.rootCmsItemId,
+            value: JSON.stringify(this.data.errorList)
+          }]
         })
         .then((res) => {
           console.log(res)
         })
     }
+
     this.setData({
       questionDataList: questionList
     })
@@ -689,7 +938,6 @@
     this.setData({
       cardList: cardUpdatedList
     })
-    // console.log(this.data.questionDataList, this.data.cardList);
   },
   // 棰樼洰鏀惰棌鎸夐挳,鏀惰棌鍜屽彇娑堝悓涓�鎺ュ彛锛屽彇娑堟暟缁勫噺鍘昏椤筰d
   setCollect() {
@@ -725,27 +973,23 @@
     }
     app.MG.identity
       .setUserKey({
-        setKeyRequests: [
-          {
-            domain: 'collectData',
-            key: this.data.rootCmsItemId,
-            value: JSON.stringify(this.data.collectList)
-          }
-        ]
+        setKeyRequests: [{
+          domain: 'collectData',
+          key: this.data.rootCmsItemId,
+          value: JSON.stringify(this.data.collectList)
+        }]
       })
-      .then((res) => { })
+      .then((res) => {})
   },
   // 澶勭悊绛旈鏁版嵁
   recordAnswerData() {
-    this.data.cardList.push(
-      {
-        name: '瀹㈣棰樺緱鍒�',
-        score: this.data.subjectiveNum,
-        path: this.data.productLinkPath,
-        // infoList: [],
-        // catalogName: ''
-      }
-    )
+    this.data.cardList.push({
+      name: '瀹㈣棰樺緱鍒�',
+      score: this.data.subjectiveNum,
+      path: this.data.productLinkPath,
+      // infoList: [],
+      // catalogName: ''
+    })
     let setInfoData = {
       currentIndex: this.data.currentIndex,
       dataList: JSON.parse(JSON.stringify(this.data.cardList))
@@ -772,15 +1016,13 @@
   setAnswerInfo(data) {
     app.MG.identity
       .setUserKey({
-        setKeyRequests: [
-          {
-            domain: 'answerData',
-            key: this.data.productLinkPath,
-            value: JSON.stringify(data)
-          }
-        ]
+        setKeyRequests: [{
+          domain: 'answerData',
+          key: this.data.productLinkPath,
+          value: JSON.stringify(data)
+        }]
       })
-      .then((res) => { })
+      .then((res) => {})
   },
   // 鑾峰彇绛旈鏁版嵁
   getAnswerInfo(callback) {
@@ -816,9 +1058,7 @@
           this.setData({
             collectList: JSON.parse(res[0].value)
           })
-          // total.value = collectList.value.length
-        } catch (error) {
-        }
+        } catch (error) {}
         if (this.data.collectList && this.data.collectList.length) {
           await this.getCollectDataList()
         } else {
@@ -827,8 +1067,8 @@
           })
           wx.showModal({
             title: '鎻愮ず',
-            content: '鏀惰棌澶规殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
-            editable: false,//鏄惁鏄剧ず杈撳叆妗�
+            content: '鏀惰棌澶规殏鏃犳暟鎹�', //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
+            editable: false, //鏄惁鏄剧ず杈撳叆妗�
             showCancel: false,
             success: (res) => {
               if (res.confirm) {
@@ -841,127 +1081,167 @@
             }
           })
         }
-        // console.log('鏀惰棌', collectList.value)
       })
   },
   // 鑾峰彇鏀惰棌澶�
   async getCollectDataList() {
     let questionArr = []
     this.setData({
-      cardList: [
-        {
-          catalogName: '鏀惰棌澶�',
-          infoList: []
-        }
-      ]
+      cardList: [{
+        catalogName: '鍗曢�夐',
+        infoList: []
+      }, {
+        catalogName: '鍒ゆ柇棰�',
+        infoList: []
+      }, {
+        catalogName: '澶氶�夐',
+        infoList: []
+      }, {
+        catalogName: '濉┖棰�',
+        infoList: []
+      }, {
+        catalogName: '绠�绛旈',
+        infoList: []
+      }]
     })
-    let query = {
-      path: '*',
-      cmsPath: this.data.rootCmsItemId,
-      cmsType: '*',
-      productId: this.data.bookId,
-      queryType: '*',
-      itemIds: this.data.collectList.map((item) => item + ''),
-      itemFields: {
-        Embedded_QuestionBank_Stem: [],
-        Embedded_QuestionBank_AnalysisCon: [],
-        Embedded_QuestionBank_Answer: [],
-        Embedded_QuestionBank_Option: [],
-        Embedded_QuestionBank_QuestionType: [],
-        Embedded_QuestionBank_StemStyle: [],
-        Embedded_QuestionBank_OptionStyle: [],
-        Embedded_QuestionBank_KnowledgePoint: [],
-        Embedded_QuestionBank_Difficulty: []
+    let singleChoiceArr = [] // 鍗曢��
+    let judgeArr = [] // 鍒ゆ柇
+    let shortArr = [] // 绠�绛�
+    let multipleChoiceArr = [] // 澶氶��
+    let completionArr = [] // 濉┖
+    for (let qindex = 0; qindex < this.data.collectList.length; qindex++) {
+      const qitem = this.data.collectList[qindex];
+      let query = {
+        path: '*',
+        cmsPath: this.data.rootCmsItemId,
+        cmsType: '*',
+        productId: this.data.bookId,
+        queryType: '*',
+        itemIds: qitem + '',
+        itemFields: {
+          Embedded_QuestionBank_Stem: [],
+          Embedded_QuestionBank_AnalysisCon: [],
+          Embedded_QuestionBank_Answer: [],
+          Embedded_QuestionBank_Option: [],
+          Embedded_QuestionBank_QuestionType: [],
+          Embedded_QuestionBank_StemStyle: [],
+          Embedded_QuestionBank_OptionStyle: [],
+          Embedded_QuestionBank_KnowledgePoint: [],
+          Embedded_QuestionBank_Difficulty: []
+        }
       }
-    }
-    app.MG.store.getProductDetail(query).then((res) => {
-      let questionArr = []
-      res.datas.cmsDatas[0].datas.forEach((item, index) => {
-        const questionObj = {
-          number: index + 1, // 棰樺彿
-          id: item.id,
-          stem:
-            item.Embedded_QuestionBank_QuestionType == 'completion'
-              ? JSON.parse(item.Embedded_QuestionBank_Stem)
-                .stemTxt.replaceAll('<vacancy>', ',input,')
-                .split(',')
-              : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
-          answer: item.Embedded_QuestionBank_Answer, // 绛旀
-          option: item.Embedded_QuestionBank_Option
-            ? JSON.parse(item.Embedded_QuestionBank_Option)
-            : '', // 閫夋嫨棰橀�夐」
-          analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽
-          questionType: item.Embedded_QuestionBank_QuestionType, // 棰樺瀷
-          optionStyle: item.Embedded_QuestionBank_OptionStyle, // 閫夐」鏄剧ず绫诲瀷
-          stemStyle: item.Embedded_QuestionBank_StemStyle, // 棰樺共鏄剧ず绫诲瀷
-          difficulty: item.Embedded_QuestionBank_Difficulty
-            ? 4 - item.Embedded_QuestionBank_Difficulty
-            : 0, // 闅惧害绛夌骇
-          userAnswer:
-            item.Embedded_QuestionBank_QuestionType == 'completion' ||
-              item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
-              ? []
-              : '',
-          isSubmit: false, // 鏌ョ湅瑙f瀽
-          isRight: null, // 鏄惁姝g‘
-          isComplete: false,
-          isCollect: true
-        }
-        // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡
-        if (
-          questionObj.questionType == 'completion' ||
-          questionObj.questionType == 'multipleChoice'
-        ) {
-          try {
-            questionObj.answer = JSON.parse(questionObj.answer)
-          } catch (error) {
-            //
+      await app.MG.store.getProductDetail(query).then((res) => {
+        let questionArr = []
+        res.datas.cmsDatas[0].datas.forEach((item, index) => {
+          const questionObj = {
+            number: index + 1, // 棰樺彿
+            id: item.id,
+            stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
+              JSON.parse(item.Embedded_QuestionBank_Stem)
+              .stemTxt.replaceAll('<vacancy>', ',input,')
+              .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
+            answer: item.Embedded_QuestionBank_Answer, // 绛旀
+            option: item.Embedded_QuestionBank_Option ?
+              JSON.parse(item.Embedded_QuestionBank_Option) : '', // 閫夋嫨棰橀�夐」
+            analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽
+            questionType: item.Embedded_QuestionBank_QuestionType, // 棰樺瀷
+            optionStyle: item.Embedded_QuestionBank_OptionStyle, // 閫夐」鏄剧ず绫诲瀷
+            stemStyle: item.Embedded_QuestionBank_StemStyle, // 棰樺共鏄剧ず绫诲瀷
+            difficulty: item.Embedded_QuestionBank_Difficulty ?
+              4 - item.Embedded_QuestionBank_Difficulty : 0, // 闅惧害绛夌骇
+            userAnswer: item.Embedded_QuestionBank_QuestionType == 'completion' ||
+              item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '',
+            isSubmit: false, // 鏌ョ湅瑙f瀽
+            isRight: null, // 鏄惁姝g‘
+            isComplete: false,
+            isCollect: true
           }
-        }
-        // 濉┖棰樻敼閫�
-        if (questionObj.questionType == 'completion') {
-          let index = 0
-          for (let i = 0; i < questionObj.stem.length; i++) {
-            const item = questionObj.stem[i]
-            if (item == 'input') {
-              questionObj.stem[i] = {
-                num: index,
-                data: 'input'
-              }
-              questionObj.userAnswer[index] = ''
-              index++
+          // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡
+          if (
+            questionObj.questionType == 'completion' ||
+            questionObj.questionType == 'multipleChoice'
+          ) {
+            try {
+              questionObj.answer = JSON.parse(questionObj.answer)
+            } catch (error) {
+              //
             }
           }
-        }
-        // 鑾峰彇鍥剧墖
-        if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
-          questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
-        }
-        if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') {
-          questionObj.option.forEach(optionItem => {
-            if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
-          })
-        }
-        // if (item.Embedded_QuestionBank_QuestionType == 'judge') {
-        //   topicList.value.judge.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
-        //   topicList.value.radio.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
-        //   topicList.value.check.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
-        //   topicList.value.gap.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
-        //   topicList.value.short.data.push(questionObj)
-        // }
-        questionArr.push(questionObj)
-        // cardList.value[0].infoList.push(questionObj)
+          // 濉┖棰樻敼閫�
+          if (questionObj.questionType == 'completion') {
+            let index = 0
+            for (let i = 0; i < questionObj.stem.length; i++) {
+              const item = questionObj.stem[i]
+              if (item == 'input') {
+                questionObj.stem[i] = {
+                  num: index,
+                  data: 'input'
+                }
+                questionObj.userAnswer[index] = ''
+                index++
+              }
+            }
+          }
+          // 鑾峰彇鍥剧墖
+          if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
+            questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
+          }
+          if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') {
+            questionObj.option.forEach(optionItem => {
+              if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
+            })
+          }
+          // 棰樺共瀵屾枃鏈鐞�
+          if (questionObj.stemStyle == 'RichText') {
+            // questionObj.option.txt = ''
+            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ').replace(/\<p/gi, '<p class="stem-rich-p"')
+
+          }
+          // 閫夐」瀵屾枃鏈鐞�
+          if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
+            questionObj.option.forEach(item => {
+              if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"')
+            })
+          }
+          if (item.Embedded_QuestionBank_QuestionType == 'judge') {
+            questionObj.type = '鍒ゆ柇棰�'
+            judgeArr.push(questionObj)
+          } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
+            questionObj.type = '鍗曢�夐'
+            singleChoiceArr.push(questionObj)
+          } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
+            questionObj.type = '澶氶�夐'
+            multipleChoiceArr.push(questionObj)
+          } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
+            questionObj.type = '濉┖棰�'
+            completionArr.push(questionObj)
+          } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
+            questionObj.type = '绠�绛旈'
+            shortArr.push(questionObj)
+          }
+        })
       })
-      // loadings.value = false
-      this.setData({
-        questionDataList: questionArr,
-        ['cardList[0].infoList']: questionArr,
-        loading: false,
-      })
+    }
+    this.setData({
+      ['cardList[0].infoList']: singleChoiceArr,
+      ['cardList[1].infoList']: judgeArr,
+      ['cardList[2].infoList']: multipleChoiceArr,
+      ['cardList[3].infoList']: completionArr,
+      ['cardList[3].infoList']: shortArr,
+    })
+    const cardList = this.data.cardList
+    for (let index = 0; index < cardList.length; index++) {
+      const item = cardList[index];
+      for (let cindex = 0; cindex < item.infoList.length; cindex++) {
+        const citem = item.infoList[cindex]
+        citem.number = cindex + 1
+        questionArr.push(citem)
+      }
+    }
+    this.setData({
+      questionDataList: questionArr,
+      cardList: cardList,
+      loading: false
     })
   },
   // 鎴戠殑閿欓妯″紡涓嬭幏鍙栭敊棰榠d鍒楄〃
@@ -976,8 +1256,7 @@
           this.setData({
             errorList: JSON.parse(res[0].value)
           })
-        } catch (error) {
-        }
+        } catch (error) {}
         if (this.data.errorList && this.data.errorList.length) {
           this.getErrorDataList()
         } else {
@@ -986,8 +1265,8 @@
           })
           wx.showModal({
             title: '鎻愮ず',
-            content: '閿欓闆嗘殏鏃犳暟鎹�',//editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
-            editable: false,//鏄惁鏄剧ず杈撳叆妗�
+            content: '閿欓闆嗘殏鏃犳暟鎹�', //editable濡傛灉涓簍rue锛岃繖灏辨槸杈撳叆妗嗙殑鍐呭
+            editable: false, //鏄惁鏄剧ず杈撳叆妗�
             showCancel: false,
             success: (res) => {
               if (res.confirm) {
@@ -1003,14 +1282,35 @@
   },
   // 鑾峰彇閿欓闆�
   async getErrorDataList() {
+    // this.setData({
+    //   cardList: [{
+    //     catalogName: '閿欓闆�',
+    //     infoList: []
+    //   }]
+    // })
     this.setData({
-      cardList: [
-        {
-          catalogName: '閿欓闆�',
-          infoList: []
-        }
-      ]
+      cardList: [{
+        catalogName: '鍗曢�夐',
+        infoList: []
+      }, {
+        catalogName: '鍒ゆ柇棰�',
+        infoList: []
+      }, {
+        catalogName: '澶氶�夐',
+        infoList: []
+      }, {
+        catalogName: '濉┖棰�',
+        infoList: []
+      }, {
+        catalogName: '绠�绛旈',
+        infoList: []
+      }]
     })
+    let singleChoiceArr = [] // 鍗曢��
+    let judgeArr = [] // 鍒ゆ柇
+    let shortArr = [] // 绠�绛�
+    let multipleChoiceArr = [] // 澶氶��
+    let completionArr = [] // 濉┖
     let query = {
       path: '*',
       cmsPath: this.data.rootCmsItemId,
@@ -1036,28 +1336,21 @@
         const questionObj = {
           number: index + 1, // 棰樺彿
           id: item.id,
-          stem:
-            item.Embedded_QuestionBank_QuestionType == 'completion'
-              ? JSON.parse(item.Embedded_QuestionBank_Stem)
-                .stemTxt.replaceAll('<vacancy>', ',input,')
-                .split(',')
-              : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
+          stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
+            JSON.parse(item.Embedded_QuestionBank_Stem)
+            .stemTxt.replaceAll('<vacancy>', ',input,')
+            .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
           answer: item.Embedded_QuestionBank_Answer, // 绛旀
-          option: item.Embedded_QuestionBank_Option
-            ? JSON.parse(item.Embedded_QuestionBank_Option)
-            : '', // 閫夋嫨棰橀�夐」
+          option: item.Embedded_QuestionBank_Option ?
+            JSON.parse(item.Embedded_QuestionBank_Option) : '', // 閫夋嫨棰橀�夐」
           analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽
           questionType: item.Embedded_QuestionBank_QuestionType, // 棰樺瀷
           optionStyle: item.Embedded_QuestionBank_OptionStyle, // 閫夐」鏄剧ず绫诲瀷
           stemStyle: item.Embedded_QuestionBank_StemStyle, // 棰樺共鏄剧ず绫诲瀷
-          difficulty: item.Embedded_QuestionBank_Difficulty
-            ? 4 - item.Embedded_QuestionBank_Difficulty
-            : 0, // 闅惧害绛夌骇
-          userAnswer:
-            item.Embedded_QuestionBank_QuestionType == 'completion' ||
-              item.Embedded_QuestionBank_QuestionType == 'multipleChoice'
-              ? []
-              : '',
+          difficulty: item.Embedded_QuestionBank_Difficulty ?
+            4 - item.Embedded_QuestionBank_Difficulty : 0, // 闅惧害绛夌骇
+          userAnswer: item.Embedded_QuestionBank_QuestionType == 'completion' ||
+            item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '',
           isSubmit: false, // 鏌ョ湅瑙f瀽
           isRight: null, // 鏄惁姝g‘
           isComplete: false,
@@ -1098,26 +1391,440 @@
             if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
           })
         }
-        // if (item.Embedded_QuestionBank_QuestionType == 'judge') {
-        //   topicList.value.judge.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
-        //   topicList.value.radio.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
-        //   topicList.value.check.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
-        //   topicList.value.gap.data.push(questionObj)
-        // } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
-        //   topicList.value.short.data.push(questionObj)
-        // }
-        questionArr.push(questionObj)
+        // 棰樺共瀵屾枃鏈鐞�
+        if (questionObj.stemStyle == 'RichText') {
+          // questionObj.option.txt = ''
+          questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" ').replace(/\<p/gi, '<p class="stem-rich-p"')
+
+        }
+        // 閫夐」瀵屾枃鏈鐞�
+        if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
+          questionObj.option.forEach(item => {
+            if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"').replace(/\<p/gi, '<p class="stem-rich-p"')
+          })
+        }
+        if (item.Embedded_QuestionBank_QuestionType == 'judge') {
+          questionObj.type = '鍒ゆ柇棰�'
+          judgeArr.push(questionObj)
+        } else if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
+          questionObj.type = '鍗曢�夐'
+          singleChoiceArr.push(questionObj)
+        } else if (item.Embedded_QuestionBank_QuestionType == 'multipleChoice') {
+          questionObj.type = '澶氶�夐'
+          multipleChoiceArr.push(questionObj)
+        } else if (item.Embedded_QuestionBank_QuestionType == 'completion') {
+          questionObj.type = '濉┖棰�'
+          completionArr.push(questionObj)
+        } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
+          questionObj.type = '绠�绛旈'
+          shortArr.push(questionObj)
+        }
+        // questionArr.push(questionObj)
       })
       this.setData({
+        // questionDataList: questionArr,
+        ['cardList[0].infoList']: singleChoiceArr,
+        ['cardList[1].infoList']: judgeArr,
+        ['cardList[2].infoList']: multipleChoiceArr,
+        ['cardList[3].infoList']: completionArr,
+        ['cardList[3].infoList']: shortArr,
+        // loading: false
+      })
+      const cardList = this.data.cardList
+      for (let index = 0; index < cardList.length; index++) {
+        const item = cardList[index];
+        for (let cindex = 0; cindex < item.infoList.length; cindex++) {
+          const citem = item.infoList[cindex]
+          citem.number = cindex + 1
+          questionArr.push(citem)
+        }
+      }
+      this.setData({
         questionDataList: questionArr,
-        ['cardList[0].infoList']: questionArr,
+        cardList: cardList,
         loading: false
       })
     })
     // loadings.value = false
-    // console.log('閿欓闆�', topicList.value)
+  },
+  // 鑾峰彇缁勫嵎缁撴灉
+  async getEduQuizConfig() {
+    await app.MG.edu
+      .getEduQuizConfigResult({
+        idOrRefCode: this.data.mockid
+      })
+      .then(async (configRes) => {
+        // 鑾峰彇 鍒嗘暟 鏃堕棿
+        this.setData({
+          'mockData.score': configRes.score
+        })
+        try {
+          this.setData({
+            'mockData.time': JSON.parse(configRes.config).time * 1000,
+            countdownTime: JSON.parse(configRes.config).time * 1000
+          })
+        } catch (error) {
+          this.setData({
+            'mockData.time': 3600 * 1000,
+            countdownTime: 3600 * 1000,
+          })
+        }
+        this.setData({
+          'mockData.sumTime': this.data.mockData.time
+        })
+        let itemIds = []
+        let numberIndex = 1
+        // 鑾峰彇鎶介缁撴灉
+        const cardList = configRes.eduQuizConfigStageResultList.map((item) => {
+          let questionIds = []
+          // 鑾峰彇蹇呭惈棰樼洰
+          let list = item.cmsItemList.map((idItem) => {
+            itemIds.push(idItem.id + '')
+            questionIds.push({
+              id: idItem.id + '',
+              score: idItem.score
+            })
+            numberIndex++
+            return {
+              number: numberIndex,
+              id: idItem.id,
+              score: idItem.score
+            }
+          })
+          // 鑾峰彇鎶介棰樼洰
+          let extractList = []
+          for (let i = 0; i < item.generatorResultList.length; i++) {
+            const extractItem = item.generatorResultList[i]
+            let extractItemList = extractItem.cmsItemList.map((extractCmsItem) => {
+              itemIds.push(extractCmsItem.id + '')
+              questionIds.push({
+                id: extractCmsItem.id + '',
+                score: extractCmsItem.score
+              })
+              numberIndex++
+              return {
+                number: numberIndex,
+                id: extractCmsItem.id,
+                score: extractCmsItem.score
+              }
+            })
+            extractList = extractList.concat(extractItemList)
+          }
+          return {
+            path: item.id,
+            catalogName: item.name,
+            infoList: list.concat(extractList)
+          }
+        })
+        this.setData({
+          cardList: cardList
+        })
+        // 鏇存柊璇ユ潯缁勫嵎鐨勬暟鎹姸鎬侊紝鍖呮嫭璁板綍鏀硅瘯鍗锋�诲垎锛屾洿鏀圭粍鍗风姸鎬乻tate涓�1锛岃〃绀哄凡缁忔娊棰樺畬鎴愶紝骞惰灏嗘娊灞夋暟鎹褰曚笅鏉�
+        if (this.data.mockData.datas && this.data.mockData.datas.length) {
+          const mockData = this.data.mockData
+          mockData.datas.forEach((item, index) => {
+            if (item.id == this.data.uuid) {
+              item.state = '1'
+              item.time = mockData.time
+              item.score = configRes.score
+              mockData.state = '1'
+            }
+          })
+          this.setData({
+            mockData: mockData
+          })
+        }
+        this.setMockInfo(this.data.mockData.datas) // 璁板綍璇曞嵎鎬诲垎 鏃堕暱锛屼慨鏀箂tate涓� 1
+        // 鏇存柊鏈湴mockData
+        this.saveMockQuestionList(this.data.cardList) // 璁板綍棰樼洰鍒楄〃
+        await this.getMockDataList(this.data.cardList) // 璇锋眰棰樼洰鏁版嵁
+      })
+  },
+  // 鑾峰彇缁勫嵎棰樼洰鍒楄〃
+  async getMockDataList(questionList, oldList) {
+    const questionDataList = this.data.questionDataList
+    for (let pathindex = 0; pathindex < questionList.length; pathindex++) {
+      const pathitem = questionList[pathindex];
+      let itemIds = []
+      pathitem.infoList.forEach(item => {
+        itemIds.push(item.id + '')
+      })
+      let query = {
+        path: '*',
+        cmsPath: this.data.rootCmsItemId,
+        cmsType: '*',
+        productId: this.data.bookId,
+        queryType: '*',
+        itemIds,
+        itemFields: {
+          Embedded_QuestionBank_Stem: [],
+          Embedded_QuestionBank_AnalysisCon: [],
+          Embedded_QuestionBank_Answer: [],
+          Embedded_QuestionBank_Option: [],
+          Embedded_QuestionBank_QuestionType: [],
+          Embedded_QuestionBank_StemStyle: [],
+          Embedded_QuestionBank_OptionStyle: [],
+          Embedded_QuestionBank_KnowledgePoint: [],
+          Embedded_QuestionBank_Difficulty: []
+        }
+      }
+      await app.MG.store.getProductDetail(query).then((res) => {
+        res.datas.cmsDatas[0].datas.forEach((item, index) => {
+          // 寰幆questionList,缁欐瘡棰樿祴鍊煎垎鏁�
+          let oldObj
+          if (oldList) oldObj = oldList.find((oldItem) => oldItem.id == item.id)
+          let questionObj = {
+            // number: pathitem.infoList.find(infoItem => infoItem.itemId == item.id).number,
+            id: item.id,
+            score: pathitem.infoList.find(infoItem => infoItem.id == item.id).score,
+            stem: item.Embedded_QuestionBank_QuestionType == 'completion' ?
+              JSON.parse(item.Embedded_QuestionBank_Stem)
+              .stemTxt.replaceAll('<vacancy>', ',input,')
+              .split(',') : JSON.parse(item.Embedded_QuestionBank_Stem), // 棰樺共
+            answer: item.Embedded_QuestionBank_Answer, // 绛旀
+            option: item.Embedded_QuestionBank_Option ?
+              JSON.parse(item.Embedded_QuestionBank_Option) : '', // 閫夋嫨棰橀�夐」
+            analysisCon: item.Embedded_QuestionBank_AnalysisCon, // 瑙f瀽
+            questionType: item.Embedded_QuestionBank_QuestionType, // 棰樺瀷
+            optionStyle: item.Embedded_QuestionBank_OptionStyle, // 閫夐」鏄剧ず绫诲瀷
+            stemStyle: item.Embedded_QuestionBank_StemStyle, // 棰樺共鏄剧ず绫诲瀷
+            difficulty: item.Embedded_QuestionBank_Difficulty ?
+              4 - item.Embedded_QuestionBank_Difficulty : 0, // 闅惧害绛夌骇
+            userAnswer: oldObj ?
+              oldObj.answer : item.Embedded_QuestionBank_QuestionType == 'completion' ||
+              item.Embedded_QuestionBank_QuestionType == 'multipleChoice' ? [] : '',
+            isUserAnswer: oldObj ? this.isHaveAnswer(oldObj.userAnswer) : false,
+            isRight: oldObj ? oldObj.isRight : null,
+            // isComplete: oldObj ? oldObj.isComplete : false,
+            isComplete: this.data.mockData.state == '3' ? true : false,
+            isCollect: this.data.collectList.indexOf(item.id) > -1 ? true : false,
+            isUnfold: '' // 鎺у埗瑙f瀽鐨勬姌鍙犻潰鏉挎槸鍚﹀睍寮�
+          }
+          // 澶氶�夊拰濉┖绛旀鑲负鏁扮粍锛岃杞崲JSON鏍煎紡
+          if (
+            questionObj.questionType == 'completion' ||
+            questionObj.questionType == 'multipleChoice'
+          ) {
+            try {
+              questionObj.answer = JSON.parse(questionObj.answer)
+            } catch (error) {
+              questionObj.answer = item.Embedded_QuestionBank_Answer
+            }
+          }
+          // 濉┖棰樻敼閫�
+          if (questionObj.questionType == 'completion') {
+            let index = 0
+            for (let i = 0; i < questionObj.stem.length; i++) {
+              const item = questionObj.stem[i]
+              if (item == 'input') {
+                questionObj.stem[i] = {
+                  num: index,
+                  data: 'input'
+                }
+                if (!oldObj) questionObj.userAnswer[index] = ''
+                index++
+              }
+            }
+          }
+          // 棰樺共瀵屾枃鏈鐞�
+          if (questionObj.stemStyle == 'RichText') {
+            // questionObj.option.txt = ''
+            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img"')
+          }
+          // 閫夐」瀵屾枃鏈鐞�
+          if (questionObj.optionStyle == 'RichText' && (questionObj.questionType == 'singleChoice' || questionObj.questionType == 'judge' || questionObj.questionType == 'multipleChoice')) {
+            questionObj.option.forEach(item => {
+              if (item.txt) item.txt = item.txt.replace(/\<img/gi, '<img class="option-rich-img"')
+            })
+          }
+          // 鑾峰彇鍥剧墖
+          if (questionObj.stemStyle == 'Image' || questionObj.stemStyle == 'TxtAndImage') {
+            questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
+          }
+          if (questionObj.optionStyle == 'Image' || questionObj.optionStyle == 'TxtAndImage') {
+            questionObj.option.forEach(optionItem => {
+              if (optionItem.img) optionItem.img = getPublicImage(optionItem.img, 150)
+            })
+          }
+          if (oldObj && oldObj.isRight) {
+            this.setData({
+              correctNum: this.data.correctNum + 1
+            })
+          }
+          if (item.questionType != 'shortAnswer' && item.isComplete) {
+            this.setData({
+              subjectiveTotal: this.data.subjectiveTotal + 1
+            })
+          }
+          // if (oldObj && isHaveAnswer(oldObj.answer)) countDownRef.value.changeAlready()
+          // cardList璧嬪��
+          let cardIndex = this.data.cardList.findIndex((item) => item.catalogName == pathitem.catalogName)
+          let infoIndex = this.data.cardList[cardIndex].infoList.findIndex(infoItem => infoItem.id == item.id)
+          this.setData({
+            [`cardList[${cardIndex}].infoList[${infoIndex}]`]: questionObj
+          })
+          let questionList = []
+          const cardUpdatedList = this.data.cardList
+          cardUpdatedList.forEach(aitem => {
+            aitem.infoList.forEach((bitem, bindex) => {
+              questionList.push(bitem)
+              bitem.number = bindex + 1
+            })
+          })
+          this.setData({
+            questionDataList: questionList,
+            cardList: cardUpdatedList
+          })
+        })
+      })
+    }
+    this.setData({
+      loading: false
+    })
+  },
+  // 鑾峰彇缁勫嵎鏁版嵁
+  getMockInfo(callback) {
+    app.MG.identity
+      .getUserKey({
+        domain: 'mockData',
+        keys: [this.data.bookId]
+      })
+      .then((res) => {
+        if (callback) callback(res)
+      })
+  },
+  // 璁板綍璐拱缁勫嵎鏃堕棿
+  setMockInfo(data) {
+    app.MG.identity.setUserKey({
+      setKeyRequests: [{
+        domain: 'mockData',
+        key: this.data.bookId + '',
+        value: JSON.stringify(data)
+      }]
+    })
+  },
+  // 璁板綍缁勫嵎棰樼洰鍒楄〃
+  saveMockQuestionList(data) {
+    app.MG.identity
+      .setUserKey({
+        setKeyRequests: [{
+          domain: 'mockQuestionData',
+          key: this.data.uuid,
+          value: JSON.stringify(data)
+        }]
+      })
+      .then((res) => {
+        console.log('妯¤�冮鐩垪琛ㄥ凡璁板綍')
+      })
+  },
+  // 鑾峰彇璁板綍缁勫嵎棰樼洰鍒楄〃
+  async getMockQuestionList() {
+    let list = []
+    await app.MG.identity
+      .getUserKey({
+        domain: 'mockQuestionData',
+        keys: [this.data.uuid]
+      })
+      .then((res) => {
+        list = JSON.parse(res[0].value)
+      })
+    return list
+  },
+  // 鑾峰彇妯¤�冪敤鎴风瓟棰樻暟鎹�
+  async getMockAnswer() {
+    let data
+    await app.MG.identity
+      .getUserKey({
+        domain: 'mockAnswerData',
+        keys: [this.data.uuid]
+      })
+      .then((res) => {
+        if (res[0]) {
+          this.setData({
+            currentIndex: JSON.parse(res[0].value).currentIndex,
+            'mockData.time': JSON.parse(res[0].value).time,
+            countdownTime: JSON.parse(res[0].value).time ? JSON.parse(res[0].value).time : this.data.mockData.sumTime,
+            'mockData.answer': JSON.parse(res[0].value).answerData
+          })
+          console.log(JSON.parse(res[0].value));
+          data = JSON.parse(res[0].value).answerData
+        }
+      })
+    return data
+  },
+
+  // 璁板綍妯¤�冪瓟棰樻暟鎹�
+  saveMockData() {
+    const data = this.data.mockData.datas.find((itme) => itme.id == this.data.uuid)
+    if (data.state == '3') return true
+    const saveData = this.data.mockData.answer
+    for (let i = 0; i < this.data.questionDataList.length; i++) {
+      const item = this.data.questionDataList[i]
+      if (this.isHaveAnswer(item.userAnswer)) {
+        const index = saveData.findIndex((saveitem) => saveitem.id == item.id)
+        if (index + '' != '-1') {
+          saveData[index].answer = item.userAnswer
+        } else {
+          saveData.push({
+            id: item.id,
+            answer: item.userAnswer
+          })
+        }
+      }
+    }
+    // 
+    if (this.data.mockData.state == '1') {
+      const datas = this.data.mockData.datas
+      datas.forEach((item) => {
+        if (item.id == this.data.uuid) {
+          item.state = '2'
+        }
+      })
+      this.setMockInfo(datas)
+    }
+    // 
+    app.MG.identity
+      .setUserKey({
+        setKeyRequests: [{
+          domain: 'mockAnswerData',
+          key: this.data.uuid,
+          value: JSON.stringify({
+            currentIndex: this.data.currentIndex,
+            time: this.data.countdownTime,
+            answerData: saveData
+          })
+        }]
+      })
+      .then((res) => {
+        this.setData({
+          saveTime: 20
+        })
+        console.log('妯¤�冪瓟棰樻暟鎹凡璁板綍')
+      })
+  },
+
+  // 瀵屾枃鏈鐞�
+  formatRichText(html) {
+    console.log(html);
+    let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
+      match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
+      match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
+      match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
+      return match;
+    });
+    newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
+      match = match
+        .replace(/<p>/gi, '<p class="p_class">')
+        .replace(/width:[^;]+;/gi, 'max-width:100%;')
+        .replace(/width:[^;]+;/gi, 'max-width:100%;');
+      return match;
+    });
+    newContent = newContent.replace(/<br[^>]*\/>/gi, "");
+    newContent = newContent.replace(/<a>/gi, '<a class="p_class "');
+    newContent = newContent.replace(/<li>/gi, '<li class="p_class "');
+    newContent = newContent.replace(/\<p/gi, '<p class="p_class "');
+    newContent = newContent.replace(/\<span/gi, '<span class="p_class "');
+    newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin-top:0;margin-bottom:0;"');
+    return newContent;
   }
 })
\ No newline at end of file

--
Gitblit v1.9.1