Ver Fonte

update 更新

wangxy há 2 meses atrás
pai
commit
2f4a882f12

+ 59 - 0
pages/newEnglish/components/audioRightWrong.vue

@@ -0,0 +1,59 @@
+<template>
+  <uni-popup ref="popupRef" :animation="false" :is-mask-click="false"
+             mask-background-color="rgba(51, 137, 217, 0.95);">
+    <view :class="data.image">
+    </view>
+  </uni-popup>
+</template>
+
+<script setup>
+	import {
+		onLoad
+	} from "@dcloudio/uni-app"
+	import {
+		ref,
+		reactive
+	} from "vue"
+	import {
+		resultAudioPlayer,
+		resultImageList
+	} from "./useAudioRightWrong.js"
+
+  const popupRef = ref(null)
+
+	const data = reactive({
+		result: '',
+		image: '',
+		showImage: false,
+	})
+
+	onLoad(() => {
+		pageInit()
+	})
+
+	function pageInit() {
+		uni.$on('result-audio-play', (code) => {
+			const {
+				codeT
+			} = code;
+			data.result = codeT;
+			data.image = resultImageList[code]
+			data.showImage = true;
+      popupRef.value.open();
+		})
+		uni.$on('result-audio-ended', (code) => {
+			const {
+				codeT
+			} = code;
+			data.result = codeT;
+			data.image = resultImageList[code];
+			data.showImage = false;
+      popupRef.value.close();
+
+    })
+	}
+</script>
+
+<style scoped>
+
+</style>

+ 5 - 0
pages/newEnglish/components/beiPage.vue

@@ -76,6 +76,9 @@
 		onLoad
 	} from "@dcloudio/uni-app"
 	import cacheManager from '@/utils/cacheManager';
+  import {resultAudioPlayer} from "./useAudioRightWrong"
+
+  const resultAudioPlayerD = new resultAudioPlayer();
 
 	const userCode = getUserIdentity();
 	
@@ -110,9 +113,11 @@
 	function checkIsRight() {
 		if (data.answer == props.activeWord.name) {
 			data.result = true;
+      resultAudioPlayerD.play('right','bei')
 			noticeBackDb()
 		} else {
 			data.result = false;
+      resultAudioPlayerD.play('wrong','bei')
 		}
 		noticeBackComplete()
 	}

+ 7 - 0
pages/newEnglish/components/pinPage.vue

@@ -43,6 +43,9 @@
 	import {
 		getUserIdentity,
 	} from "@/utils/common.js"
+  import {resultAudioPlayer} from "./useAudioRightWrong"
+
+  const resultAudioPlayerD = new resultAudioPlayer();
 
 	const emits = defineEmits(['play-audio'])
 
@@ -142,6 +145,9 @@
 			data.isAll = false;
 		} else {
 			data.isAll = true;
+      if (data.isAll && !data.result) {
+        resultAudioPlayerD.play('wrong','pin')
+      }
 		}
 
 	}
@@ -150,6 +156,7 @@
 		if (data.list.join('') === data.selectList.join('')) {
 			// 正确
 			data.result = true;
+      resultAudioPlayerD.play('right','pin')
 			noticeBackDb();
 		} else {
 			data.result = false;

+ 5 - 0
pages/newEnglish/components/selectPage.vue

@@ -49,6 +49,9 @@
 	import {
 		getUserIdentity,
 	} from "@/utils/common.js"
+  import {resultAudioPlayer} from "./useAudioRightWrong"
+
+  const resultAudioPlayerD = new resultAudioPlayer();
 
 	const userCode = getUserIdentity();
 	
@@ -97,9 +100,11 @@
 		if (data.answer == props.activeWord.daan) {
 			// 正确
 			data.result = true;
+      resultAudioPlayerD.play('right','select')
 			noticeBackDb()
 		} else {
 			data.result = false;
+      resultAudioPlayerD.play('wrong','select')
 		}
 	}
 

+ 47 - 0
pages/newEnglish/components/useAudioRightWrong.js

@@ -0,0 +1,47 @@
+let audioContext = null;
+let code = null; // 身份标识
+audioContext = uni.createInnerAudioContext(); // 单例模式[3](@ref)
+audioContext.onEnded(() => {
+	// 播放结束
+	uni.$emit('result-audio-ended', code)
+})
+audioContext.onPlay(() => {
+	// 播放
+	uni.$emit('result-audio-play', code);
+});
+
+const audioList = {
+	right: '/static/mp3/newYingyu/right-tip.mp3',
+	wrong: '/static/mp3/newYingyu/error-tip.mp3'
+}
+
+export const resultImageList = {
+	right: '/static/images/study/cjdc/right-tip-img-gif',
+	wrong: '/static/images/study/cjdc/error-tip-img-gif'
+}
+
+
+export class resultAudioPlayer {
+	// 播放音频
+	play(codeT, code1) {
+		code = {
+			code1,
+			codeT
+		};
+		if (audioContext.src === audioList[codeT] && !audioContext.paused) return;
+		audioContext.src = audioList[codeT];
+		audioContext.play();
+	}
+
+	// 暂停播放
+	pause() {
+		audioContext?.pause();
+	}
+
+	// 停止播放(释放资源)
+	stop() {
+		audioContext?.stop();
+		audioContext = null;
+	}
+
+}

+ 3 - 0
pages/newEnglish/index.vue

@@ -25,6 +25,8 @@
 				<view class="word-view-btn" v-if="isLast&&isLearnRecord!=0" @click="handleComplete">完成</view>
 			</view>
 		</view>
+		
+		<audioRightWrongVue></audioRightWrongVue>
 	</view>
 </template>
 
@@ -47,6 +49,7 @@
 		audioPlayer
 	} from "./components/useAudio.js"
   import {getWordCancel} from "../../api/word";
+  import audioRightWrongVue from "./components/audioRightWrong.vue";
 
 	const userCode = getUserIdentity();