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 |  355 +++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 238 insertions(+), 117 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js
index 196a0ce..83953d8 100644
--- a/packageBookService/pages/bookServices/examination/examination.js
+++ b/packageBookService/pages/bookServices/examination/examination.js
@@ -253,6 +253,13 @@
       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) {
     const id = e.detail.id
@@ -277,8 +284,7 @@
         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)
+          this.handleQuestion(this.data.currentIndex)
         }
       }
     }
@@ -388,7 +394,6 @@
   },
   // 鎻愪氦閫昏緫
   submitPaper() {
-
     // 鍏抽棴閫�鍑洪〉闈㈢洃鍚�
     wx.disableAlertBeforeUnload()
     this.setData({
@@ -824,9 +829,8 @@
     })
   },
   // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級
-  handleQuestion(num) {
+  handleQuestion(index) {
     const questionList = this.data.questionDataList
-    const index = num
     if (questionList[index].isComplete) {
       // 棰樼洰宸插畬鎴愶紝璺宠繃
       return true
@@ -854,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]
@@ -1044,7 +1058,6 @@
           this.setData({
             collectList: JSON.parse(res[0].value)
           })
-          // total.value = collectList.value.length
         } catch (error) {}
         if (this.data.collectList && this.data.collectList.length) {
           await this.getCollectDataList()
@@ -1075,110 +1088,160 @@
     let questionArr = []
     this.setData({
       cardList: [{
-        catalogName: '鏀惰棌澶�',
+        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鍒楄〃
@@ -1219,12 +1282,35 @@
   },
   // 鑾峰彇閿欓闆�
   async getErrorDataList() {
+    // this.setData({
+    //   cardList: [{
+    //     catalogName: '閿欓闆�',
+    //     infoList: []
+    //   }]
+    // })
     this.setData({
       cardList: [{
-        catalogName: '閿欓闆�',
+        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,
@@ -1305,22 +1391,57 @@
             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
       })
     })

--
Gitblit v1.9.1