From 8f1835f66ef83bbd752e080178afb98632a6970d Mon Sep 17 00:00:00 2001
From: yiming <m13691596795@163.com>
Date: 星期四, 28 三月 2024 14:09:44 +0800
Subject: [PATCH] 云学习购买

---
 packageBookService/pages/bookServices/examination/examination.js |  113 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 94 insertions(+), 19 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js
index 9b5823d..0762452 100644
--- a/packageBookService/pages/bookServices/examination/examination.js
+++ b/packageBookService/pages/bookServices/examination/examination.js
@@ -246,10 +246,11 @@
     this.setData({
       currentIndex: e.detail.index
     })
-    if (this.data.answerType == 'collectQuestion' || this.data.answerType == 'errorQuestion') {
-      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)
+    let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0
+    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)
     }
   },
   // 鐐瑰嚮绛旈鍗¤烦杞鐩�
@@ -269,21 +270,46 @@
     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) {
+          let index = this.data.currentIndex - 1 >= 0 ? this.data.currentIndex - 1 : 0
+          this.handleQuestion(index)
+        }
       }
-    })
+    }
+    // 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
-    cardListUpdata.forEach(item => {
-      item.infoList.forEach(citem => {
-        if (citem.id == id) {
+    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,
       cardList: cardListUpdata
@@ -375,7 +401,7 @@
       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 (!item.isComplete) this.handleQuestion(index)
       }
     }
     if (this.data.answerType == 'option') {
@@ -439,10 +465,10 @@
     })
     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鍒楄〃
@@ -472,7 +498,6 @@
         }
         if (mocklist.length && this.data.uuid) {
           const oldMockData = mocklist.find((mockItem) => mockItem.id == this.data.uuid)
-          debugger
           this.setData({
             'mockData.state': oldMockData.state,
             'mockData.score': oldMockData.score,
@@ -735,6 +760,18 @@
               }
             }
           }
+          // 棰樺共瀵屾枃鏈鐞�
+          if (questionObj.stemStyle == 'RichText') {
+            // questionObj.option.txt = ''
+            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img 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') {
             questionObj.stem.stemImage = getPublicImage(questionObj.stem.stemImage, 150)
@@ -793,6 +830,8 @@
         })
       })
     }
+    // 鏈夐鐩啀寮�濮嬪�掕鏃�
+    if (this.data.questionDataList.length) this.startCountdown()
     this.setData({
       loading: false
     })
@@ -800,7 +839,7 @@
   // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級
   handleQuestion(num) {
     const questionList = this.data.questionDataList
-    const index = num - 1 >= 0 ? num - 1 : 0
+    const index = num
     if (questionList[index].isComplete) {
       // 棰樼洰宸插畬鎴愶紝璺宠繃
       return true
@@ -1508,6 +1547,17 @@
               }
             }
           }
+          // 棰樺共瀵屾枃鏈鐞�
+          if (questionObj.stemStyle == 'RichText') {
+            // questionObj.option.txt = ''
+            questionObj.stem.stemTxt = questionObj.stem.stemTxt.replace(/\<img/gi, '<img 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)
@@ -1678,5 +1728,30 @@
         })
         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