From d35f5acd92a50d608d141e1214555feef89e31a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E8=88=AA?= Date: Mon, 10 Nov 2025 16:56:23 +0800 Subject: [PATCH] fix; bug --- src/api/common.js | 15 +++++++ src/pages/course/components/talkingItem.vue | 48 ++++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/src/api/common.js b/src/api/common.js index 4656ddad..3a75acb3 100644 --- a/src/api/common.js +++ b/src/api/common.js @@ -169,6 +169,21 @@ export function downloadVoiceFile(url) { }); }); } +// 获取音频 通用参数 +export function downloadVoiceParams(url) { + const token = getToken(); + const header = { + "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + }; + if (token) + header['summary'] = token + let baseUrl = get_base_url(url); + return { + url: `${baseUrl}${url}`, + header, + timeout: 180000, + } +} export function getAudioByText(data) { diff --git a/src/pages/course/components/talkingItem.vue b/src/pages/course/components/talkingItem.vue index 37adea31..2c029db7 100644 --- a/src/pages/course/components/talkingItem.vue +++ b/src/pages/course/components/talkingItem.vue @@ -220,6 +220,7 @@ import VideoPreview from '@/components/image-preview/video-preview.vue'; import { downloadVoiceFile, + downloadVoiceParams, uploadVoiceFile, getAudioByText } from '@/api/common.js'; @@ -439,16 +440,22 @@ // pauseVoice(); console.log('onUnload') talkVoiceObj.value?.destroy() + if(downloadFnc.value) downloadFnc.value?.abord() + downloadFnc.value = null }); onHide(() => { console.log('onHide') voiceLoading.value = false; + if(downloadFnc.value) downloadFnc.value?.abord() + downloadFnc.value = null }); let prevTime = -1; let pauseTime = -1; const startPlay = ref(false) + const voiceIsPlaying = ref(false) talkVoiceObj.value.onEnded(() => { console.log('onEnded'); + voiceIsPlaying.value = false if(props.activeVoiceId){ emit('changePlay', ''); } @@ -459,6 +466,7 @@ talkVoiceObj.value.onStop(() => { console.log('onStop'); voiceLoading.value = false; + voiceIsPlaying.value = false if(props.activeVoiceId){ emit('changePlay', ''); } @@ -467,19 +475,23 @@ talkVoiceObj.value.src = ''; }); talkVoiceObj.value.onPause(() => { + voiceIsPlaying.value = false voiceLoading.value = false; prevTime = talkVoiceObj.value.currentTime; pauseTime = prevTime + if(downloadFnc.value) downloadFnc.value?.abord() + downloadFnc.value = null }); talkVoiceObj.value.onPlay(() => { console.log('onPlay'); prevTime = talkVoiceObj.value.currentTime; pauseTime = prevTime startPlay.value = true + voiceIsPlaying.value = true setTimeout(()=> { startPlay.value= false },300) - // emit('changePlay', unref(dataInfo)?.id); + emit('changePlay', unref(dataInfo)?.id); }); talkVoiceObj.value.onTimeUpdate(() => { @@ -526,6 +538,7 @@ playVoice(); } }; + const downloadFnc = ref(null) const playVoice = (readType = 'pgth') => { let _content = showContent.value; if (!_content) { @@ -597,8 +610,10 @@ talkVoiceObj.value.play(); } else { storageStore.setGettingVoiceId(unref(dataInfo)?.id); - downloadVoiceFile(_url) - .then((res) => { + let _paramsObj = downloadVoiceParams(_url) + downloadFnc.value = uni.downloadFile({ + ..._paramsObj, + success(res) { if (res?.data) { common.msg(res.data.message); return; @@ -611,10 +626,31 @@ talkVoiceObj.value.play(); storageStore.setStorage('audio', _url + _params.teachNo, itemVoice.value); } - }) - .catch((err) => { + }, + complete() { voiceLoading.value = false; - }); + downloadFnc.value = null + }, + }); + // downloadVoiceFile(_url) + // .then((res) => { + // if (res?.data) { + // common.msg(res.data.message); + // return; + // } + // voiceLoading.value = false; + // if() + // itemVoice.value = res.tempFilePath; + // talkVoiceObj.value.src = res.tempFilePath; + // // 判斷是否在當前頁面 + // if(unref(isGettingId) === unref(dataInfo)?.id){ + // talkVoiceObj.value.play(); + // storageStore.setStorage('audio', _url + _params.teachNo, itemVoice.value); + // } + // }) + // .catch((err) => { + // voiceLoading.value = false; + // }); } });