新增文件缓存路径store,优先判断缓存

This commit is contained in:
yanghang
2025-07-03 10:51:14 +08:00
parent 98fb45e7da
commit b2b730ceef
6 changed files with 83 additions and 20 deletions
+8 -3
View File
@@ -60,9 +60,14 @@ export default class WebSocketUtil {
// 监听WebSocket消息接收事件
this.socketTask.onMessage((res) => {
console.log('收到WebSocket消息', res);
const { rtnCode } = JSON.parse(res.data)
if(['0005', 'QQ0005'].includes(res.rtnCode)) {
if(res.data){
const { rtnCode } = JSON.parse(res.data)
console.log('收到WebSocket消息', JSON.parse(res.data) );
if(['0005', 'QQ0005'].includes(res.rtnCode)) {
goto_login_fun();
return
}
}else{
goto_login_fun();
return
}
+25 -4
View File
@@ -4,7 +4,10 @@
<script>
import {previewFile, previewCacheThumbImage} from'@/api/common.js'
import {get_base_url} from '@/api/request.js'
import { get_base_url } from '@/api/request.js'
import { useStorageStore } from "@/store/storage.js"
// const storageStore = useStorageStore()
export default {
name:"image-preview",
props:{
@@ -36,6 +39,12 @@
base_url: get_base_url()
};
},
computed:{
storageStore:() => useStorageStore(),
imageObj() {
return this.storageStore?.imgObj||{}
}
},
watch: {
imgId: {
handler(newval, oldval) {
@@ -58,15 +67,26 @@
},
methods: {
getPreviewUrlBlob(id) {
if (id === null) {
console.log('谢谢谢谢谢谢', id);
if (!id) {
this.imgUrlShow = ''
return
}
if(this.isCache){
let _cache = this.imageObj[`/${id}/${this.width}/${this.height}`] || ''
if(_cache){
this.imgUrlShow = _cache;
return
}
previewCacheThumbImage(id, this.width,this.height).then((res) => {
this.imgUrlShow = res;
this.storageStore.setStorage('image', `/${id}/${this.width}/${this.height}`, res)
});
}else{
let _cache = this.imageObj[`${id}`] || ''
if(_cache){
this.imgUrlShow = _cache;
return
}
previewFile(id).then((result) => {
//#ifdef APP-PLUS
let _header = result.header['Content-Type'].split(';')[0]
@@ -76,6 +96,7 @@
// #endif
let base64 = `data:${_header};base64,` + uni.arrayBufferToBase64(result.data)
this.imgUrlShow = base64;
this.storageStore.setStorage('image', id, base64)
});
}
},
+24 -7
View File
@@ -1,27 +1,34 @@
<template>
<view class="video-view-box">
<video class="video-cont" v-if="imgUrlShow" :src="imgUrlShow" controls></video>
<video class="video-cont" v-if="fileUrlShow" :src="fileUrlShow" controls></video>
</view>
</template>
<script>
import { downloadFile } from'@/api/common.js'
import { useStorageStore } from "@/store/storage.js"
export default {
name:"video-preview",
props:{
imgId:{
fileId:{
default:'',
type:String
}
},
data() {
return {
imgUrlShow:'',
fileUrlShow:'',
watching:false
};
},
computed:{
storageStore:() => useStorageStore(),
videoObj() {
return this.storageStore?.videoObj||{}
}
},
watch: {
imgId: {
fileId: {
handler(newval, oldval) {
if (newval && this.watching) {
this.getPreviewUrlBlob(newval);
@@ -33,14 +40,24 @@
},
methods: {
getPreviewUrlBlob(id) {
if (!id) {
this.fileUrlShow = ''
return
}
let _cache = this.videoObj[id] || ''
if(_cache){
this.fileUrlShow = _cache;
return
}
downloadFile(id).then(res=>{
this.imgUrlShow = res.tempFilePath
this.fileUrlShow = res.tempFilePath
this.storageStore.setStorage('video', id, this.fileUrlShow)
})
},
},
mounted() {
if (this.imgId) {
this.getPreviewUrlBlob(this.imgId);
if (this.fileId) {
this.getPreviewUrlBlob(this.fileId);
}
this.watching = true
},
@@ -139,6 +139,10 @@ import { studyParagraphOverApi } from "@/api/study.js"
import ChartFour from "./chartFour.vue"
import ChartThree from "./chartThree.vue"
import { getUserInfo } from '@/common/common';
import { useStorageStore } from "@/store/storage.js"
const storageStore = useStorageStore()
const audioCacheObj = computed(() => storageStore.audioObj)
const props = defineProps({
type:{
@@ -236,11 +240,21 @@ import { getUserInfo } from '@/common/common';
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
})
+12 -1
View File
@@ -159,10 +159,13 @@ import TalkingItem from '@/pages/course/components/talkingItem.vue'
import ImagePreview from '@/components/image-preview/image-preview.vue'
import { useSocketStore } from "@/store/socket.js"
import { useStorageStore } from "@/store/storage.js"
import { storeToRefs } from 'pinia'
const socketStore = useSocketStore()
const storageStore = useStorageStore()
const { SocketObj } = storeToRefs(socketStore)
const audioCacheObj = computed(() => storageStore.audioObj)
const { proxy } = getCurrentInstance()
const crsNum = ref('');
@@ -248,6 +251,7 @@ const choiceTeacherInfo = computed(()=>{
const activeVoiceTeachNo = ref('')
const teacherVoiceObj = uni.createInnerAudioContext()
teacherVoiceObj.onEnded(()=>{
activeVoiceTeachNo.value = ''
teacherVoiceObj.src = ''
@@ -262,10 +266,17 @@ 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)
})
}
}
@@ -523,7 +534,6 @@ const hideOverlayTalking = (obj) => {
// #endif
//#ifdef APP-PLUS
commonUploadVoiceFile(audioPath.value, '/trastudy/traStdyInfo/studyAnswerVoiceUp', _data).then(res=>{
console.log(res.data)
let _res = JSON.parse(res.data)
if(_res.rtnCode === '0000'){
let _id = new Date().getTime() + 'id'
@@ -635,6 +645,7 @@ const chooseRate = ref('1.0')
const chooseRateNow = (item) => {
chooseRate.value = item
showSeekModel.value = false
teacherVoiceObj.playbackRate = Number(item)
}
</script>
-5
View File
@@ -18,11 +18,6 @@ export const useSocketStore = defineStore('socketStore',{
let _baseUrl = get_base_url().split('http').join('ws')
if(this.SocketObj && this.SocketObj?.close) return
this.SocketObj = new SocketClass(_baseUrl + '/trastudy/trasoket/open?summary=' + getToken());
this.SocketObj.on('close', () => {
setTimeout(()=>{
this.SocketObj = null
},100)
})
},
closeSocket() {
if(!(this.SocketObj && this.SocketObj?.close)) return