fix: bug
This commit is contained in:
@@ -1,18 +1,18 @@
|
||||
<template>
|
||||
<view class="talk-btns" ref="talkBtnRef">
|
||||
<view class="touch-btn" v-if="!isGettingPermission" @touchstart="getRecordPermission" @touchend="hideOverlayTalking" @touchmove="handleMove">
|
||||
<view class="touch-btn" @touchstart="getRecordPermission" @touchend="hideOverlayTalking" @touchmove="handleMove">
|
||||
<view class="center-text">
|
||||
<image class="type-icon" src="@/static/images/sparring/talk-icon.png"></image>
|
||||
{{'语音对话'}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="touch-btn" v-else @click="stopRecord()">
|
||||
<!-- <view class="touch-btn" v-else @click="stopRecord()">
|
||||
<view class="center-text">
|
||||
<image class="type-icon" src="@/static/images/sparring/talk-icon.png"></image>
|
||||
{{'语音对话'}}
|
||||
</view>
|
||||
</view>
|
||||
<uni-popup ref="talkModelRef" type="bottom" @click="hideOverlayTalking"
|
||||
</view> -->
|
||||
<uni-popup ref="talkModelRef" type="bottom" @click="hideOverlayTalking" @touchend="hideOverlayTalking"
|
||||
mask-background-color="rgba(0,0,0,0.9)">
|
||||
<view class="overlay-box">
|
||||
<view class="circle-bg-box">
|
||||
@@ -60,7 +60,7 @@
|
||||
onHide,
|
||||
onShow
|
||||
} from '@dcloudio/uni-app';
|
||||
|
||||
|
||||
const storageStore = useStorageStore();
|
||||
const proxy = getCurrentInstance();
|
||||
const emit = defineEmits(['uploadVoice', 'startRecord']);
|
||||
@@ -134,13 +134,16 @@
|
||||
recordObjCom.value = uni.getRecorderManager();
|
||||
unref(recordObjCom)?.onStop((res, duration) => {
|
||||
isRecording.value = false
|
||||
if(isGettingPermission.value){
|
||||
isGettingPermission.value = false
|
||||
console.log(15)
|
||||
if (isGettingPermission.value) {
|
||||
isGettingPermission.value = false
|
||||
console.log(16)
|
||||
closeModel();
|
||||
return
|
||||
}
|
||||
audioPath.value = res.tempFilePath;
|
||||
if (!isOut.value) {
|
||||
console.log(17)
|
||||
if (startFlag.value !== 2) {
|
||||
closeModel(() => {
|
||||
nextTick(() => {
|
||||
@@ -148,17 +151,19 @@
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log(18)
|
||||
closeModel();
|
||||
emit('uploadVoice', audioPath.value, recordTime.value);
|
||||
}
|
||||
} else {
|
||||
console.log(19)
|
||||
closeModel();
|
||||
}
|
||||
});
|
||||
unref(recordObjCom).onStart(() => {
|
||||
isRecording.value = true
|
||||
recordTime.value = 0
|
||||
if(isGettingPermission.value){
|
||||
if (isGettingPermission.value) {
|
||||
stopRecord();
|
||||
return
|
||||
}
|
||||
@@ -175,26 +180,27 @@
|
||||
});
|
||||
unref(recordObjCom).onError(() => {
|
||||
isRecording.value = false
|
||||
if(isGettingPermission.value){
|
||||
isGettingPermission.value = false
|
||||
isGettingPermission.value = false
|
||||
if (showTalkingModel.value) {
|
||||
closeModel();
|
||||
}
|
||||
common.msg('语音输入错误,请重试!')
|
||||
});
|
||||
};
|
||||
const setRecordTime = () => {
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
recordTime.value += 1
|
||||
if(isRecording.value){
|
||||
if (isRecording.value) {
|
||||
setRecordTime()
|
||||
}
|
||||
},1000)
|
||||
}, 1000)
|
||||
}
|
||||
const isRecording = ref(false)
|
||||
const recordTime = ref(0)
|
||||
const startFlag = ref(1);
|
||||
const startRecord = () => {
|
||||
isStartNum.value += 1;
|
||||
console.log(8, '开始录音前')
|
||||
unref(recordObjCom).start({
|
||||
format: formatType.value
|
||||
});
|
||||
@@ -204,20 +210,25 @@
|
||||
isStopNum.value = isStartNum.value;
|
||||
try {
|
||||
if (isRecording.value && unref(recordObjCom).stop) {
|
||||
setTimeout(()=>{
|
||||
setTimeout(() => {
|
||||
isGettingPermission.value = false
|
||||
}, 1000)
|
||||
console.log(10, '验证停止方法存在')
|
||||
closeModel();
|
||||
unref(recordObjCom).stop();
|
||||
} else {
|
||||
console.log(11, '验证停止方法不存在')
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
}
|
||||
} catch {
|
||||
console.log(12, '验证错误')
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
}
|
||||
};
|
||||
const closeModel = (cb = () => {}) => {
|
||||
console.log(99, '关闭弹窗')
|
||||
isStopNum.value = isStartNum.value;
|
||||
setTimeout(() => {
|
||||
isTalking.value = false;
|
||||
@@ -264,18 +275,20 @@
|
||||
}, 500);
|
||||
return;
|
||||
}
|
||||
console.log(1, '开始执行获取权限')
|
||||
// #ifdef APP-PLUS
|
||||
if (!hasPermission.value) {
|
||||
let _res = await getPermission()
|
||||
console.log(2, '取到权限结果:', _res)
|
||||
if (_res) {
|
||||
hasPermission.value = true
|
||||
setTimeout(()=>{
|
||||
if(!isGettingPermission.value){
|
||||
setTimeout(() => {
|
||||
if (!isGettingPermission.value) {
|
||||
showOverlayTalking(obj);
|
||||
}else{
|
||||
} else {
|
||||
isGettingPermission.value = false
|
||||
}
|
||||
},100)
|
||||
}, 100)
|
||||
}
|
||||
} else {
|
||||
showOverlayTalking(obj);
|
||||
@@ -331,15 +344,22 @@
|
||||
const isMoving = ref(false);
|
||||
const isTalking = ref(false);
|
||||
const showOverlayTalking = (obj) => {
|
||||
if (showTalkingModel.value) return;
|
||||
console.log(3, '权限验证通过,展示录音弹窗')
|
||||
if (showTalkingModel.value) {
|
||||
console.log(4, '默认展开状态关闭,return')
|
||||
showTalkingModel.value = false
|
||||
return
|
||||
};
|
||||
if (isGettingPermission.value) {
|
||||
if(isRecording.value){
|
||||
console.log(5, 'onhide状态触发')
|
||||
if (isRecording.value) {
|
||||
stopRecord()
|
||||
}else{
|
||||
} else {
|
||||
isGettingPermission.value = false
|
||||
}
|
||||
return
|
||||
}
|
||||
console.log(6, '未触发 hide导致的事件')
|
||||
if (isLoadingState.value) {
|
||||
uni.showToast({
|
||||
title: props.loadingText,
|
||||
@@ -354,6 +374,7 @@
|
||||
recNum.value += 1;
|
||||
let _recnum = recNum.value
|
||||
if (!isDisabled.value) {
|
||||
console.log(7, '开始录音')
|
||||
touchX.value = obj.changedTouches[0].pageX;
|
||||
touchY.value = obj.changedTouches[0].pageY;
|
||||
baseY.value = obj.currentTarget.offsetTop;
|
||||
@@ -377,8 +398,9 @@
|
||||
};
|
||||
const hideOverlayTalking = (obj) => {
|
||||
isMoving.value = false;
|
||||
if (!showTalkingModel.value) return;
|
||||
// if (!showTalkingModel.value) return;
|
||||
//#ifdef APP-PLUS
|
||||
console.log(9, '关闭录音窗口')
|
||||
stopRecord();
|
||||
// #endif
|
||||
};
|
||||
@@ -392,13 +414,13 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
onShow(()=>{
|
||||
onShow(() => {
|
||||
// stopRecord()
|
||||
// if(isGettingPermission.value){
|
||||
// hideOverlayTalking()
|
||||
// }
|
||||
})
|
||||
onHide(()=>{
|
||||
onHide(() => {
|
||||
isGettingPermission.value = true
|
||||
})
|
||||
</script>
|
||||
@@ -448,12 +470,14 @@
|
||||
// justify-content: flex-end;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
|
||||
.circle-bg-box {
|
||||
height: 234rpx;
|
||||
background: url(@/static/images/course/talking.png) no-repeat;
|
||||
background-size: cover;
|
||||
position: relative;
|
||||
pointer-events: none;
|
||||
|
||||
.icon-box {
|
||||
position: absolute;
|
||||
@@ -463,10 +487,12 @@
|
||||
margin-top: -24rpx;
|
||||
width: 34rpx;
|
||||
height: 48rpx;
|
||||
pointer-events: none;
|
||||
|
||||
image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,6 +503,7 @@
|
||||
color: #c0c0c0;
|
||||
text-align: center;
|
||||
margin: 12rpx 0 24rpx;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.btns-box {
|
||||
@@ -488,6 +515,7 @@
|
||||
font-size: 28rpx;
|
||||
text-align: center;
|
||||
line-height: 116rpx;
|
||||
pointer-events: none;
|
||||
|
||||
.close-btn {
|
||||
float: left;
|
||||
@@ -495,9 +523,11 @@
|
||||
width: 154rpx;
|
||||
overflow: hidden;
|
||||
color: #999;
|
||||
pointer-events: none;
|
||||
|
||||
&.is-out {
|
||||
color: #fff;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,11 +537,13 @@
|
||||
width: 154rpx;
|
||||
overflow: hidden;
|
||||
color: #999;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.btn-box {
|
||||
width: 100%;
|
||||
height: 154rpx;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,6 +554,7 @@
|
||||
background-color: #06f;
|
||||
border-radius: 32rpx;
|
||||
position: relative;
|
||||
pointer-events: none;
|
||||
|
||||
&.is-out {
|
||||
background-color: #ff3e49;
|
||||
@@ -538,6 +571,7 @@
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&::after {
|
||||
@@ -551,33 +585,7 @@
|
||||
bottom: -22rpx;
|
||||
left: 50%;
|
||||
margin-left: -22rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.white-bg-box {
|
||||
height: 365rpx;
|
||||
background-color: #fff;
|
||||
overflow: hidden;
|
||||
border-radius: 32rpx 32rpx 0 0;
|
||||
padding: 58rpx 36rpx;
|
||||
|
||||
.box-title {
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
line-height: 46rpx;
|
||||
margin-bottom: 46rpx;
|
||||
}
|
||||
|
||||
.box-btns {
|
||||
height: 46rpx;
|
||||
line-height: 46rpx;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
color: #999;
|
||||
|
||||
.is-active {
|
||||
color: #06f;
|
||||
}
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
<template>
|
||||
<view class="talk-btns" ref="talkBtnRef">
|
||||
<view class="touch-btn" v-if="!isGettingPermission" @touchstart="getRecordPermission" @touchend="hideOverlayTalking" @touchmove="handleMove">
|
||||
<view class="center-text">
|
||||
<image class="type-icon" src="@/static/images/sparring/talk-icon.png"></image>
|
||||
{{'语音对话'}}
|
||||
</view>
|
||||
</view>
|
||||
<view class="touch-btn" v-else @click="isGettingPermission = false">
|
||||
<view class="touch-btn" @touchstart="getRecordPermission" @touchend="hideOverlayTalking" @touchmove="handleMove">
|
||||
<view class="center-text">
|
||||
<image class="type-icon" src="@/static/images/sparring/talk-icon.png"></image>
|
||||
{{'语音对话'}}
|
||||
@@ -135,8 +129,7 @@
|
||||
unref(recordObjCom)?.onStop((res, duration) => {
|
||||
isRecording.value = false
|
||||
if(isGettingPermission.value){
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
isGettingPermission.value = false
|
||||
return
|
||||
}
|
||||
audioPath.value = res.tempFilePath;
|
||||
@@ -199,17 +192,12 @@
|
||||
const stopRecord = () => {
|
||||
isStopNum.value = isStartNum.value;
|
||||
try {
|
||||
if (isRecording.value && unref(recordObjCom).stop) {
|
||||
setTimeout(()=>{
|
||||
isGettingPermission.value = false
|
||||
}, 1000)
|
||||
if (unref(recordObjCom).stop) {
|
||||
unref(recordObjCom).stop();
|
||||
} else {
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
}
|
||||
} catch {
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
}
|
||||
};
|
||||
@@ -314,8 +302,10 @@
|
||||
return false
|
||||
} else if (_state === 'not determined') {
|
||||
// startRecord()
|
||||
// isGettingPermission.value = false
|
||||
return true
|
||||
} else {
|
||||
// isGettingPermission.value = false
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -329,11 +319,8 @@
|
||||
const showOverlayTalking = (obj) => {
|
||||
if (showTalkingModel.value) return;
|
||||
if (isGettingPermission.value) {
|
||||
if(isRecording.value){
|
||||
stopRecord()
|
||||
}else{
|
||||
isGettingPermission.value = false
|
||||
}
|
||||
stopRecord()
|
||||
isGettingPermission.value = false
|
||||
return
|
||||
}
|
||||
if (isLoadingState.value) {
|
||||
@@ -358,6 +345,7 @@
|
||||
startRecord();
|
||||
// #endif
|
||||
setTimeout(() => {
|
||||
console.log(_recnum, recNum.value)
|
||||
if (_recnum === recNum.value) {
|
||||
hideOverlayTalking(recNum.value);
|
||||
}
|
||||
@@ -395,6 +383,7 @@
|
||||
// }
|
||||
})
|
||||
onHide(()=>{
|
||||
console.log('onHide')
|
||||
isGettingPermission.value = true
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user