文件缓存处理
This commit is contained in:
@@ -138,6 +138,7 @@ import { downloadVoiceFile, uploadVoiceFile, } from "@/api/common.js"
|
||||
import { studyParagraphOverApi } from "@/api/study.js"
|
||||
import ChartFour from "./chartFour.vue"
|
||||
import ChartThree from "./chartThree.vue"
|
||||
import common from '@/common/common';
|
||||
import { getUserInfo } from '@/common/common';
|
||||
import { useStorageStore } from "@/store/storage.js"
|
||||
|
||||
@@ -220,6 +221,11 @@ const audioCacheObj = computed(() => storageStore.audioObj)
|
||||
}
|
||||
const itemVoice = ref('')
|
||||
const playVoice = (readType = 'pgth') =>{
|
||||
let _content = unref(dataInfo)?.pgrphContent || unref(dataInfo)?.qnsContent || unref(dataInfo)?.talkingContent || ''
|
||||
if(!_content){
|
||||
common.msg('没有可以播放的文字信息!')
|
||||
return
|
||||
}
|
||||
// readType 阅读内容类型pgrh段落/qns问题
|
||||
emit('changePlay', unref(dataInfo)?.id)
|
||||
if(itemVoice.value){
|
||||
@@ -235,29 +241,52 @@ const audioCacheObj = computed(() => storageStore.audioObj)
|
||||
qnsId: unref(dataInfo)?.qnsId || '',
|
||||
readType: readType,
|
||||
teachNo: unref(dataInfo)?.userInfo?.teacherNo, // 必填
|
||||
content: unref(dataInfo)?.pgrphContent || unref(dataInfo)?.qnsContent || unref(dataInfo)?.talkingContent,
|
||||
content: _content
|
||||
}
|
||||
let _url = '/trastudy/traStdyInfo/readContent?' + Object.keys(_params).map(t=>{
|
||||
return encodeURIComponent(t) + '=' + encodeURIComponent(_params[t])
|
||||
}).join('&')
|
||||
|
||||
let _cache = audioCacheObj.value[_url]
|
||||
if(_cache){
|
||||
voiceLoading.value = false
|
||||
itemVoice.value = _cache
|
||||
talkVoiceObj.value.src = _cache
|
||||
talkVoiceObj.value.play()
|
||||
return
|
||||
}
|
||||
downloadVoiceFile(_url).then(res=>{
|
||||
voiceLoading.value = false
|
||||
itemVoice.value = res.tempFilePath
|
||||
talkVoiceObj.value.src = res.tempFilePath
|
||||
talkVoiceObj.value.play()
|
||||
storageStore.setStorage('audio', _url, itemVoice.value)
|
||||
}).catch((err)=>{
|
||||
voiceLoading.value = false
|
||||
storageStore.getStorageById('audio', _url, (url)=>{
|
||||
if(url){
|
||||
voiceLoading.value = false
|
||||
itemVoice.value = url
|
||||
talkVoiceObj.value.src = url
|
||||
talkVoiceObj.value.play()
|
||||
}else{
|
||||
downloadVoiceFile(_url).then(res=>{
|
||||
console.log(res)
|
||||
if(res?.data){
|
||||
common.msg(res.data.message)
|
||||
return
|
||||
}
|
||||
voiceLoading.value = false
|
||||
itemVoice.value = res.tempFilePath
|
||||
talkVoiceObj.value.src = res.tempFilePath
|
||||
talkVoiceObj.value.play()
|
||||
storageStore.setStorage('audio', _url, itemVoice.value)
|
||||
}).catch((err)=>{
|
||||
voiceLoading.value = false
|
||||
})
|
||||
}
|
||||
})
|
||||
// let _cache = audioCacheObj.value[_url]
|
||||
// if(_cache){
|
||||
// voiceLoading.value = false
|
||||
// itemVoice.value = _cache
|
||||
// talkVoiceObj.value.src = _cache
|
||||
// talkVoiceObj.value.play()
|
||||
// return
|
||||
// }
|
||||
// downloadVoiceFile(_url).then(res=>{
|
||||
// voiceLoading.value = false
|
||||
// itemVoice.value = res.tempFilePath
|
||||
// talkVoiceObj.value.src = res.tempFilePath
|
||||
// talkVoiceObj.value.play()
|
||||
// storageStore.setStorage('audio', _url, itemVoice.value)
|
||||
// }).catch((err)=>{
|
||||
// voiceLoading.value = false
|
||||
// })
|
||||
}
|
||||
}
|
||||
const playQnsVoice = (readType = 'qns', item) =>{
|
||||
|
||||
+12
-11
@@ -266,17 +266,18 @@ const playTeacherVoice = (item) =>{
|
||||
teacherVoiceObj.src = item.voicePath
|
||||
teacherVoiceObj.play()
|
||||
}else{
|
||||
let _cache = audioCacheObj.value[item.teacherNo]
|
||||
if(_cache){
|
||||
teacherVoiceObj.src = _cache
|
||||
teacherVoiceObj.play()
|
||||
return
|
||||
}
|
||||
downloadVoiceFile('/trastudy/traStdyInfo/trialListening?teachNo='+item.teacherNo).then(res=>{
|
||||
item.voicePath = res.tempFilePath
|
||||
teacherVoiceObj.src = item.voicePath
|
||||
teacherVoiceObj.play()
|
||||
storageStore.setStorage('audio', id, item.voicePath)
|
||||
storageStore.getStorageById('audio', item.teacherNo, (url)=>{
|
||||
if(url){
|
||||
teacherVoiceObj.src = _cache
|
||||
teacherVoiceObj.play()
|
||||
}else{
|
||||
downloadVoiceFile('/trastudy/traStdyInfo/trialListening?teachNo='+item.teacherNo).then(res=>{
|
||||
item.voicePath = res.tempFilePath
|
||||
teacherVoiceObj.src = item.voicePath
|
||||
teacherVoiceObj.play()
|
||||
storageStore.setStorage('audio', item.teacherNo, item.voicePath)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user