From 8dc4e50769a7ebc5f0a3d766f61aa08b8f23b772 Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期五, 06 九月 2024 11:23:21 +0800
Subject: [PATCH] login

---
 packageBookService/pages/bookServices/examination/examination.js |  234 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 195 insertions(+), 39 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js
index f3924ad..c96c46d 100644
--- a/packageBookService/pages/bookServices/examination/examination.js
+++ b/packageBookService/pages/bookServices/examination/examination.js
@@ -14,6 +14,8 @@
     countdownInterval: null, // 璁℃椂鍣�
     isCountdownRunning: true, // 鏄惁鍊掕鏃�
     countdownTime: 0, // 鍊掕鏃舵椂闂�
+    storeInfo: '',
+    jslx: '',
     bookId: "",
     productLinkPath: "",
     rootCmsItemId: "",
@@ -30,6 +32,7 @@
     total: 0, // 棰樼洰鎬绘暟
     cardList: [], // 鎻愪氦椤�,
     questionDataList: [], // 鏄剧ず棰樼洰鍒楄〃
+    noData: false,
     mockid: 0,
     uuid: 0,
     mockData: {
@@ -46,6 +49,8 @@
     sliderValue: 0, // 瀛椾綋婊戝潡
     startTime: "", //杩涘叆椤甸潰褰撳墠鏃堕棿
     pauseTime: 0, //鏆傚仠鏃堕棿
+    showDialog: false, // 鏈彁浜ら��鍑烘嫤鎴脊绐�
+    showId: ''
   },
 
   /**
@@ -65,15 +70,25 @@
       rootCmsItemId: options.rootCmsItemId,
       idPathList: options.idPathList ? JSON.parse(options.idPathList) : [],
       answerType: options.answerType,
+      storeInfo: options.storeInfo,
+      jslx: options.jslx,
     });
+    wx.setNavigationBarTitle({
+      title: options.answerTitle,
+    })
     if (this.data.answerType == "mock") {
       this.setData({
         uuid: options.uuid,
         mockid: options.mockid,
       });
     }
+    const token = wx.getStorageSync(app.config.tokenKey)
+    if (!token) {
+      loginInfo(app, (data) => {
+        if (data) {} else {}
+      })
+    }
     this.init();
-    console.log("浼犲弬", options);
   },
 
   /**
@@ -180,7 +195,6 @@
   // 鐩戝惉watch
   watch(context, variableName, callback) {
     let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊�
-
     // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter
     Object.defineProperty(context.data, variableName, {
       configurable: true, // 鍙厤缃�
@@ -195,6 +209,48 @@
       },
     });
   },
+  // 淇敼nav棰滆壊
+  changeNavBarColor(e) {
+    if (type == 'night') {
+      wx.setNavigationBarColor({
+        backgroundColor: '#000000',
+        frontColor: '#ffffff',
+      })
+    } else {
+      wx.setNavigationBarColor({
+        backgroundColor: '#ffffff',
+        frontColor: '#000000',
+      })
+    }
+  },
+  // 姝e垯鎵惧嚭鍚姏src
+  extractSourceSrc(htmlString) {
+    // 姝e垯琛ㄨ揪寮忓尮閰�<source>鏍囩涓殑src灞炴�у��  
+    var srcRegex = /<source\s+src="([^"]+)"/i;
+    var srcTwo = /<audio\s+src="([^"]+)"/i;
+
+    // 鎵ц姝e垯鍖归厤  
+    var match = srcRegex.exec(htmlString);
+    const local = srcTwo.exec(htmlString)
+    // 濡傛灉鍖归厤鎴愬姛锛岃繑鍥炵涓�涓崟鑾风粍鐨勫唴瀹癸紙src灞炴�х殑鍊硷級  
+    if (match && match[1]) {
+      return match[1].replace('../file', app.config.requestCtx + '/file');
+    } else if (local && local[1]) {
+      return local[1].replace('../file', app.config.requestCtx + '/file')
+    } else {
+      // 濡傛灉娌℃湁鍖归厤鍒帮紝杩斿洖null  
+      return null;
+    }
+  },
+
+  // 鎷垮埌鍚姏棰橀櫎audio鏍囩澶栧叾浠栧唴瀹�
+  removeVideoAndAudioTags(htmlString) {
+    // 浣跨敤姝e垯琛ㄨ揪寮忓尮閰嶅苟绉婚櫎鎵�鏈夌殑 <video> 鍜� <audio> 鏍囩
+    var cleanedHtml = htmlString.replace(/<video[^>]*>[\s\S]*?<\/video>|<audio[^>]*>[\s\S]*?<\/audio>/gi, '');
+
+    return cleanedHtml;
+  },
+
   // 鏀瑰彉loading鐘舵��
   changeLoadingState() {
     this.setData({
@@ -203,21 +259,28 @@
   },
   // 杩斿洖鎷︽埅
   beforeleave() {
-    wx.showModal({
-      title: "鎻愮ず",
-      content: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰�",
-      confirmColor: "#ff6c00",
-      cancelColor: "#949494",
-      complete: (res) => {
-        if (res.cancel) {}
-        if (res.confirm) {
-          this.setData({
-            submitStatus: true,
-          });
-          wx.navigateBack();
-        }
-      },
-    });
+    if ((this.data.answerType == 'option' || this.data.answerType == 'mock') && !this.data.submitStatus) {
+      wx.showModal({
+        title: "鎻愮ず",
+        content: "鏈彁浜わ紝鏄惁閫�鍑虹瓟棰�",
+        confirmColor: "#ff6c00",
+        cancelColor: "#949494",
+        complete: (res) => {
+          if (res.cancel) {
+            this.setData({
+              showDialog: true
+            })
+          }
+          if (res.confirm) {
+            this.setData({
+              submitStatus: true,
+              showDialog: false
+            });
+            wx.navigateBack();
+          }
+        },
+      });
+    }
   },
   onChangeSlider(e) {
     this.setData({
@@ -232,9 +295,21 @@
   },
   //璁剧疆鑳屾櫙鑹�
   changeBGColor(e) {
+    const flag = e.detail.value
     this.setData({
-      isNight: e.detail.value,
+      isNight: flag,
     });
+    if (flag) {
+      wx.setNavigationBarColor({
+        backgroundColor: '#000000',
+        frontColor: '#ffffff',
+      })
+    } else {
+      wx.setNavigationBarColor({
+        backgroundColor: '#ffffff',
+        frontColor: '#000000',
+      })
+    }
   },
   // 鑾峰彇淇濆瓨鐨勫�掕鏃舵椂闂�
   getSavedTime() {
@@ -292,11 +367,13 @@
   },
   // 鍒囨崲棰樼洰
   changeSwiper(e) {
-    this.setData({
-      currentIndex: e.detail.index,
-    });
     let index = e.detail.index - 1 >= 0 ? e.detail.index - 1 : 0;
     const item = this.data.questionDataList[index];
+    const lastItem = this.data.questionDataList[index + 1];
+    this.setData({
+      currentIndex: e.detail.index,
+      showId: lastItem.id
+    });
     if (
       (this.data.answerType == "collectQuestion" ||
         this.data.answerType == "errorQuestion") &&
@@ -395,7 +472,6 @@
     const inputData = e.detail.value.detail.value;
     const id = e.detail.value.currentTarget.dataset.id;
     const index = Number(e.detail.value.currentTarget.dataset.index);
-    console.log(index);
     const questionList = this.data.questionDataList;
     questionList.forEach((item) => {
       if (item.id == id) {
@@ -463,7 +539,6 @@
       loading: true,
     });
     const child = this.selectComponent("#question-options");
-    debugger
     if (
       this.data.answerType == "option" ||
       this.data.answerType == "errorQuestion" ||
@@ -526,6 +601,7 @@
     }
     this.setData({
       loading: false,
+      showDialog: false,
     });
   },
   // 鍒濆鍖栧嚱鏁�
@@ -538,7 +614,6 @@
     });
     if (this.data.answerType == "option") {
       if (this.data)
-        // this.startCountdown()
         this.setData({
           countdownTime: 2 * 60 * 60 * 1000,
         });
@@ -602,6 +677,9 @@
             oldMockData.state == "2"
           ) {
             this.startCountdown();
+            this.setData({
+              showDialog: true
+            })
           }
           if (oldMockData.state == "3") {
             this.setData({
@@ -623,6 +701,7 @@
       subjectiveNum: 0,
       currentIndex: 0,
       submitStatus: false,
+      showDialog: true
     });
     if (this.data.answerType == "option") {
       this.setData({
@@ -697,11 +776,13 @@
               this.setData({
                 currentIndex: value.currentIndex,
               });
-              console.log(this.data.submitStatus);
               // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰
               await this.getQuestionList(value.dataList);
             } else {
               await this.getQuestionList(); // 鑾峰彇棰樺簱棰樼洰
+              this.setData({
+                showDialog: true
+              })
             }
           });
         }
@@ -726,6 +807,7 @@
   async getQuestionList(oldData) {
     // 娓呯┖姝g‘棰樻暟璁板綍
     this.setData({
+      noData: false,
       cardList: [],
       correctNum: 0,
     });
@@ -745,6 +827,7 @@
       let query = {
         path: "*",
         queryType: "*",
+
         productId: this.data.bookId,
         cmsPath: pathitem.productLinkPath,
         itemFields: {
@@ -764,6 +847,9 @@
           size: 999,
         },
       };
+      if (this.data.storeInfo) {
+        query.storeInfo = this.data.storeInfo
+      }
       await app.MG.store.getProductDetail(query).then((res) => {
         this.setData({
           total: res.datas.cmsDatas[0].datas.length,
@@ -780,6 +866,19 @@
           });
         }
         res.datas.cmsDatas[0].datas.forEach((item, index) => {
+          if (this.data.storeInfo || this.data.jslx) {
+            if (item.Embedded_QuestionBank_QuestionType == 'singleChoice') {
+              pathitem.name = "鍗曢�夐"
+            } else if (item.Embedded_QuestionBank_QuestionType == 'shortAnswer') {
+              pathitem.name = "绠�绛旈"
+            } else if (item.Embedded_QuestionBank_QuestionType == "completion") {
+              pathitem.name = "濉┖棰�";
+            } else if (item.Embedded_QuestionBank_QuestionType == "multipleChoice") {
+              pathitem.name = "澶氶�夐";
+            } else if (item.Embedded_QuestionBank_QuestionType == "judge") {
+              pathitem.name = "鍒ゆ柇棰�";
+            }
+          }
           let oldObj = "";
           if (oldList)
             oldObj = oldList.find((oldItem) => oldItem.id == item.id);
@@ -843,7 +942,7 @@
                 /\<img/gi,
                 '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
               )
-              .replace(/\<p/gi, '<p class="stem-rich-p"');
+              .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
           }
           // 閫夐」瀵屾枃鏈鐞�
           if (
@@ -856,7 +955,7 @@
               if (item.txt)
                 item.txt = item.txt
                 .replace(/\<img/gi, '<img class="option-rich-img"')
-                .replace(/\<p/gi, '<p class="stem-rich-p"');
+                .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
             });
           }
           // 瑙f瀽瀵屾枃鏈鐞�
@@ -868,6 +967,14 @@
               /\<img/gi,
               '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
             );
+          }
+          // 鍚姏棰樹慨鏀�
+          if (questionObj.questionType == 'singleChoice') {
+            const src = this.extractSourceSrc(questionObj.stem.stemTxt)
+            if (src) {
+              questionObj.src = src
+              questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt)
+            }
           }
           // 鑾峰彇鍥剧墖
           if (
@@ -943,13 +1050,24 @@
             questionDataList: questionList,
             cardList: cardUpdatedList,
           });
+          console.log(
+            '棰樼洰', this.data.questionDataList
+          );
         });
       });
     }
     // 鏈夐鐩啀寮�濮嬪�掕鏃�
-    if (this.data.questionDataList.length) this.startCountdown();
+    if (this.data.questionDataList.length) {
+      console.log(this.data.questionDataList);
+      this.startCountdown();
+    } else {
+      this.setData({
+        noData: true
+      })
+    }
     this.setData({
       loading: false,
+      showId: this.data.questionDataList[0].id
     });
   },
   // 鎵规敼棰樼洰 锛堢粌涔狅紝鎴戠殑閿欓锛屾垜鐨勬敹钘�,锛岀粍鍗凤級
@@ -1141,7 +1259,6 @@
         }
       }
     }
-
     this.setAnswerInfo(setInfoData);
   },
   // 鎻愪氦绛旈鏁版嵁
@@ -1196,6 +1313,7 @@
         } else {
           this.setData({
             loading: false,
+            noData: true
           });
           wx.showModal({
             title: "鎻愮ず",
@@ -1268,6 +1386,9 @@
           Embedded_QuestionBank_Difficulty: [],
         },
       };
+      if (this.data.storeInfo) {
+        query.storeInfo = this.data.storeInfo
+      }
       await app.MG.store.getProductDetail(query).then((res) => {
         let questionArr = [];
         res.datas.cmsDatas[0].datas.forEach((item, index) => {
@@ -1347,7 +1468,7 @@
                 /\<img/gi,
                 '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
               )
-              .replace(/\<p/gi, '<p class="stem-rich-p"');
+              .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
           }
           // 閫夐」瀵屾枃鏈鐞�
           if (
@@ -1360,7 +1481,7 @@
               if (item.txt)
                 item.txt = item.txt
                 .replace(/\<img/gi, '<img class="option-rich-img"')
-                .replace(/\<p/gi, '<p class="stem-rich-p"');
+                .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
             });
           }
           // 瑙f瀽瀵屾枃鏈鐞�
@@ -1372,6 +1493,14 @@
               /\<img/gi,
               '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
             );
+          }
+          // 鍚姏棰樹慨鏀�
+          if (questionObj.questionType == 'singleChoice') {
+            const src = this.extractSourceSrc(questionObj.stem.stemTxt)
+            if (src) {
+              questionObj.src = src
+              questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt)
+            }
           }
           if (item.Embedded_QuestionBank_QuestionType == "judge") {
             questionObj.type = "鍒ゆ柇棰�";
@@ -1414,6 +1543,7 @@
     }
     this.setData({
       questionDataList: questionArr,
+      showId: questionArr[0].id,
       cardList: cardList,
       loading: false,
     });
@@ -1435,7 +1565,8 @@
           this.getErrorDataList();
         } else {
           this.setData({
-            loading: true,
+            loading: false,
+            noData: true
           });
           wx.showModal({
             title: "鎻愮ず",
@@ -1505,6 +1636,9 @@
         Embedded_QuestionBank_Difficulty: [],
       },
     };
+    if (this.data.storeInfo) {
+      query.storeInfo = this.data.storeInfo
+    }
     await app.MG.store.getProductDetail(query).then((res) => {
       let questionArr = [];
       res.datas.cmsDatas[0].datas.forEach((item, index) => {
@@ -1586,7 +1720,7 @@
               /\<img/gi,
               '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
             )
-            .replace(/\<p/gi, '<p class="stem-rich-p"');
+            .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
         }
         // 閫夐」瀵屾枃鏈鐞�
         if (
@@ -1599,7 +1733,7 @@
             if (item.txt)
               item.txt = item.txt
               .replace(/\<img/gi, '<img class="option-rich-img"')
-              .replace(/\<p/gi, '<p class="stem-rich-p"');
+              .replace(/\<p/gi, '<p class="stem-rich-p"').replace('../file', app.config.requestCtx + '/file');
           });
         }
         // 瑙f瀽瀵屾枃鏈鐞�
@@ -1611,6 +1745,15 @@
             /\<img/gi,
             '<img style="max-width: 300rpx !important;object-fit: contain;" class="stem-rich-img" '
           );
+        }
+        // 鍚姏棰樹慨鏀�
+        if (questionObj.questionType == 'singleChoice') {
+          const src = this.extractSourceSrc(questionObj.stem.stemTxt)
+          if (src) {
+            questionObj.src = src
+            questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt)
+            console.log('棰樺共', questionObj.stem.stemTxt);
+          }
         }
         if (item.Embedded_QuestionBank_QuestionType == "judge") {
           questionObj.type = "鍒ゆ柇棰�";
@@ -1652,11 +1795,11 @@
       }
       this.setData({
         questionDataList: questionArr,
+        showId: questionArr[0].id,
         cardList: cardList,
         loading: false,
       });
     });
-    // loadings.value = false
   },
   // 鑾峰彇缁勫嵎缁撴灉
   async getEduQuizConfig() {
@@ -1781,6 +1924,9 @@
           Embedded_QuestionBank_Difficulty: [],
         },
       };
+      if (this.data.storeInfo) {
+        query.storeInfo = this.data.storeInfo
+      }
       await app.MG.store.getProductDetail(query).then((res) => {
         res.datas.cmsDatas[0].datas.forEach((item, index) => {
           // 寰幆questionList,缁欐瘡棰樿祴鍊煎垎鏁�
@@ -1847,7 +1993,7 @@
             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"').replace('../file', app.config.requestCtx + '/file');
           }
           // 閫夐」瀵屾枃鏈鐞�
           if (
@@ -1861,8 +2007,16 @@
                 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');
             });
+          }
+          // 鍚姏棰樹慨鏀�
+          if (questionObj.questionType == 'singleChoice') {
+            const src = this.extractSourceSrc(questionObj.stem.stemTxt)
+            if (src) {
+              questionObj.src = src
+              questionObj.stem.stemTxt = this.removeVideoAndAudioTags(questionObj.stem.stemTxt)
+            }
           }
           // 鑾峰彇鍥剧墖
           if (
@@ -1927,6 +2081,7 @@
     }
     this.setData({
       loading: false,
+      showId: this.data.questionDataList[0].id
     });
   },
   // 鑾峰彇缁勫嵎鏁版嵁
@@ -1987,11 +2142,12 @@
       })
       .then((res) => {
         if (res[0]) {
+          // 杩欓噷鐨� countdownTime 璧嬪�硷細濡傛灉鏄椂闂村埌浜嗘彁浜わ紝璁板綍鐨勫墿浣欐椂闂村氨鏄�0锛屾墍浠ワ細濡傛灉鏄�0鐨勮瘽璧嬪��1绉掞紝闃叉鐩戝惉鍒版椂闂翠负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,
+            countdownTime: JSON.parse(res[0].value).time > 0 ?
+              JSON.parse(res[0].value).time : 1000,
             "mockData.answer": JSON.parse(res[0].value).answerData,
           });
           console.log(JSON.parse(res[0].value));

--
Gitblit v1.9.1