fix ;bug
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
})
|
||||
@@ -88,12 +99,19 @@ const initRecord = () => {
|
||||
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(() => {
|
||||
console.log('开始录音了');
|
||||
startFlag.value = 1
|
||||
setTimeout(()=>{
|
||||
startFlag.value = 2
|
||||
},1000)
|
||||
let _recordPerm = uni.getAppAuthorizeSetting()
|
||||
let _state = _recordPerm.microphoneAuthorized
|
||||
if(_state === 'authorized'){
|
||||
@@ -101,6 +119,7 @@ const initRecord = () => {
|
||||
}
|
||||
})
|
||||
}
|
||||
const startFlag = ref(1)
|
||||
const startRecord = () => {
|
||||
unref(recordObjCom).start({format:'mp3'})
|
||||
}
|
||||
@@ -139,10 +158,7 @@ onMounted(async ()=>{
|
||||
common.show('提示信息', '当前页面需要使用的录音权限,是否前往开启?',true, '取消','确定').then((res) => {
|
||||
if(res) {
|
||||
// 去开启权限
|
||||
permission.gotoAppPermissionSetting()
|
||||
uni.openAppAuthorizeSetting({
|
||||
|
||||
})
|
||||
uni.openAppAuthorizeSetting()
|
||||
}else{
|
||||
// 取消
|
||||
common.navigateBack()
|
||||
@@ -173,22 +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({
|
||||
@@ -198,6 +202,15 @@ 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){
|
||||
@@ -220,6 +233,7 @@ const showOverlayTalking = (obj) => {
|
||||
}
|
||||
}
|
||||
const hideOverlayTalking = (obj) => {
|
||||
isMoving.value = false
|
||||
if(!showTalkingModel.value) return
|
||||
//#ifdef APP-PLUS
|
||||
stopRecord()
|
||||
@@ -227,10 +241,12 @@ const hideOverlayTalking = (obj) => {
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 发送文本
|
||||
|
||||
@@ -85,6 +85,8 @@
|
||||
@startRecord="changePlayItemId('')"
|
||||
:isLoading="isUploadingVoice"
|
||||
:onlyVoice="answerOnlyVoice"
|
||||
:canAnswer="testAnswer"
|
||||
:canAnswerText="'每个问题最多连续发送五次答案!'"
|
||||
:isDisabled="((lastTalkingInfo.type||0) !== 4)"
|
||||
/>
|
||||
</view>
|
||||
|
||||
@@ -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: {
|
||||
@@ -77,6 +77,14 @@ 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()
|
||||
@@ -84,20 +92,22 @@ import { onUnload } from '@dcloudio/uni-app';
|
||||
}
|
||||
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(itemVoice.value){
|
||||
setTimeout(()=>{
|
||||
talkVoiceObj.value.src = itemVoice.value
|
||||
talkVoiceObj.value.play()
|
||||
},100)
|
||||
}
|
||||
}
|
||||
}
|
||||
const initVoice = () => {
|
||||
if(unref(dataInfo).talkingVoice){
|
||||
if(unref(dataInfo).intrctWay === '02'){
|
||||
talkVoiceObj.value = uni.createInnerAudioContext()
|
||||
talkVoiceObj.value.onEnded(()=>{
|
||||
emit('changePlay', '')
|
||||
@@ -158,6 +168,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;
|
||||
|
||||
Reference in New Issue
Block a user