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 | 67 ++++++++++++++++++++++++++++++--- 1 files changed, 60 insertions(+), 7 deletions(-) diff --git a/packageBookService/pages/bookServices/examination/examination.js b/packageBookService/pages/bookServices/examination/examination.js index 2c5d010..070b53f 100644 --- a/packageBookService/pages/bookServices/examination/examination.js +++ b/packageBookService/pages/bookServices/examination/examination.js @@ -182,7 +182,6 @@ // 鐩戝惉watch watch(context, variableName, callback) { let value = context.data[variableName]; // 鑾峰彇琚洃鍚睘鎬х殑褰撳墠鍊� - // 浣跨敤 Object.defineProperty 鏂规硶鍦ㄦ暟鎹璞′笂瀹氫箟灞炴�х殑 getter 鍜� setter Object.defineProperty(context.data, variableName, { configurable: true, // 鍙厤缃� @@ -197,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({ @@ -874,12 +902,12 @@ ); } // 鍚姏棰樹慨鏀� - if (questionObj.questionType == 'singleChoiceArr') { - questionObj.stem.stemTxt = questionObj.stem.stemTxt - .replace( - /\<audio/gi, - '<audio @play="play" ' - ) + 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 ( @@ -1386,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); @@ -1625,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 = "鍒ゆ柇棰�"; @@ -1878,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