Kaynağa Gözat

Merge branch '2024鹅状元' of https://gogs.mtavip.com/wangguoyu/uniProject into 2024鹅状元

tanxue 4 ay önce
ebeveyn
işleme
5ea90106e1

+ 1 - 0
components/question/yingyu/danxuan.vue

@@ -68,6 +68,7 @@
 	}
 	
 	function formatData(val) {
+		console.log('val',val);
 		if (val) {
 			data.name = val.name;
 			data.contents = val.optList.map((item, index) => {

+ 187 - 0
components/question/yingyu/danxuanCeshi.vue

@@ -0,0 +1,187 @@
+<template>
+	<view>
+		<view>12312312</view>
+		<!-- 选项区域 -->
+		<view v-for="(item,index) in data.contents" class="yingyu-danxuan-option-box" :key="index">
+			<text class="option-change">{{item.number}}</text>
+			<view v-if="item.placeholders.length ==1"  @click="ceshiAA(item,index)">
+					<rich-text :nodes="item.neirong" class="option-question"></rich-text>
+			</view>
+			<view v-else v-for="(item2,index2) in item.placeholders"  @click="ceshiBB(item2,index2)">
+					<rich-text :nodes="item.neirong[index2]" class="option-question"></rich-text>
+			</view>
+		</view>
+	</view>
+</template>
+<script setup>
+	import {
+		ref,
+		reactive,
+		onMounted,
+		watch
+	} from 'vue';
+	import {
+		useQuestionTools
+	} from "../useQuestionTools"
+
+	import textReplaceIconVue from './textReplaceIcon.vue'
+
+	let richTextNodes = [{
+		name: 'div',
+		attrs: {
+			class: 'div-class',
+		},
+		children: [{
+			type: 'text',
+			text: 'Hello&nbsp;uni-app!'
+		}]
+	}]
+	const {
+		getLetterByIndex
+	} = useQuestionTools();
+
+	const props = defineProps({
+		question: {
+			type: Object,
+		},
+		showError: {
+			type: Boolean,
+			default: false
+		},
+		placeholders: { // 占位符
+			type: Array,
+			required: true
+		},
+		code: {
+			type: String,
+		}
+	})
+	const data = reactive({
+		name: '', //题干数据
+		contents: [], // 选项数据
+	})
+	let modifiedHtml = ''
+	let index11 = ''
+	let number = 0
+	const iconHtml = ref('<p class="yingyu-canplay-img" data-index="0">喇叭1</p>')
+	const dynamicContentRef = ref(null);
+	watch(() => props.question, (val) => formatData(val), {
+		immediate: true
+	})
+
+
+	function itemclick(event) {
+		console.log('event', event);
+	}
+	function ceshiAA(item,index){
+		console.log('item', item);
+		console.log('index', index);
+	}
+	function ceshiBB(item,index){
+		console.log('item2', item);
+		console.log('index2', index);
+	}
+	function formatData(val) {
+		if (val) {
+			data.name = val.name;
+			data.contents = val.optList.map((item, index) => {
+				//	console.log('item,',item);
+				const iconHtml =
+					`<img class="yingyu-canplay-img">`;; // 这里使用了一个简单的图标符号
+				modifiedHtml = item.neirong.replace(/&&&/g, iconHtml);
+				let regex = /<p[>]*>([\s\S]*?)<\/p>/g;
+				let pTagCount = (modifiedHtml.match(/<p>/g) || []).length;
+				let result;
+				if (pTagCount === 1) {
+				  // 如果只有一个<p>标签,保持原样
+				  result = modifiedHtml;
+				} else if (pTagCount > 1) {
+				  // 如果有多个<p>标签,转换成数组
+				  result = modifiedHtml.match(regex);
+				} else {
+				  // 如果没有<p>标签,可以返回一个空数组或null,根据实际需求决定
+				  result = [];
+				}
+				
+			//	console.log('modifiedHtml', modifiedHtml);
+				return {
+					neirong: result,
+					number: getLetterByIndex(index),
+					placeholders: getPlaceholders(item.neirong)
+				}
+			})
+			console.log('data', data);
+		}
+	}
+
+	function getPlaceholders(html) {
+			console.log('html',html);
+		// 使用正则表达式匹配所有&&&,并返回一个数组,每个元素代表一个占位符
+		return html.match(/&&&/g) || [];
+	}
+	let audioContext = null;
+	let isPlaying = false;
+	let currentIndex = -1;
+
+
+	function initAudioContext() {
+		if (!audioContext) {
+			audioContext = uni.createInnerAudioContext();
+
+			// 监听音频播放状态
+			audioContext.onPlay(() => {
+				isPlaying = true;
+				console.log('音频开始播放');
+			});
+
+			audioContext.onPause(() => {
+				isPlaying = false;
+				console.log('音频暂停播放');
+			});
+
+			audioContext.onStop(() => {
+				isPlaying = false;
+				console.log('音频停止播放');
+			});
+
+			audioContext.onEnded(() => {
+				isPlaying = false;
+				console.log('音频播放结束');
+			});
+		}
+	}
+
+	function playAudio(src) {
+		if (!audioContext) {
+			initAudioContext();
+		}
+		audioContext.src = src;
+		audioContext.play();
+	}
+
+	function audioCreat(item, index, placeholderIndex) {
+
+		console.log('item', item);
+		console.log('index', index);
+		console.log('placeholderIndex', placeholderIndex);
+		return
+		// 如果 index 变化了,或者当前没有音频在播放,就播放新音频
+		if (index !== currentIndex || !isPlaying) {
+			// 如果之前有音频在播放,先暂停
+			if (isPlaying) {
+				audioContext.pause();
+			}
+			// 更新当前索引和播放状态
+			currentIndex = index;
+			playAudio(item.audio);
+		} else {
+			// 如果 index 没变化且音频正在播放,就暂停音频
+			if (isPlaying) {
+				audioContext.pause();
+			} else {
+				// 如果 index 没变化但音频没播放,就播放音频
+				playAudio(item.audio);
+			}
+		}
+	}
+</script>

+ 50 - 49
components/question/yingyu/textReplaceIcon.vue

@@ -39,17 +39,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}`
+						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.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}`
+					} 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}`
+						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>`
 						);
@@ -69,67 +73,64 @@
 					this.isFirst = -1
 					return;
 				}
-
 				if (this.isplaying) {
 					uni.$emit('do-yy-audio-stop', data);
 					this.isFirst++;
 					return;
 				}
-
 				// 初次播放
 				if (!this.isplaying) {
 					uni.$emit('do-yy-audio-play', data);
 					this.isFirst++;
 					return;
 				}
-
 			}
 		},
-				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-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', () => {
+		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('unitTest-submit', () => {
+					}
+				}
+			})
+			// 音频播放
+			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-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">

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

@@ -50,7 +50,10 @@ export function useAudio() {
 			uni.$emit('destory-stop')	
 		}
 	}
-
+	// 离开当前页面 停止播放
+	uni.$on('back-outpage',() => {
+		handleStop();
+	})
 
 	// 播放过程中点击同一个视频触发终止
 	uni.$on('repeat-play-to-stop',() => {

+ 78 - 28
pages/unitTest/index.vue

@@ -12,24 +12,25 @@
 						<danxuan :question="item" v-if="item.type == '1'"></danxuan>
 						<panduan :question="item" v-if="item.type == '2'"></panduan>
 						<tiankong :question="item" v-if="item.type == '3'" :placeholders="item.placeholders"></tiankong>
-						<yingyuDanxuan :question="item" v-if="item.type == '4'" :placeholders="item.placeholders"></yingyuDanxuan>
+						<yingyuDanxuan :question="item" v-if="item.type == '4'" :placeholders="item.placeholders">
+						</yingyuDanxuan>
 					</view>
 				</template>
 			</w-swiper>
-			<view class="exam-submit-btn" v-if="current === list.length-1" 
-				@click="handleSubmit(uniPointsRef)"></view>
+			<view class="exam-submit-btn" v-if="current === list.length-1" @click="handleSubmit(uniPointsRef)"></view>
 		</view>
-			
+
 		<!--  左右滑动  -->
-		<view class="tip-mask-box"  @click="handleCloseTishi" v-if="showTishi">
+		<view class="tip-mask-box" @click="handleCloseTishi" v-if="showTishi">
 			<view class="exam-tip-box">左右滑动查看更多题目</view>
 		</view>
-		
+
 
 		<!-- 答卷 -->
-		<chengji ref="chengjiRef" :list="list"  @back="handleBack" :cardId="cardId"></chengji>
+		<chengji ref="chengjiRef" :list="list" @back="handleBack" :cardId="cardId"></chengji>
 		<!-- 分数弹窗 -->
-		<uniPointsVue ref="uniPointsRef" @checkAnswer="checkAnswer" @goStudy="goStudyContinue" :isLastZhang="!!haveFlag" :studyFlag="studyFlag"></uniPointsVue>
+		<uniPointsVue ref="uniPointsRef" @checkAnswer="checkAnswer" @goStudy="goStudyContinue" :isLastZhang="!!haveFlag"
+			:studyFlag="studyFlag"></uniPointsVue>
 		<!-- 填空 -->
 		<FillItem :value="result" ref="popupRef" @blur="onBlur"></FillItem>
 
@@ -46,7 +47,8 @@
 	import danxuan from "@/components/question/danxuan.vue";
 	import panduan from "@/components/question/panduan.vue";
 	import tiankong from "@/components/question/tiankong.vue";
-	import yingyuDanxuan from "@/components/question/yingyu/danxuan.vue";
+	 import yingyuDanxuan from "@/components/question/yingyu/danxuanCeshi.vue";
+	//import yingyuDanxuan from "@/components/question/yingyu/danxuan.vue";
 	import chengji from "@/components/chengji/chengji.vue";
 	import uniPointsVue from '@/components/points/uni-points.vue';
 	import * as httpUnit from "@/api/unitTest.js"
@@ -58,10 +60,13 @@
 	} from './useUnit';
 	import {
 		ref,
+		reactive
 	} from "vue";
-    import cacheManager from "@/utils/cacheManager";
-	import {onLoad} from "@dcloudio/uni-app"
-	
+	import cacheManager from "@/utils/cacheManager";
+	import {
+		onLoad
+	} from "@dcloudio/uni-app"
+
 
 
 	const {
@@ -88,31 +93,76 @@
 
 	const uniPointsRef = ref(null);
 	const chengjiRef = ref(null);
-	const popupRef= ref(null);
+	const popupRef = ref(null);
 	const result = ref('');
 	const curTiankong = ref(null);
-	
+
+	const ceshiData = reactive({
+			"stId": 378,
+			"type": 4,
+			"name": "<p>发音:/b/ 1231[yingyu1]</p>",
+			"result": "0",
+			"answer": "<p>单词book发音为/bʊk/ [yingyu5]; 单词pool的发音是/puːl/ [yingyu4]。</p>",
+			"audios": "https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile1a3bd1236181491b8de49e84857a9163.MP3,https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile16b16267eafb43b6a272b8b212049ae4.MP3,https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFileb23646275ada46769e76a3ae0dba230e.MP3,https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFileeff5e2bb7a6f4a0d9bc78b503ebea846.MP3,https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile6cbe483d691b4e5eb13401e301d62c9c.mp3",
+			"jiangjie": null,
+			"optList": [{
+				"neirong": "<p>book [yingyu2]</p>",
+				"audio":"https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile1a3bd1236181491b8de49e84857a9163.MP3"
+			}, {
+				"neirong": "<p>pool [yingyu3]</p>",
+				"audio":"https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile16b16267eafb43b6a272b8b212049ae4.MP3"
+			}]
+		},
+		{
+			"stId": 379,
+			"type": 4,
+			"name": "<p>判断划线部分发音是否相同。</p><p><br></p><p>park  [yingyu1]</p><p><br></p><p>cup [yingyu2]</p>",
+			"result": "0",
+			"answer": "<p>在单词park中,p发 /p/音 [yingyu3];在单词cup中,p发/p/音 [yingyu4],故发音相同。</p>",
+			"audios": "https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile304fcea7440e400ca2bd0207354b2fa3.MP3,https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile052863fbfd074e718c63509db47f0f6c.MP3,https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFilefee406d7614443609b450b4f260b33e5.MP3,https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile725a16a4dea642ccaf0129ae877b4a7c.MP3",
+			"jiangjie": null,
+			"optList": [{
+				"neirong": "<p>相同</p>",
+					"audio":"https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile1a3bd1236181491b8de49e84857a9163.MP3"
+			}, {
+				"neirong": "<p>不同</p>",
+					"audio":"https://ezy-app.oss-cn-beijing.aliyuncs.com/test/resource/uploadFile1a3bd1236181491b8de49e84857a9163.MP3"
+			}]
+		}
+	);
+
+
 	function getPopupRef() {
 		return popupRef.value;
 	}
 	onLoad(() => {
-		uni.$on('tiankong-fillItem',(val) => {
-			const {index,question} = val;
+		uni.$on('tiankong-fillItem', (val) => {
+			const {
+				index,
+				question
+			} = val;
 			curTiankong.value = val;
 			result.value = question.reply[index];
 			const dom = getPopupRef();
 			dom && dom.showPopup();
 		})
-		
+
 	})
-	function onBlur({result}) {
+
+	function onBlur({
+		result
+	}) {
 		if (curTiankong.value) {
-			uni.$emit('tiankong-setResult', {index: curTiankong.value.index,stId:curTiankong.value.question.stId,result});
+			uni.$emit('tiankong-setResult', {
+				index: curTiankong.value.index,
+				stId: curTiankong.value.question.stId,
+				result
+			});
 		}
 		const dom = getPopupRef();
 		dom && dom.handleClear();
 	}
-	
+
 	// 查看答案
 	function checkAnswer() {
 		chengjiRef.value.showPopup();
@@ -120,27 +170,28 @@
 	// 继续学习
 	async function goStudyContinue() {
 		// 设置 从单元测试 到 岛 的路由参数
-    activeZhang.value.nextZhang ? activeZhang.value.nextZhang.zhangId : null;
-    cacheManager.updateObject('auth', {
-      zhangId: activeZhang.value.nextZhang.zhangId,
-    })
+		activeZhang.value.nextZhang ? activeZhang.value.nextZhang.zhangId : null;
+		cacheManager.updateObject('auth', {
+			zhangId: activeZhang.value.nextZhang.zhangId,
+		})
 		uni.redirectTo({
 			url: `/pages/study/index`
 		})
 	}
-	
+
 	function handleBack() {
 		// 数学
 		uni.redirectTo({
 			url: `/pages/study/index`
 		})
+		uni.$emit('back-outpage')
 	}
-	
+
 	function onSwiperChange(index) {
 		current.value = index;
 		uni.$emit('swiper-change', index)
 	}
-	
+
 	function courseBjFun() {
 		switch (cardId) {
 			case 1:
@@ -153,7 +204,6 @@
 				break;
 		}
 	}
-
 </script>
 
 <style lang="scss" scoped>

+ 1 - 0
pages/wrong/index.vue

@@ -129,6 +129,7 @@
 		uni.redirectTo({
 			url: '/pages/my/index'
 		})
+		uni.$emit('back-outpage')
 	}
 
 	function handleBackFromCuoti() {