Bläddra i källkod

英语题追加音频播放

wangxy 4 månader sedan
förälder
incheckning
44e605fee1
2 ändrade filer med 46 tillägg och 49 borttagningar
  1. 46 48
      components/question/yingyu/textReplaceIcon.vue
  2. 0 1
      components/question/yingyu/useAudio.js

+ 46 - 48
components/question/yingyu/textReplaceIcon.vue

@@ -38,23 +38,21 @@
 					// 使用正则表达式全局替换占位符
 					const regex = new RegExp(`\\${placeholder}`, 'g');
 					if (!this.isplaying) {
-						
+
 						const cId = this.code ? `t_${this.question.stId}_${index}_${this.code}`:`t_${this.question.stId}_${index}`
 						result = result.replace(regex,
 							`<view	class="yingyu-canplay-img" id="${cId}"></view>`
 						);
-					} else if (this.question.stId == this.isplaying.stId && this.isplaying.index == index) {
+					} else if (this.isplaying && this.question.stId == this.isplaying.stId && this.isplaying.index == index) {
 						const cId = this.code ? `t_${this.question.stId}_${index}_${this.code}`:`t_${this.question.stId}_${index}`
 						result = result.replace(regex,
 							`<view	class="yingyu-playing-img" id="${cId}"></view>`
 						);
 					} else {
 						const cId = this.code ? `t_${this.question.stId}_${index}_${this.code}`:`t_${this.question.stId}_${index}`
-						console.log('before',result)
 						result = result.replace(regex,
 							`<view	class="yingyu-canplay-img" id="${cId}"></view>`
 						);
-						console.log('after result', result)
 					}
 				});
 				this.myflag++;
@@ -87,51 +85,51 @@
 
 			}
 		},
-		created() {
-			// 切换不同播放音频时 重置状态
-			uni.$on('reset-playing-status', (data) => {
-				if (this.isplaying) {
-					if (data.stId == this.isplaying.stId && data.index == this.isplaying.index) {
+				created() {
+					// 切换不同播放音频时 重置状态
+					uni.$on('reset-playing-status', (data) => {
+						if (this.isplaying) {
+							if (data.stId == this.isplaying.stId && data.index == this.isplaying.index) {
+								this.isplaying = null;
+							}
+						}
+					})
+					// 音频播放
+					uni.$on('yy-audio-playing', (data) => {
+						if (this.isplaying) {
+							// 存在播放实例 并且播放非同一音频
+							if (this.isplaying.stId != data.value.stId) {
+								this.isplaying = null;
+							}
+						} else {
+							// 不存在播放实例 
+							this.isplaying = data;
+						}
+					})
+					// 音频异常  重置音频
+					uni.$on('yy-audio-error', (data) => {
 						this.isplaying = null;
-					}
-				}
-			})
-			// 音频播放
-			uni.$on('yy-audio-playing', (data) => {
-				if (this.isplaying) {
-					// 存在播放实例 并且播放非同一音频
-					if (this.isplaying.stId != data.value.stId) {
+					})
+					// 音频自然播放结束  重置音频
+					uni.$on('yy-audio-end', (data) => {
 						this.isplaying = null;
-					}
-				} else {
-					// 不存在播放实例 
-					this.isplaying = data;
+					})
+					// 音频销毁 重置音频
+					uni.$on('destory-stop', (data) => {
+						this.isplaying = null;
+					})
+					// 试题切换 重置音频
+					uni.$on('swiper-change', () => {
+						this.isplaying = null;
+					})
+					// 解析关闭 重置音频
+					uni.$on('question-jiexi-close', () => {
+						this.isplaying = null;
+					})
+					uni.$on('unitTest-submit', () => {
+						this.isplaying = null;
+					})
 				}
-			})
-			// 音频异常  重置音频
-			uni.$on('yy-audio-error', (data) => {
-				this.isplaying = null;
-			})
-			// 音频自然播放结束  重置音频
-			uni.$on('yy-audio-end', (data) => {
-				this.isplaying = null;
-			})
-			// 音频销毁 重置音频
-			uni.$on('destory-stop', (data) => {
-				this.isplaying = null;
-			})
-			// 试题切换 重置音频
-			uni.$on('swiper-change', () => {
-				this.isplaying = null;
-			})
-			// 解析关闭 重置音频
-			uni.$on('question-jiexi-close', () => {
-				this.isplaying = null;
-			})
-			uni.$on('unitTest-submit', () => {
-				this.isplaying = null;
-			})
-		}
 	}
 </script>
 <script module="YY" lang="renderjs">
@@ -187,12 +185,12 @@
 				}
 			},
 			initListener(question) {
-				console.log('init')
 				if (!question) {
 					return;
 				}
 				question.placeholders.forEach((item, index) => {
-					const cId = this.code ? `t_${this.question.stId}_${index}_${this.code}`:`t_${this.question.stId}_${index}`
+					const cId = this.code ? `t_${question.stId}_${index}_${this.code}` :
+						`t_${question.stId}_${index}`
 					const dom = document.getElementById(cId)
 					if (dom) {
 						const qaindex = this.callbacks.findIndex(item => item.index === index)

+ 0 - 1
components/question/yingyu/useAudio.js

@@ -32,7 +32,6 @@ export function useAudio() {
 	},50)
 	
 	function handlePlay(data) {
-		// console.log('play111',data)
 		if (innerAudioContext.value) {
 			innerAudioContext.value.stop();
 			innerAudioContext.value.destroy();