fix: 打包错误信息处理

This commit is contained in:
yanghang
2025-07-01 14:42:57 +08:00
parent ad2a9449bd
commit 1d1288539e
6 changed files with 113 additions and 62 deletions
+21 -2
View File
@@ -79,7 +79,17 @@ export const commonUploadVoiceFile = (file, url, data = {}, fileKey='voice') =>
name: fileKey,
formData: data,
success(result) {
resolve(result)
try {
const res = JSON.parse(result.data);
console.log(res)
if (res.rtnCode === '0000') {
resolve(result);
} else {
reject(new Error(res.message));
}
} catch (error) {
reject(new Error('Failed to parse response'));
}
},
fail(error) {
reject(new Error('Upload failed'));
@@ -104,7 +114,16 @@ export const uploadVoiceFile = (file) => {
filePath: file,
name: 'voice',
success(result) {
resolve(result)
try {
const res = JSON.parse(result.data);
if (res.rtnCode === '0000') {
resolve(result);
} else {
reject(new Error(res.message));
}
} catch (error) {
reject(new Error('Failed to parse response'));
}
},
fail(error) {
reject(new Error('Upload failed'));
+1 -1
View File
@@ -1,6 +1,6 @@
import App from './App'
import { createSSRApp } from 'vue'
import pinia from './store'
import pinia from './store/index.js'
export function createApp() {
const app = createSSRApp(App)
+45 -33
View File
@@ -85,7 +85,7 @@
</view> -->
<view class="play-btn">
<image class="icon"
@click="playQnsVoice('qns', item)"
@click="playQnsVoice('qns', dataInfo)"
v-show="props.activeVoiceId !== dataInfo.id"
src="@/static/images/course/play-blue.png"
style="width: 100%;height: 100%;"
@@ -97,9 +97,9 @@
style="width: 100%;height: 100%;"
></image>
</view>
<view class="icon text-btn" v-if="type === 1" @click="translateVoice(item)"></view>
<view class="icon text-right-btn" @click="translateVoice(item)">完成</view>
<view class="icon text-right-btn" @click="translateVoice(item)">撤回</view>
<view class="icon text-btn" v-if="type === 1" @click="translateVoice(dataInfo)"></view>
<view class="icon text-right-btn" @click="translateVoice(dataInfo)" v-if="isLast">完成</view>
<view class="icon text-right-btn" @click="translateVoice(dataInfo)">撤回</view>
</view>
</view>
</view>
@@ -123,10 +123,10 @@
</template>
<script setup>
import { watch, unref, ref, toRefs, computed } from 'vue'
import { watch, unref, ref, toRefs, computed, nextTick } from 'vue'
import ImagePreview from '@/components/image-preview/image-preview.vue'
import VideoPreview from '@/components/image-preview/video-preview.vue'
import { downloadVoiceFile } from "@/api/common.js"
import { downloadVoiceFile, uploadVoiceFile, } from "@/api/common.js"
import { studyParagraphOverApi } from "@/api/study.js"
import ChartFour from "./chartFour.vue"
import ChartThree from "./chartThree.vue"
@@ -144,48 +144,60 @@ import { getUserInfo } from '@/common/common';
activeVoiceId:{
default:'',
type: String
},
isLast:{
default:false,
type: Boolean
}
})
const { type, dataInfo, activeVoiceId } = toRefs(props)
const emit = defineEmits(['changePlay', 'nextQuestion'])
// 声音播放初始化
const talkVoiceObj = uni.createInnerAudioContext()
const talkVoiceObj = ref(uni.createInnerAudioContext())
const userInfo = computed(() => getUserInfo())
watch(() => props.activeVoiceId,(val) => {
if(val && (val !== unref(dataInfo).id)){
talkVoiceObj?.stop()
talkVoiceObj.value?.stop()
}
},{
deep: true,
immediate: true
})
talkVoiceObj.onEnded(()=>{
emit('changePlay',unref(dataInfo)?.id)
talkVoiceObj.value.onEnded(()=>{
emit('changePlay', '')
talkVoiceObj.value.src = ''
})
talkVoiceObj.onError(()=>{
emit('changePlay',unref(dataInfo)?.id)
talkVoiceObj.value.onError(()=>{
emit('changePlay', '')
talkVoiceObj.value.src = ''
})
const pauseVoice = () => {
if(!talkVoiceObj) return
talkVoiceObj.pause()
emit('changePlay',unref(dataInfo)?.id)
if(!talkVoiceObj.value) return
talkVoiceObj.value.pause()
emit('changePlay', '')
}
// 重播
const restartPlay = () => {
if(talkVoiceObj.src){
talkVoiceObj.seek(0)
talkVoiceObj.play()
emit('changePlay', unref(dataInfo)?.id)
if(itemVoice.value){
setTimeout(()=>{
talkVoiceObj.value.src = itemVoice.value
talkVoiceObj.value.play()
},100)
}else{
playVoice()
}
}
const itemVoice = ref('')
const playVoice = (readType = 'pgth') =>{
// readType 阅读内容类型pgrh段落/qns问题
emit('changePlay', unref(dataInfo)?.id)
if(talkVoiceObj.src){
talkVoiceObj.play()
if(itemVoice.value){
setTimeout(()=>{
talkVoiceObj.value.src = itemVoice.value
talkVoiceObj.value.play()
},100)
}else{
let _params = {
crsId: unref(dataInfo)?.crsId || '',
@@ -193,34 +205,34 @@ import { getUserInfo } from '@/common/common';
qnsId: unref(dataInfo)?.qnsId || '',
readType: readType,
teachNo: unref(dataInfo)?.userInfo?.teacherNo, // 必填
content: unref(dataInfo)?.pgrphContent || unref(dataInfo)?.talkingContent,
content: unref(dataInfo)?.pgrphContent || unref(dataInfo)?.qnsContent || unref(dataInfo)?.talkingContent,
}
let _url = '/trastudy/traStdyInfo/readContent?' + Object.keys(_params).map(t=>{
return encodeURIComponent(t) + '=' + encodeURIComponent(_params[t])
}).join('&')
downloadVoiceFile(_url).then(res=>{
talkVoiceObj.src = res.tempFilePath
talkVoiceObj.play()
itemVoice.value = res.tempFilePath
talkVoiceObj.value.src = res.tempFilePath
talkVoiceObj.value.play()
})
}
}
const playQnsVoice = (readType = 'qns', item) =>{
console.log(unref(dataInfo))
if(type.value === 2){
//
// 文本转语
playVoice(readType)
return
}
// readType 阅读内容类型pgrh段落/qns问题
emit('changePlay', unref(dataInfo)?.id)
if(talkVoiceObj.src){
talkVoiceObj.play()
}else{
talkVoiceObj.src = item.talkingVoice
talkVoiceObj.play()
}
setTimeout(()=>{
itemVoice.value = item.talkingVoice
talkVoiceObj.value.src = item.talkingVoice
talkVoiceObj.value.play()
},100)
}
const translateVoice = (item) =>{
if(!item.talkingVoice) return
uploadVoiceFile(item.talkingVoice,{}).then(res=>{
let _data = JSON.parse(res.data)
item.talkingContent = _data.body
@@ -451,7 +463,7 @@ import { getUserInfo } from '@/common/common';
background-size: 100%;
margin-bottom: 16rpx;
&.is-play{
background: url(@/static/images/course/voice-gif.gif) no-repeat;
background: url(@/static/images/course/voice-white.gif) no-repeat;
background-size: 100%;
}
}
+42 -22
View File
@@ -33,26 +33,30 @@
</view>
</view>
<view class="course-study-body" v-show="step === 2" @click="playRecord">
<view class="body-title">
<view class="body-title" @click="scrollToBottomNow">
<uv-icon class="arrow-icon" name="arrow-left" @click="common.navigateBack()"/>
课程学习
</view>
<view class="talking-list" id="scroll-box" ref="scrollBoxRef">
<scroll-view class="talking-list" :scroll-y="true">
<!-- <view class="talking-list-cont" id="scroll-box" ref="scrollBoxRef"> -->
<view class="study-num">
<view class="color-blue">{{ showOrder }}</view> / {{ pgrphNum }}
</view>
<TalkingItem
class="talking-item"
v-for="item in talkingList"
v-for="item,index in talkingList"
:key="'item' + item.id"
:type="item.type"
:dataInfo="item"
:activeVoiceId="activeVoiceTalkingItemId"
@changePlay="changePlayItemId"
@nextQuestion="nextQuestionSuccess"
:id="'item' + item.id"
:isLast="talkingList.length === (index+1)"
></TalkingItem>
<!-- <video v-if="videoUrlShow" :src="videoUrlShow" controls></video> -->
</view>
<!-- </view> -->
</scroll-view>
<view class="talk-btns">
<view
class="touch-btn"
@@ -348,21 +352,24 @@ const nextQuestionSuccess = (info) => {
}
const scrollBoxRef = ref()
const scrollToBottomNow = () => {
setTimeout(() => {
// let scrollElem = scrollBoxRef.value.$el
let scrollElem = document.getElementById('scroll-box')
scrollElem.scrollTo({
top: scrollElem.scrollHeight, behavior: 'smooth'
})
// let _arr = talkingList.value || []
// if(_arr.length && _arr.length > 0){
// let _last = talkingList.value[talkingList.value.length - 1]
// uni.pageScrollTo({
// selector: '#item' + _last.id,
// duration: 300
// })
// }
},200)
nextTick(()=>{
setTimeout(() => {
// let scrollElem = scrollBoxRef.value.$el
// // let scrollElem = document.getElementById('scroll-box')
// scrollElem.scrollTo({
// top: scrollElem.scrollHeight, behavior: 'smooth'
// })
let _arr = talkingList.value || []
if(_arr.length && _arr.length > 0){
let _last = talkingList.value[talkingList.value.length - 1]
console.log('#item' + _last.id)
uni.pageScrollTo({
selector: '#item' + _last.id,
duration: 300
})
}
},200)
})
}
const reconnectTimer = null // 重连timer
@@ -427,7 +434,7 @@ const startRecord = () => {
unref(recordObj).start({format:'mp3'})
}
const stopRecord = () => {
unref(recordObj).stop()
unref(recordObj)?.stop?.()
}
// #endif
//#ifndef APP-PLUS
@@ -446,7 +453,7 @@ onShow(()=>{
// teacherVoiceObj.src = ''
// })
onUnmounted(()=>{
teacherVoiceObj.stop()
teacherVoiceObj?.stop?.()
teacherVoiceObj.src = ''
})
const playRecord = () => {
@@ -481,7 +488,7 @@ const hideOverlayTalking = (obj) => {
stopRecord()
// #endif
if(!isOut.value){
// audioPath.value /traStdyInfo/studyAnswerVoiceUp
console.log(11111111111111)
setTimeout(()=>{
let _data = {
qnsId: unref(lastTalkingInfo).qnsId,// 问题ID 必输项:true 类型:String
@@ -505,7 +512,9 @@ const hideOverlayTalking = (obj) => {
})
// #endif
//#ifdef APP-PLUS
console.log(222)
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'
@@ -521,6 +530,12 @@ const hideOverlayTalking = (obj) => {
})
scrollToBottomNow()
}
}).catch(err=>{
uni.showToast({
title: err||'系统异常,请联系管理员',
icon: "none",
duration:1000
});
})
// #endif
},1000)
@@ -585,6 +600,11 @@ const handleMove = (obj) => {
background: url(@/static/images/course/study-bg.png) no-repeat;
background-size: cover;
border-radius: 30rpx 30rpx 0 0;
box-sizing: border-box;
width: 100%;
.talking-list-cont{
padding: 0;
}
.study-num{
height: 36rpx;
line-height: 36rpx;
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

+4 -4
View File
@@ -19,11 +19,11 @@ export const useSocketStore = defineStore('socketStore',{
if(this.SocketObj && this.SocketObj?.close) return
this.SocketObj = new SocketClass(_baseUrl + '/trastudy/trasoket/open?summary=' + getToken());
},
closeSocket: () => {
if(!this.SocketObj || !this.SocketObj?.close) return
this.SocketObj && this.SocketObj?.close?.()
closeSocket() {
if(!(this.SocketObj && this.SocketObj?.close)) return
this.SocketObj && this.SocketObj.close()
},
setOnmessageCb: (cb) => {
setOnmessageCb(cb){
if(!this.SocketObj || !this.SocketObj?.on) return
this.SocketObj.on('message', cb)
}