JLBA202505130001_关于吉林银行新建AI智能培训系统的需求_fix: 录音按钮问题处理
This commit is contained in:
@@ -177,7 +177,7 @@
|
||||
stopRecord();
|
||||
} else {
|
||||
setRecordTime()
|
||||
if(!showTalkingModel.value){
|
||||
if (!showTalkingModel.value) {
|
||||
showTalkingModel.value = true;
|
||||
}
|
||||
}
|
||||
@@ -212,33 +212,49 @@
|
||||
};
|
||||
|
||||
const stopRecord = () => {
|
||||
isStopNum.value = isStartNum.value;
|
||||
try {
|
||||
if (isRecording.value && unref(recordObjCom).stop) {
|
||||
setTimeout(() => {
|
||||
isGettingPermission.value = false
|
||||
}, 1000)
|
||||
console.log(10, '验证停止方法存在')
|
||||
if (isRecording.value) {
|
||||
isStopNum.value = isStartNum.value;
|
||||
try {
|
||||
if (isRecording.value && unref(recordObjCom).stop) {
|
||||
setTimeout(() => {
|
||||
isGettingPermission.value = false
|
||||
}, 1000)
|
||||
console.log(10, '验证停止方法存在')
|
||||
// closeModel();
|
||||
unref(recordObjCom).stop();
|
||||
} else {
|
||||
console.log(11, '验证停止方法不存在')
|
||||
unref(recordObjCom).stop();
|
||||
setTimeout(() => {
|
||||
closeModel()
|
||||
}, 300)
|
||||
} else {
|
||||
console.log(11, '验证停止方法不存在')
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
}
|
||||
} catch {
|
||||
console.log(12, '验证错误')
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
closeModel();
|
||||
}
|
||||
} catch {
|
||||
console.log(12, '验证错误')
|
||||
isGettingPermission.value = false
|
||||
} else {
|
||||
console.log(88, '松开太快')
|
||||
setTimeout(() => {
|
||||
if (showTalkingModel.value) {
|
||||
stopRecord()
|
||||
} else {
|
||||
closeModel();
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
};
|
||||
const closeModel = (cb = () => {}) => {
|
||||
console.log(99, '关闭弹窗')
|
||||
if (isHandleClosed.value) return
|
||||
isStopNum.value = isStartNum.value;
|
||||
isHandleClosed.value = true
|
||||
setTimeout(() => {
|
||||
if(showTalkingModel.value){
|
||||
if (showTalkingModel.value) {
|
||||
showTalkingModel.value = false;
|
||||
// isTalking.value = false;
|
||||
}
|
||||
cb && cb();
|
||||
}, 300);
|
||||
@@ -251,8 +267,8 @@
|
||||
//#ifndef APP-PLUS
|
||||
const recordObjCom = ref({});
|
||||
const initRecord = () => {
|
||||
|
||||
// talkModelRef.value.open()
|
||||
|
||||
// talkModelRef.value.open()
|
||||
};
|
||||
// #endif
|
||||
onMounted(async () => {
|
||||
@@ -279,6 +295,7 @@
|
||||
const hasPermission = ref(false)
|
||||
|
||||
const getRecordPermission = async (obj) => {
|
||||
showTalkingModel.value = false
|
||||
if (isDisabled.value) return;
|
||||
if (isTalking.value) {
|
||||
common.msg('操作频繁,请稍后重试!');
|
||||
@@ -312,7 +329,7 @@
|
||||
if (IsAndEnv) {
|
||||
let _recordPerm = await permission.requestAndroidPermission('android.permission.RECORD_AUDIO');
|
||||
if (_recordPerm !== 1) {
|
||||
if(showTalkingModel.value){
|
||||
if (showTalkingModel.value) {
|
||||
showTalkingModel.value = false;
|
||||
}
|
||||
let res = await common.show('提示信息', '当前页面需要使用的录音权限,是否前往开启?', true, '取消', '确定')
|
||||
@@ -360,9 +377,7 @@
|
||||
console.log(3, '权限验证通过,展示录音弹窗')
|
||||
if (showTalkingModel.value) {
|
||||
console.log(4, '默认展开状态关闭,return')
|
||||
if(showTalkingModel.value){
|
||||
showTalkingModel.value = false;
|
||||
}
|
||||
showTalkingModel.value = false;
|
||||
return
|
||||
};
|
||||
if (isGettingPermission.value) {
|
||||
@@ -402,7 +417,7 @@
|
||||
}
|
||||
}, 59 * 1010);
|
||||
} else {
|
||||
if(showTalkingModel.value){
|
||||
if (showTalkingModel.value) {
|
||||
showTalkingModel.value = false;
|
||||
}
|
||||
uni.showToast({
|
||||
@@ -536,6 +551,7 @@
|
||||
line-height: 116rpx;
|
||||
pointer-events: none;
|
||||
display: flex;
|
||||
|
||||
.close-btn {
|
||||
padding-top: 40rpx;
|
||||
line-height: 28rpx;
|
||||
@@ -614,6 +630,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep .uv-input__content__field-wrapper__field {
|
||||
padding-right: 60rpx;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
{{'语音对话'}}
|
||||
</view>
|
||||
</view>
|
||||
<uni-popup ref="talkModelRef" type="bottom" @click="hideOverlayTalking"
|
||||
mask-background-color="rgba(0,0,0,0.9)">
|
||||
<!-- <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" mask-background-color="rgba(0,0,0,0.9)">
|
||||
<view class="overlay-box">
|
||||
<view class="circle-bg-box">
|
||||
<view class="icon-box">
|
||||
@@ -17,9 +22,9 @@
|
||||
<view class="tips-box">松开发送</view>
|
||||
<view class="btns-box">
|
||||
<view :class="['close-btn', isOut ? 'is-out' : '']">
|
||||
取消
|
||||
<image class="btn-box" v-if="!isOut" src="/src/static/images/course/close.png" mode=""></image>
|
||||
<image class="btn-box" v-else src="/src/static/images/course/close-active.png" mode=""></image>
|
||||
<text>取消</text>
|
||||
<image class="btn-box" v-if="!isOut" src="/src/static/images/course/close.png" mode="heightFix"></image>
|
||||
<image class="btn-box" v-else src="/src/static/images/course/close-active.png" mode="heightFix"></image>
|
||||
</view>
|
||||
</view>
|
||||
<view :class="['talk-dialog', isOut ? 'is-out' : '']">
|
||||
@@ -54,7 +59,7 @@
|
||||
onHide,
|
||||
onShow
|
||||
} from '@dcloudio/uni-app';
|
||||
|
||||
|
||||
const storageStore = useStorageStore();
|
||||
const proxy = getCurrentInstance();
|
||||
const emit = defineEmits(['uploadVoice', 'startRecord']);
|
||||
@@ -124,16 +129,21 @@
|
||||
const isStartNum = ref(0);
|
||||
const isStopNum = ref(0);
|
||||
const isGettingPermission = ref(false)
|
||||
const isHandleClosed = ref(false)
|
||||
const initRecord = () => {
|
||||
recordObjCom.value = uni.getRecorderManager();
|
||||
unref(recordObjCom)?.onStop((res, duration) => {
|
||||
isRecording.value = false
|
||||
if(isGettingPermission.value){
|
||||
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(() => {
|
||||
@@ -141,18 +151,21 @@
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log(18)
|
||||
closeModel();
|
||||
emit('uploadVoice', audioPath.value, recordTime.value);
|
||||
let _time = Math.ceil(recordTime.value)
|
||||
emit('uploadVoice', audioPath.value, _time);
|
||||
recordTime.value = 0
|
||||
}
|
||||
} else {
|
||||
console.log(19)
|
||||
closeModel();
|
||||
}
|
||||
});
|
||||
unref(recordObjCom).onStart(() => {
|
||||
isRecording.value = true
|
||||
recordTime.value = 0
|
||||
setRecordTime()
|
||||
if(isGettingPermission.value){
|
||||
if (isGettingPermission.value) {
|
||||
stopRecord();
|
||||
return
|
||||
}
|
||||
@@ -160,61 +173,87 @@
|
||||
setTimeout(() => {
|
||||
startFlag.value = 2;
|
||||
}, 1000);
|
||||
let _recordPerm = uni.getAppAuthorizeSetting();
|
||||
let _state = _recordPerm.microphoneAuthorized;
|
||||
if (_state === 'authorized') {
|
||||
if (isStopNum.value === isStartNum.value) {
|
||||
stopRecord();
|
||||
} else {
|
||||
if ((isStopNum.value === isStartNum.value) || isHandleClosed.value) {
|
||||
stopRecord();
|
||||
} else {
|
||||
setRecordTime()
|
||||
if(!showTalkingModel.value){
|
||||
showTalkingModel.value = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
unref(recordObjCom).onError(() => {
|
||||
isRecording.value = false
|
||||
isGettingPermission.value = false
|
||||
if (showTalkingModel.value) {
|
||||
closeModel();
|
||||
}
|
||||
common.msg('语音输入错误,请重试!')
|
||||
});
|
||||
};
|
||||
const setRecordTime = () => {
|
||||
setTimeout(()=>{
|
||||
if(isRecording.value){
|
||||
recordTime.value += 1
|
||||
setTimeout(() => {
|
||||
recordTime.value += 0.2
|
||||
if (isRecording.value) {
|
||||
setRecordTime()
|
||||
}
|
||||
},1000)
|
||||
}, 200)
|
||||
}
|
||||
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
|
||||
});
|
||||
// showTalkingModel.value = true;
|
||||
};
|
||||
|
||||
const stopRecord = () => {
|
||||
isStopNum.value = isStartNum.value;
|
||||
try {
|
||||
if (unref(recordObjCom).stop) {
|
||||
if (isRecording.value && unref(recordObjCom).stop) {
|
||||
setTimeout(() => {
|
||||
isGettingPermission.value = false
|
||||
}, 1000)
|
||||
console.log(10, '验证停止方法存在')
|
||||
// closeModel();
|
||||
unref(recordObjCom).stop();
|
||||
} else {
|
||||
closeModel();
|
||||
console.log(11, '验证停止方法不存在')
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
}
|
||||
} catch {
|
||||
closeModel();
|
||||
console.log(12, '验证错误')
|
||||
isGettingPermission.value = false
|
||||
closeModel();
|
||||
}
|
||||
};
|
||||
const closeModel = (cb = () => {}) => {
|
||||
console.log(99, '关闭弹窗')
|
||||
isStopNum.value = isStartNum.value;
|
||||
isHandleClosed.value = true
|
||||
setTimeout(() => {
|
||||
showTalkingModel.value = false;
|
||||
if(showTalkingModel.value){
|
||||
showTalkingModel.value = false;
|
||||
}
|
||||
cb && cb();
|
||||
}, 350);
|
||||
}, 300);
|
||||
setTimeout(() => {
|
||||
isTalking.value = false;
|
||||
}, 800);
|
||||
isHandleClosed.value = false
|
||||
}, 1000);
|
||||
};
|
||||
// #endif
|
||||
//#ifndef APP-PLUS
|
||||
const recordObjCom = ref({});
|
||||
const initRecord = () => {};
|
||||
const initRecord = () => {
|
||||
|
||||
// talkModelRef.value.open()
|
||||
};
|
||||
// #endif
|
||||
onMounted(async () => {
|
||||
initRecord?.();
|
||||
@@ -248,18 +287,19 @@
|
||||
}, 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);
|
||||
@@ -272,7 +312,9 @@
|
||||
if (IsAndEnv) {
|
||||
let _recordPerm = await permission.requestAndroidPermission('android.permission.RECORD_AUDIO');
|
||||
if (_recordPerm !== 1) {
|
||||
showTalkingModel.value = false;
|
||||
if(showTalkingModel.value){
|
||||
showTalkingModel.value = false;
|
||||
}
|
||||
let res = await common.show('提示信息', '当前页面需要使用的录音权限,是否前往开启?', true, '取消', '确定')
|
||||
if (res) {
|
||||
// 去开启权限
|
||||
@@ -284,6 +326,7 @@
|
||||
return false
|
||||
} else {
|
||||
// isGettingPermission.value = false
|
||||
hasPermission.value = true
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
@@ -301,11 +344,8 @@
|
||||
});
|
||||
return false
|
||||
} else if (_state === 'not determined') {
|
||||
// startRecord()
|
||||
// isGettingPermission.value = false
|
||||
return true
|
||||
} else {
|
||||
// isGettingPermission.value = false
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -317,12 +357,24 @@
|
||||
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')
|
||||
if(showTalkingModel.value){
|
||||
showTalkingModel.value = false;
|
||||
}
|
||||
return
|
||||
};
|
||||
if (isGettingPermission.value) {
|
||||
stopRecord()
|
||||
isGettingPermission.value = false
|
||||
console.log(5, 'onhide状态触发')
|
||||
if (isRecording.value) {
|
||||
stopRecord()
|
||||
} else {
|
||||
isGettingPermission.value = false
|
||||
}
|
||||
return
|
||||
}
|
||||
console.log(6, '未触发 hide导致的事件')
|
||||
if (isLoadingState.value) {
|
||||
uni.showToast({
|
||||
title: props.loadingText,
|
||||
@@ -337,21 +389,22 @@
|
||||
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;
|
||||
//#ifdef APP-PLUS
|
||||
// canStart.value = false
|
||||
startRecord();
|
||||
// #endif
|
||||
setTimeout(() => {
|
||||
console.log(_recnum, recNum.value)
|
||||
if (_recnum === recNum.value) {
|
||||
hideOverlayTalking(recNum.value);
|
||||
}
|
||||
}, 59 * 1010);
|
||||
} else {
|
||||
showTalkingModel.value = false;
|
||||
if(showTalkingModel.value){
|
||||
showTalkingModel.value = false;
|
||||
}
|
||||
uni.showToast({
|
||||
title: '暂无问题需要回答!',
|
||||
icon: 'none',
|
||||
@@ -361,8 +414,9 @@
|
||||
};
|
||||
const hideOverlayTalking = (obj) => {
|
||||
isMoving.value = false;
|
||||
if (!showTalkingModel.value) return;
|
||||
// if (!showTalkingModel.value) return;
|
||||
//#ifdef APP-PLUS
|
||||
console.log(9, '关闭录音窗口')
|
||||
stopRecord();
|
||||
// #endif
|
||||
};
|
||||
@@ -376,14 +430,13 @@
|
||||
}
|
||||
}
|
||||
};
|
||||
onShow(()=>{
|
||||
onShow(() => {
|
||||
// stopRecord()
|
||||
// if(isGettingPermission.value){
|
||||
// hideOverlayTalking()
|
||||
// }
|
||||
})
|
||||
onHide(()=>{
|
||||
console.log('onHide')
|
||||
onHide(() => {
|
||||
isGettingPermission.value = true
|
||||
})
|
||||
</script>
|
||||
@@ -404,7 +457,6 @@
|
||||
background-color: #06f;
|
||||
font-weight: 400;
|
||||
position: relative;
|
||||
;
|
||||
color: #fff;
|
||||
font-size: 29rpx;
|
||||
border-radius: 23rpx;
|
||||
@@ -434,12 +486,16 @@
|
||||
// justify-content: flex-end;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
max-height: 100vh;
|
||||
justify-content: space-between;
|
||||
|
||||
.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;
|
||||
@@ -449,10 +505,12 @@
|
||||
margin-top: -24rpx;
|
||||
width: 34rpx;
|
||||
height: 48rpx;
|
||||
pointer-events: none;
|
||||
|
||||
image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -460,30 +518,40 @@
|
||||
.tips-box {
|
||||
height: 40rpx;
|
||||
line-height: 40rpx;
|
||||
font-size: 28rpx;
|
||||
color: #c0c0c0;
|
||||
text-align: center;
|
||||
margin: 12rpx 0 24rpx;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.btns-box {
|
||||
height: 270rpx;
|
||||
// padding: 0 120rpx;
|
||||
width: 154rpx;
|
||||
margin: 0 auto 100rpx;
|
||||
margin: 0 auto;
|
||||
overflow: hidden;
|
||||
font-size: 28rpx;
|
||||
text-align: center;
|
||||
line-height: 116rpx;
|
||||
|
||||
pointer-events: none;
|
||||
display: flex;
|
||||
.close-btn {
|
||||
padding-top: 40rpx;
|
||||
line-height: 28rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
float: left;
|
||||
height: 100%;
|
||||
width: 154rpx;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
color: #999;
|
||||
pointer-events: none;
|
||||
|
||||
&.is-out {
|
||||
color: #fff;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -493,11 +561,14 @@
|
||||
width: 154rpx;
|
||||
overflow: hidden;
|
||||
color: #999;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.btn-box {
|
||||
width: 100%;
|
||||
height: 154rpx;
|
||||
max-height: 152rpx;
|
||||
pointer-events: none;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,6 +579,7 @@
|
||||
background-color: #06f;
|
||||
border-radius: 32rpx;
|
||||
position: relative;
|
||||
pointer-events: none;
|
||||
|
||||
&.is-out {
|
||||
background-color: #ff3e49;
|
||||
@@ -524,6 +596,7 @@
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
&::after {
|
||||
@@ -537,37 +610,10 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
::v-deep .uv-input__content__field-wrapper__field {
|
||||
padding-right: 60rpx;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user