From cb6bb8bda31df75afe5a5bd50fe8e3ff6a3d34e2 Mon Sep 17 00:00:00 2001
From: 闫增涛 <1829501689@qq.com>
Date: 星期一, 15 四月 2024 09:31:39 +0800
Subject: [PATCH] 详情页bug修改,资源购买页添加骨架屏

---
 packageBookService/pages/bookServices/examination/examination.js |   75 +++++++++++++++++++++++++++++++++++--
 1 files changed, 71 insertions(+), 4 deletions(-)

diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js
index f3924ad..070b53f 100644
--- a/packageBookService/pages/bookServices/examination/examination.js
+++ b/packageBookService/pages/bookServices/examination/examination.js
@@ -30,6 +30,7 @@
     total: 0, // 棰樼洰鎬绘暟
     cardList: [], // 鎻愪氦椤�,
     questionDataList: [], // 鏄剧ず棰樼洰鍒楄〃
+    noData: false,
     mockid: 0,
     uuid: 0,
     mockData: {
@@ -46,6 +47,7 @@
     sliderValue: 0, // 瀛椾綋婊戝潡
     startTime: "", //杩涘叆椤甸潰褰撳墠鏃堕棿
     pauseTime: 0, //鏆傚仠鏃堕棿
+
   },
 
   /**
@@ -180,7 +182,6 @@
   // 鐩戝惉watch
   watch(context, variableName, callback) {
     let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊�
-
     // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter
     Object.defineProperty(context.data, variableName, {
       configurable: true, // 鍙厤缃�
@@ -195,6 +196,35 @@
       },
     });
   },
+
+  // 姝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({
@@ -463,7 +493,6 @@
       loading: true,
     });
     const child = this.selectComponent("#question-options");
-    debugger
     if (
       this.data.answerType == "option" ||
       this.data.answerType == "errorQuestion" ||
@@ -697,7 +726,6 @@
               this.setData({
                 currentIndex: value.currentIndex,
               });
-              console.log(this.data.submitStatus);
               // 鎼哄甫绛旈璁板綍 鑾峰彇棰樼洰
               await this.getQuestionList(value.dataList);
             } else {
@@ -726,6 +754,7 @@
   async getQuestionList(oldData) {
     // 娓呯┖姝g‘棰樻暟璁板綍
     this.setData({
+      noData: false,
       cardList: [],
       correctNum: 0,
     });
@@ -765,6 +794,9 @@
         },
       };
       await app.MG.store.getProductDetail(query).then((res) => {
+        if (!res.datas.cmsDatas[0].datas.length) return this.setData({
+          noData: true
+        })
         this.setData({
           total: res.datas.cmsDatas[0].datas.length,
         });
@@ -868,6 +900,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 (
@@ -1196,6 +1236,7 @@
         } else {
           this.setData({
             loading: false,
+            noData: true
           });
           wx.showModal({
             title: "鎻愮ず",
@@ -1373,6 +1414,14 @@
               '<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 = "鍒ゆ柇棰�";
             judgeArr.push(questionObj);
@@ -1435,7 +1484,8 @@
           this.getErrorDataList();
         } else {
           this.setData({
-            loading: true,
+            loading: false,
+            noData: true
           });
           wx.showModal({
             title: "鎻愮ず",
@@ -1611,6 +1661,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 = "鍒ゆ柇棰�";
@@ -1864,6 +1923,14 @@
                 );
             });
           }
+          // 鍚姏棰樹慨鏀�
+          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 (
             questionObj.stemStyle == "Image" ||

--
Gitblit v1.9.1