Merge branch 'develop' into 'sit'

Develop

See merge request K17_AITS/tra-app!42
This commit is contained in:
田岩
2025-07-18 16:45:36 +08:00
9 changed files with 117 additions and 76 deletions
+1
View File
@@ -35,6 +35,7 @@ export default class WebSocketUtil {
*/
init(flag = false) {
if(flag) this.reconnectCount = 0
this.isClose = false; // 手动关闭
// 创建WebSocket连接
this.socketTask = uni.connectSocket({
url: this.url,
@@ -156,7 +156,7 @@
position: absolute;
left: 50%;
top: 50%;
max-width: 100%;
width: 100vw;
max-height: 100%;
transform: translate(-50%, -50%);
}
@@ -104,8 +104,8 @@
transform: translate(-50%, -50%);
}
.overlay-box .video-cont-center{
max-width: 100%;
max-height: 80%;
width: 100vw;
max-height: 100%;
position: absolute;
top: 50%;
left: 50%;
+6 -15
View File
@@ -367,13 +367,17 @@ const audioCacheObj = computed(() => storageStore.audioObj)
},100)
}else{
voiceLoading.value = true
let _type = props.type == 2 ? 'ans' : props.type == 3 ? 'pgrh' : props.type == 4 ? 'qns' : ''
let _readId = props.type == 2 ? unref(dataInfo)?.intrctId : props.type == 3 ? unref(dataInfo)?.pgrphId : props.type == 4 ? unref(dataInfo)?.qnsId : ''
console.log(unref(dataInfo))
let _params = {
crsId: unref(dataInfo)?.crsId || '',
pgrphId: unref(dataInfo)?.pgrphId || '',
qnsId: unref(dataInfo)?.qnsId || '',
readType: readType,
readType: _type,// 2 文本回答 3, 段落信息 4 问题信息
teachNo: unref(teacherInfo)?.teacherNo, // 必填
content: _content
readId: _readId
// content: _content
}
@@ -388,19 +392,6 @@ const audioCacheObj = computed(() => storageStore.audioObj)
talkVoiceObj.value.src = url
talkVoiceObj.value.play()
}else{
// getAudioByText(_params).then(res=>{
// // uni.env.USER_DATA_PATH ||
// let filePath = `${'/'}/${dataInfo.value.id}.mp3`
// saveFile(res, filePath, () => {
// voiceLoading.value = false
// itemVoice.value = filePath
// talkVoiceObj.value.src = filePath
// talkVoiceObj.value.play()
// storageStore.setStorage('audio', _url + _params.teachNo, itemVoice.value)
// })
// }).catch(err=>{
// console.log(err)
// })
downloadVoiceFile(_url).then(res=>{
if(res?.data){
common.msg(res.data.message)
+69 -46
View File
@@ -61,12 +61,23 @@ const props = defineProps({
default: false,
type: Boolean
},
canAnswer:{
default: true,
type: Boolean
},
canAnswerText:{
default: '当前状态不能发送内容!',
type: String
},
})
const { isDisabled, onlyVoice } = toRefs(props)
const isLoadingState = computed(() => props.isLoading)
watch(()=>props.isLoading,()=>{},{
deep:true,immediate:true
})
watch(()=>props.canAnswer,()=>{},{
deep:true,immediate:true
})
watch(()=>props.onlyVoice,()=>{},{
deep:true,immediate:true
})
@@ -87,11 +98,32 @@ const initRecord = () => {
// stopRecord()
unref(recordObjCom)?.onStop((res, duration)=>{
audioPath.value = res.tempFilePath
showTalkingModel.value = false
if(startFlag.value !== 2){
common.msg('说话时间太短,没有听清!')
return
}
if(!isOut.value){
emit('uploadVoice', audioPath.value)
}
})
unref(recordObjCom).onStart(() => {
startFlag.value = 1
setTimeout(()=>{
startFlag.value = 2
},1000)
let _recordPerm = uni.getAppAuthorizeSetting()
let _state = _recordPerm.microphoneAuthorized
if(_state === 'authorized'){
showTalkingModel.value = true
}
})
}
const startFlag = ref(1)
const startRecord = () => {
unref(recordObjCom).start({format:'mp3'})
}
const stopRecord = () => {
if(unref(recordObjCom).stop){
unref(recordObjCom)?.stop?.()
@@ -120,18 +152,21 @@ onMounted(async ()=>{
})
}
}else{
// let _recordPerm = permission.judgeIosPermission('record')
// if(!_recordPerm){
// common.show('提示信息', '当前页面需要使用的录音权限,是否前往开启?',true, '取消','确定').then((res) => {
// if(res) {
// // 去开启权限
// permission.gotoAppPermissionSetting()
// }else{
// // 取消
// common.navigateBack()
// }
// })
// }
let _recordPerm = uni.getAppAuthorizeSetting()
let _state = _recordPerm.microphoneAuthorized
if(_state === 'denied'){
common.show('提示信息', '当前页面需要使用的录音权限,是否前往开启?',true, '取消','确定').then((res) => {
if(res) {
// 去开启权限
uni.openAppAuthorizeSetting()
}else{
// 取消
common.navigateBack()
}
})
}else if(_state === 'not determined'){
// startRecord()
}
}
// #endif
})
@@ -154,21 +189,10 @@ const outScreen = computed(()=>{
const recNum = ref(1)
const activeNum = ref(1)
const getRecordPermission = async (obj) => {
//#ifdef APP-PLUS
// 安卓端
// let _recordPerm = await permission.requestAndroidPermission('android.permission.RECORD_AUDIO')
// if(_recordPerm !== 1){
// permission.gotoAppPermissionSetting()
// return
// }
showOverlayTalking(obj)
// #endif
//#ifndef APP-PLUS
// pc端
showOverlayTalking(obj)
// #endif
const getRecordPermission = (obj) => {
showOverlayTalking(obj)
}
const isMoving = ref(false)
const showOverlayTalking = (obj) => {
if(isLoadingState.value){
uni.showToast({
@@ -178,10 +202,18 @@ const showOverlayTalking = (obj) => {
})
return
}
if(!props.canAnswer){
uni.showToast({
title: props.canAnswerText,
icon: "none",
duration:1000
})
return
}
isMoving.value = true
emit('startRecord')
recNum.value += 1
if(!isDisabled.value){
showTalkingModel.value = true
touchX.value = obj.changedTouches[0].pageX
touchY.value = obj.changedTouches[0].pageY
baseY.value = obj.currentTarget.offsetTop
@@ -201,29 +233,20 @@ const showOverlayTalking = (obj) => {
}
}
const hideOverlayTalking = (obj) => {
isMoving.value = false
if(!showTalkingModel.value) return
if(activeNum.value + 1 === recNum.value){
showTalkingModel.value = false
//#ifdef APP-PLUS
stopRecord()
// #endif
if(!isOut.value){
setTimeout(()=>{
emit('uploadVoice', audioPath.value)
},1000)
}
}else{
showTalkingModel.value = false
common.msg('录音失败,请重试!')
}
activeNum.value = recNum.value
//#ifdef APP-PLUS
stopRecord()
// #endif
}
const handleMove = (obj) => {
touchX.value = obj.changedTouches[0].pageX
touchY.value = obj.changedTouches[0].pageY
if(outScreen.value){
hideOverlayTalking(obj)
if(isMoving.value){
touchX.value = obj.changedTouches[0].pageX
touchY.value = obj.changedTouches[0].pageY
if(outScreen.value){
hideOverlayTalking(obj)
}
}
}
// 发送文本
+2
View File
@@ -85,6 +85,8 @@
@startRecord="changePlayItemId('')"
:isLoading="isUploadingVoice"
:onlyVoice="answerOnlyVoice"
:canAnswer="testAnswer"
:canAnswerText="'每个问题最多连续发送五次答案!'"
:isDisabled="((lastTalkingInfo.type||0) !== 4)"
/>
</view>
+27 -11
View File
@@ -1,6 +1,6 @@
<template>
<view class="talking-info" v-if="dataInfo.intrctWay === '02'">
<view :class="['talking-gif', !voiceLoading ? 'is-play' : '']">
<view :class="['talking-gif', !voiceLoading&&(props.activeVoiceId === dataInfo.id) ? 'is-play' : '']">
<CommonLoading color="#fff" v-show="voiceLoading"/>
</view>
<view class="right-time">{{voiceTime}}</view>
@@ -45,7 +45,7 @@
</template>
<script setup>
import { computed, unref, ref, toRefs, watch, onMounted } from "vue"
import { computed, unref, ref, toRefs, watch, onMounted } from "vue"
import { onUnload } from '@dcloudio/uni-app';
const props = defineProps({
dataInfo: {
@@ -63,6 +63,7 @@ import { onUnload } from '@dcloudio/uni-app';
// 声音播放初始化
const talkVoiceObj = ref(null)
const isPlaying = ref(false)
const voiceLoading = ref(false)
const translateLoading = ref(false)
@@ -77,27 +78,39 @@ import { onUnload } from '@dcloudio/uni-app';
onUnload(()=>{
pauseVoice()
})
watch(() => props.dataInfo.talkingVoice,(val)=>{
if(val){
initVoice()
}
},{
deep: true,
immediate: true
})
const pauseVoice = () => {
if(!talkVoiceObj.value) return
talkVoiceObj.value.pause()
isPlaying.value = false
emit('changePlay', '')
}
const playVoice = () =>{
emit('changePlay', unref(dataInfo)?.id)
if(talkVoiceObj.value.src && talkVoiceObj.value.src === itemVoice.value) {
if(talkVoiceObj.value && talkVoiceObj.value.src && talkVoiceObj.value.src === itemVoice.value) {
talkVoiceObj.value.play()
return
}
talkVoiceObj.value.src = ''
if(itemVoice.value){
setTimeout(()=>{
talkVoiceObj.value.src = itemVoice.value
talkVoiceObj.value.play()
},100)
}else{
initVoice()
talkVoiceObj.value.src = ''
if(unref(dataInfo).talkingVoice){
setTimeout(()=>{
talkVoiceObj.value.src = unref(dataInfo).talkingVoice
talkVoiceObj.value.play()
isPlaying.value = true
},100)
}
}
}
const initVoice = () => {
if(unref(dataInfo).talkingVoice){
if(unref(dataInfo).intrctWay === '02'){
talkVoiceObj.value = uni.createInnerAudioContext()
talkVoiceObj.value.onEnded(()=>{
emit('changePlay', '')
@@ -158,6 +171,9 @@ import { onUnload } from '@dcloudio/uni-app';
height: 38rpx;
line-height: 38rpx;
}
&.talking-info-loading{
padding-bottom: 20rpx;
}
&.talking-info-text{
padding-bottom: 20rpx;
width: auto;
@@ -4,6 +4,7 @@
v-if="talkingType === 'question'"
@changePlay="changePlay"
:dataInfo="talkingInfo"
:activeVoiceId="activeVoiceId"
></questionVue>
<answerVue
v-else-if="talkingType === 'answer'"
@@ -28,6 +29,10 @@
talkingInfo:{
default: () => ({}),
type: Object
},
activeVoiceId:{
default:'',
type: String
}
})
watch(() => props.talkingInfo, () => {},{deep: true,immediate: true})
+4 -1
View File
@@ -50,6 +50,7 @@
v-for="item in talkingList"
:talkingType="item.type"
:talkingInfo="item"
:activeVoiceId="activeVoiceTalkingItemId"
@handleEvents="talkItemEvents"
>
</TalkingItem>
@@ -139,7 +140,7 @@ import {
},time)
})
}
const activeVoiceTalkingItemId = ref('')
// ws 初始化逻辑
const reconnectTimer = null // 重连timer
const isManualClose = ref(false) // 是否手动关闭
@@ -246,6 +247,7 @@ import {
if(commond === 'ASK-ERR'){
console.log('提问失败,系统异常!')
console.log('body')
return
}
}else{
@@ -313,6 +315,7 @@ import {
break;
case 'changePlay':
console.log('播放/暂停')
activeVoiceTalkingItemId.value = id
break;
default:
break;