JLBA202505130001_关于吉林银行新建AI智能培训系统的需求_补充一个未提交的文件

This commit is contained in:
田岩
2026-03-04 14:27:49 +08:00
parent 0a688c8186
commit 44a88a55e6
7 changed files with 328 additions and 157 deletions
+3 -5
View File
@@ -4,15 +4,13 @@ ENV = 'development'
VITE_APP_BASE_API_Url = 'https://aits.jlbank.com.cn:7001'
#VITE_APP_BASE_API_Url = 'https://aits.jlbank.com.cn:7001'
#VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
# VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002'
# VITE_APP_BASE_API_Url = 'http://192.168.247.200'
# VITE_APP_BASE_API_Url = 'http://aitscdn.jlbank.com.cn:7001'
# VITE_APP_BASE_API_Url = 'http://192.168.108.129'
# dev
# DEV
+18 -2
View File
@@ -169,7 +169,7 @@
setTimeout(() => {
textShow.value = true;
textLoading.value = false;
}, 500);
}, 400);
} else {
textShow.value = false;
}
@@ -222,7 +222,7 @@
console.log('加载声音', props.dataInfo);
if (newVal === '' && props.dataInfo.ossKey) {
// 去下载oss内容
console.log('真下载oss内容');
console.log('真下载oss内容', props.dataInfo.ossKey);
downloadFile(props.dataInfo.ossKey).then((res) => {
voiceTime.value = '';
innerAudio.setAudioSrc(res.tempFilePath);
@@ -236,6 +236,22 @@
},
{ immediate: true }
);
watch(
() => props.dataInfo.ossKey,
(newVal) => {
if (props.dataInfo.voicePath === undefined && props.dataInfo.ossKey) {
console.log('真下载oss内容', props.dataInfo.ossKey);
downloadFile(props.dataInfo.ossKey).then((res) => {
voiceTime.value = '';
props.dataInfo.voicePath = res.tempFilePath;
innerAudio.setAudioSrc(res.tempFilePath);
});
} else if (newVal === undefined) {
innerAudio.stopAudio();
}
},
{ immediate: true }
);
});
onUnload(() => {
// 1. 停止当前播放(优先处理,避免音频继续播放)
@@ -61,6 +61,7 @@
.circle-bg-box {
animation: moveBottomOut 0.3s ease-out forwards;
}
}
// 仅语音
&.voice-only {
@@ -143,6 +144,10 @@
visibility: visible; // 激活后可见
animation: fadeIn 0.4s ease-out 0.1s forwards;
}
// 仅文字模式,隐藏发送原语音按钮
&.text-only>.trans-btn{
visibility: hidden;
}
.transVoiceIng {
width: 154rpx;
height: 154rpx;
+1 -1
View File
@@ -17,7 +17,7 @@ export const icKeyboardSvg = () : string => {
};
export const iconMicSvg = () : string => {
const svgXml = `
<svg t="1772357429950" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1775" width="200" height="200"><path d="M513.788813 938.289925c-113.566274 0-220.223734-44.167967-300.444149-124.388381-80.220415-80.220415-124.388382-186.877876-124.388382-300.44415s44.167967-220.227983 124.388382-300.448398c165.543834-165.548083 435.348714-165.548083 600.892548 0 165.548083 165.548083 165.548083 435.348714 0 600.892548-80.220415 80.220415-186.877876 124.388382-300.44415 124.388381z m0-785.973112c-92.538158 0-185.072066 35.453344-255.379651 105.756681-68.2001 68.204349-105.75668 158.63927-105.756681 255.3839s37.556581 187.175303 105.756681 255.379652c68.204349 68.2001 158.936697 106.054108 255.379651 105.75668 96.74888 0 187.179552-37.556581 255.379652-105.75668 140.912598-140.912598 140.912598-369.850954 0-510.759303-70.303336-70.307585-162.841494-105.75668-255.379652-105.756681z" fill="#515151" p-id="1776"></path><path d="M318.672199 341.705826h46.313693c11.047303 0 19.545228 8.497925 19.545228 19.120332v46.313693c0 10.622407-8.497925 19.120332-19.120332 19.120332h-46.738589c-10.622407 0.424896-19.120332-8.073029-19.120332-18.695436v-46.738589c0-10.622407 8.497925-19.120332 19.120332-19.120332zM488.630705 341.705826h46.313693c11.047303 0 19.545228 8.497925 19.545229 19.120332v46.313693c0 10.622407-8.497925 19.120332-19.120332 19.120332h-46.73859c-10.622407 0.424896-19.120332-8.073029-19.120332-18.695436v-46.738589c0-10.622407 8.497925-19.120332 19.120332-19.120332zM658.589212 341.705826h46.313693c11.047303 0 19.545228 8.497925 19.545228 19.120332v46.313693c0 10.622407-8.497925 19.120332-19.120332 19.120332h-46.738589c-10.622407 0.424896-19.120332-8.073029-19.120332-18.695436v-46.738589c0-10.622407 8.497925-19.120332 19.120332-19.120332zM318.672199 469.174705h46.313693c10.622407 0 19.120332 8.497925 19.120332 19.120332v46.313693c0 10.622407-8.497925 19.120332-19.120332 19.120332H318.672199c-10.622407 0.424896-19.120332-8.073029-19.120332-18.695435v-46.73859c0-10.622407 8.497925-19.120332 19.120332-19.120332zM488.630705 469.174705h46.313693c10.622407 0 19.120332 8.497925 19.120332 19.120332v46.313693c0 10.622407-8.497925 19.120332-19.120332 19.120332h-46.313693c-10.622407 0.424896-19.120332-8.073029-19.120332-18.695435v-46.73859c0-10.622407 8.497925-19.120332 19.120332-19.120332zM658.589212 469.174705h46.313693c10.622407 0 19.120332 8.497925 19.120332 19.120332v46.313693c0 10.622407-8.497925 19.120332-19.120332 19.120332h-46.313693c-10.622407 0.424896-19.120332-8.073029-19.120332-18.695435v-46.73859c0-10.622407 8.497925-19.120332 19.120332-19.120332zM458.887967 660.378025h106.224066c17.420747 0 31.86722 14.446473 31.86722 31.86722s-14.446473 31.86722-31.86722 31.86722h-106.224066c-17.420747 0-31.86722-14.446473-31.86722-31.86722s14.446473-31.86722 31.86722-31.86722z" fill="#515151" p-id="1777"></path></svg>
<svg t="1772603482440" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5657" width="256" height="256"><path d="M512 64c247.424 0 448 200.576 448 448S759.424 960 512 960 64 759.424 64 512 264.576 64 512 64z m0 68c-209.868 0-380 170.132-380 380s170.132 380 380 380 380-170.132 380-380-170.132-380-380-380z m52.766 130.24c12.33-12.32 32.298-12.32 44.625-0.005l0.018 0.019 4.026 4.133c131.545 137.211 131.4 354.035-0.317 491.07l-4.073 4.17-0.342 0.348c-5.74 5.758-13.6 9.025-21.802 9.025a30.85 30.85 0 0 1-22.19-9.419c-11.208-11.926-11.208-30.444-0.044-42.324l0.097-0.1 3.343-3.404c109.19-113.003 109.2-292.426 0.033-405.442l-3.376-3.438-0.365-0.372c-11.943-12.356-11.821-32.055 0.367-44.261z m-115.333 89.643c11.818-10.51 29.644-10.51 41.463-0.003l0.462 0.418 0.096 0.1 2.53 2.652c82.68 88.053 82.688 225.361 0.026 313.424l-2.672 2.799-0.124 0.11-0.358 0.316c-11.864 10.301-29.51 10.302-41.376 0.003l-0.533-0.472-0.157-0.171-0.325-0.36c-10.61-11.942-10.502-30.015 0.325-41.832l0.132-0.138 1.892-1.933c61.805-64.168 61.812-165.846 0.019-230.022l-1.998-2.04-0.083-0.092-0.318-0.361c-10.4-11.99-10.294-29.879 0.318-41.747l0.154-0.172 0.17-0.157z m-128.057 125.89c13.666-13.46 34.104-17.488 51.906-10.157C391.264 475.02 403 492.549 403 512c0 19.452-11.736 36.98-29.718 44.385a47.973 47.973 0 0 1-51.93-10.182l-0.413-0.412-0.425-0.427A47.64 47.64 0 0 1 306.889 512a47.658 47.658 0 0 1 13.675-33.413l0.4-0.403z" fill="#515151" p-id="5658"></path></svg>
`;
return `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgXml)}`;
};
+1 -1
View File
@@ -44,7 +44,7 @@ export type TouchBtnEmits = {
* @param voiceData - 语音相关数据(包含ossKey、识别文本等核心字段)
* @param duration - 录音时长(单位:毫秒),用于校验最短录音时长
*/
submitVoice: [params: { ossKey: string; text: string }];
submitVoice: [params: { ossKey: string; text: string, recordId:string }];
/**
* 提交文字答案(用户确认识别结果/手动编辑后触发)
* @param answerText - 最终提交的文字答案内容
+269 -144
View File
@@ -1,52 +1,84 @@
<template>
<view>
<view class="talk-btns-components" :class="{action:isRecording, inputMode:!isInputVisible}">
<view class="talk-btns-components" :class="{ action: isRecording, inputMode: !isInputVisible }">
<view class="touch-btn" @click="disabled_click">
<button v-if="!isTextOnlyMode && isInputVisible" class="voice-btn" @touchstart="startRecord"
@touchend="stopRecord()" @touchmove="handleMove" @touchcancel="stopRecord()" :plain="true">
<button
v-if="isInputVisible"
class="voice-btn"
@touchstart="startRecord"
@touchend="stopRecord()"
@touchmove="handleMove"
@touchcancel="stopRecord()"
:plain="true"
>
<text class="voice-text">{{ isRecording ? '松开发送' : '按住说话' }}</text>
</button>
<input v-if="!isVoiceOnlyMode && !isInputVisible" class="input-box" ref="inputRef" v-model="inputText"
:maxlength="props.maxlength" :adjustPosition="true"
placeholderStyle="color:#999999;font-size:26rpx" placeholder="请输入文字"
:disabled="props.isDisabled" @click="disabled_click"></input>
<input
v-if="!isVoiceOnlyMode && !isInputVisible"
class="input-box"
ref="inputRef"
v-model="inputText"
:maxlength="props.maxlength"
:adjustPosition="true"
placeholderStyle="color:#999999;font-size:26rpx"
placeholder="请输入文字"
:disabled="props.isDisabled"
@click="disabled_click"
/>
</view>
<view class="talk-right-icon-div" v-if="!isTextOnlyMode && !isVoiceOnlyMode">
<view class="talk-right-icon-div" v-if="!isVoiceOnlyMode">
<image class="talk-right-icon" :src="talkRightIcon" mode="widthFix" @click="changeBtn"></image>
</view>
</view>
<uni-popup ref="popupRef" class="popup" @touchmove.stop.prevent="false">
<view class="overlay-box" >
<view class="overlay-box">
<view class="fl1"></view>
<view class="talk-dialog-box">
<view class="talk-dialog-div" :class="dialogDynamicClasses">
<view class="talk-dialog" >
<image :src="voiceWhiteBtn" mode="" class="gif-box"></image>
<uv-textarea class="textarea" ref="inputRef" v-model="textAreaText" :maxlength="255" @click.stop
<view class="talk-dialog">
<image :src="TouchBtnImages.voiceWhiteBtn" mode="" class="gif-box"></image>
<uv-textarea
class="textarea"
ref="inputRef"
v-model="textAreaText"
:maxlength="255"
@click.stop
customStyle="background: #ffffff00; padding-bottom: 50rpx; color: #fff; caret-color: #fff"
text-style="color: #fff" border="none" placeholderStyle="color:#999999;font-size:26rpx;"
placeholder=""></uv-textarea>
text-style="color: #fff"
border="none"
placeholderStyle="color:#999999;font-size:26rpx;"
placeholder=""
></uv-textarea>
<view class="error-tip-div">
<image :src="iconRecognizeErrorSvg()" mode="aspectFill" class="img"></image>
<view class="">
未识别到文字
</view>
<image :src="TouchBtnImages.iconRecognizeErrorSvg()" mode="aspectFill" class="img"></image>
<view class="">未识别到文字</view>
</view>
</view>
</view>
</view>
<!-- 第一形态两侧按钮 -->
<view class="page-box" :style="{marginBottom:pageBoxMarginBottom}">
<view class="page-box" :style="{ marginBottom: pageBoxMarginBottom }">
<view class="page-1" :class="[status, props.mode]">
<view class="btns-box">
<!-- 左侧取消按钮 -->
<image class="btn-box btn-box-1" :src="isOutStatus == '02' ? cancelActiveBtn : cancelBtn"
mode="heightFix" @click="closePopup()"></image>
<image
class="btn-box btn-box-1"
:src="isOutStatus == '02' ? TouchBtnImages.cancelActiveBtn : TouchBtnImages.cancelBtn"
mode="heightFix"
@click="closePopup()"
></image>
<!-- 右侧转文字按钮 -->
<image class="btn-box btn-box-2" :src="isOutStatus == '03' ? translateActiveBtn : translateBtn"
mode="heightFix"></image>
<image class="btn-box-3" :src="isOutStatus == '02'? closeActiveBtn : closeBtn"
mode="heightFix" @click="closePopup()"></image>
<image
class="btn-box btn-box-2"
:src="isOutStatus == '03' ? TouchBtnImages.translateActiveBtn : TouchBtnImages.translateBtn"
mode="heightFix"
></image>
<image
class="btn-box-3"
:src="isOutStatus == '02' ? TouchBtnImages.closeActiveBtn : TouchBtnImages.closeBtn"
mode="heightFix"
@click="closePopup()"
></image>
</view>
<!-- 下方按钮 -->
<view class="circle-bg-box">
@@ -54,15 +86,19 @@
</view>
</view>
<!-- 第二形态 -->
<view class="page-2" :class="[ status, voice_to_text_status]" >
<view class="page-2" :class="[status, voice_to_text_status, props.mode]">
<!-- 左侧XX -->
<view class="transVoiceIng cancel-btn" @click="closePopup()"><text class="btn-text">取消</text></view>
<view class="transVoiceIng cancel-btn" @click="closePopup()">
<text class="btn-text">取消</text>
</view>
<!-- 中间发送原语音 -->
<view class="transVoiceIng trans-btn" @click="testFun()"><text class="btn-text">发送原语音</text></view>
<view class="transVoiceIng trans-btn" @click="testFun()">
<text class="btn-text">发送原语音</text>
</view>
<!-- 右侧发送按钮椭圆 -->
<view class="send-btn" @click="send_msg()">
<view class="send-btn-text">发送</view>
<CommonLoading class="send-btn-loading" color="#444"/>
<CommonLoading class="send-btn-loading" color="#444" />
</view>
</view>
</view>
@@ -72,16 +108,13 @@
</template>
<script setup lang="ts">
// 导出图片
import { cancelBtn, cancelActiveBtn, translateBtn, translateActiveBtn, voiceWhiteBtn,closeBtn,closeActiveBtn, icKeyboardSvg, iconMicSvg, iconSendSvg, iconRecognizeErrorSvg } from './touch-btn.images';
import { StatusType, VoiceToTextSubStatus,ErrorCode } from './touch-btn.types';
import type {TouchBtnEmits } from './touch-btn.types';
import * as TouchBtnImages from './touch-btn.images'; // 导出图片
import { StatusType, VoiceToTextSubStatus, ErrorCode } from './touch-btn.types';
import type { TouchBtnEmits } from './touch-btn.types';
import { wsUrl, bottomAreaTopBoundary, horizontalSplitX, initWebSocket, showErrorTip, vibrateLight } from './touch-btn';
import { ref, computed, onMounted, nextTick, watch, reactive } from 'vue';
import { onHide, onLaunch } from '@dcloudio/uni-app';
import common from '@/common/common';
import {setupKeyboardHeightListener} from '@/common/common';
import common, { setupKeyboardHeightListener } from '@/common/common';
import { startAudioRecord, stopAudioRecord, preRequestRecordPermission } from '@/uni_modules/ty-recording';
import { ProtocolCodec, MessageType, ControlCommand, ControlCode, ControlBody } from '@/common/protocolCodec';
import permissionApi from '@/common/permission';
@@ -97,8 +130,8 @@
// mode控制功能模式
mode: {
type: String,
default: 'voice-only',
validator: (value : string) => {
default: 'text-only',
validator: (value: string) => {
return ['voice-only', 'text-only', 'both'].includes(value);
}
},
@@ -147,10 +180,11 @@
});
const dialogDynamicClasses = computed(() => {
const classes = [];
isOutStatus.value === '02' && classes.push('is-out')
isOutStatus.value === '03' && classes.push('is-translate')
voice_to_text_status.value !== '' && classes.push(voice_to_text_status.value)
isOutStatus.value === '02' && classes.push('is-out');
(isOutStatus.value === '03' || status.value === 'voice_to_text') && classes.push('is-translate');
// 仅语音模式,01松手后要和03操作一样
// isOutStatus.value === '01' && props.mode === 'text-only' && status.value == 'voice_to_text' && classes.push('is-translate');
voice_to_text_status.value !== '' && classes.push(voice_to_text_status.value);
return classes;
});
const recordId = ref('');
@@ -162,23 +196,23 @@
// 是否录音中
const isRecording = ref(false);
// 键盘还是语音
const isInputVisible = ref(props.mode !== 'text-only'); // true=显示录音按钮,false=显示输入框
const isInputVisible = ref(true); // true=显示录音按钮,false=显示输入框
const recordStartTime = ref(0); // 录音开始时间戳
const pressTimer = ref<number | null>(null);
// 计算属性:判断是否仅语音/仅文字模式(简化模板逻辑)
const isVoiceOnlyMode = computed(() => props.mode === 'voice-only');
const isTextOnlyMode = computed(() => props.mode === 'text-only');
const talkRightIcon = computed(() => {
if (isInputVisible.value) return icKeyboardSvg();
if (inputText.value) return iconSendSvg();
return iconMicSvg();
if (isInputVisible.value) return TouchBtnImages.icKeyboardSvg();
if (inputText.value) return TouchBtnImages.iconSendSvg();
return TouchBtnImages.iconMicSvg();
});
// 计算是否超出按下盒子位置01代表下方盒子,02代表左上03代表右上
const isOutStatus = computed(() => {
const { y: touchY, x: touchX } = touchPos;
if (touchY >= bottomAreaTopBoundary) return '01';
// 仅语音模式只能返回02,就是取消
if(props.mode === 'voice-only') return '02';
// 仅语音模式只能返回取消02
if (props.mode === 'voice-only') return '02';
return touchX < horizontalSplitX ? '02' : '03';
});
// 监听按下移动
@@ -188,15 +222,16 @@
touchPos.y = pageY;
};
const testFun = () => {
voice_to_text_status.value = 'failed'
}
voice_to_text_status.value = 'failed';
};
// 开启语音
const startRecord = async (obj : { touches : any[]; }) => {
if(props.isDisabled) return;
const startRecord = async (obj: { touches: any[] }) => {
if (props.isDisabled) return;
try {
const state = await permissionApi.judgeIosPermission('record');
if (state === 'not determined') { // 苹果专用
preRequestRecordPermission(() => {})
if (state === 'not determined') {
// 苹果专用
preRequestRecordPermission(() => {});
return;
}
} catch (e) {
@@ -205,51 +240,59 @@
}
// 标记录音开始
isRecording.value = true;
status.value = 'voice_recording'
voice_to_text_status.value = ''
status.value = 'voice_recording';
voice_to_text_status.value = '';
tempText.value = '';
allText.value = '';
initWebSocket(wsUrl).then(socketTask => {
ws.value = socketTask
wsStatus.value = true;
console.log('WS连接成功');
ws.value.onMessage((res : { data : Uint8Array | ArrayBuffer; }) => {
try {
const { msgType, body } = ProtocolCodec.unpack(res.data);
console.log('msgType', msgType, body);
if (msgType === MessageType.TEXT_MESSAGE) {
tempText.value = '';
allText.value = allText.value + body;
} else if (msgType === MessageType.TIP_MESSAGE) {
tempText.value = body as string;
} else if (msgType === MessageType.CONTROL_CMD) { // 返回结束消息
const controlBody = body as ControlBody;
if(controlBody.type === ControlCode.SERVER_TO_FRONT_OVER) {
if(controlBody?.txt === '') { //说明没有识别到文字
voice_to_text_status.value = 'failed'
// todo
} else { // 识别成功
voice_to_text_status.value = 'success'
const ossKey = controlBody?.ossKey;
const text = controlBody?.txt;
// todo
console.log('ossKey', ossKey);
emit('submitVoice', {ossKey,text})
initWebSocket(wsUrl)
.then((socketTask) => {
ws.value = socketTask;
wsStatus.value = true;
console.log('WS连接成功');
ws.value.onMessage((res: { data: Uint8Array | ArrayBuffer }) => {
try {
const { msgType, body } = ProtocolCodec.unpack(res.data);
console.log('msgType', msgType, body);
if (msgType === MessageType.TEXT_MESSAGE) {
tempText.value = '';
allText.value = allText.value + body;
} else if (msgType === MessageType.TIP_MESSAGE) {
tempText.value = body as string;
} else if (msgType === MessageType.CONTROL_CMD) {
// 返回结束消息
const controlBody = body as ControlBody;
if (controlBody.type === ControlCode.SERVER_TO_FRONT_OVER) {
console.log('识别结束', controlBody);
// if(status.value === 'default') return;
// status.value = 'default'; // 恢复成默认状态
if (controlBody?.txt === '') {
//说明没有识别到文字
voice_to_text_status.value = 'failed';
emit('submitVoice', { ossKey:'', text:'', recordId: recordId.value });
// todo
} else {
// 识别成功
voice_to_text_status.value = 'success';
const ossKey = controlBody?.ossKey;
let text = '';
if (typeof controlBody?.txt === 'string') {
text = controlBody.txt.trim();
}
emit('submitVoice', { ossKey, text, recordId: recordId.value });
}
}
}
} catch (e) {
console.log('后端发来的信息有问题');
}
} catch (e) {
console.log('后端发来的信息有问题');
}
});
})
.catch(() => {
stopRecord('networkError');
console.log('网络出现问题');
});
}).catch(() => {
stopRecord('networkError')
console.log('网络出现问题');
})
pressTimer.value = setTimeout(() => {
vibrateLight() // 触感震动
vibrateLight(); // 触感震动
// 重设按下位置
const changedTouche = obj.touches[0];
touchPos.x = changedTouche.clientX;
@@ -259,14 +302,14 @@
// 弹出录音界面
popupRef.value.open();
startAudioRecord({
onFrame: (pcmData : any) => {
onFrame: (pcmData: any) => {
if (wsStatus.value && ws.value) {
ws.value.send({ data: ProtocolCodec.pack(MessageType.AUDIO_DATA, pcmData)});
ws.value.send({ data: ProtocolCodec.pack(MessageType.AUDIO_DATA, pcmData) });
}
},
onStart: (res : any) => {
onStart: (res: any) => {
console.log('启动', res);
recordId.value = res.recordId ?? ''
recordId.value = res.recordId ?? '';
},
onStop: () => {
console.log('关闭');
@@ -278,63 +321,147 @@
}
}
});
}, 120)
}, 120);
};
// 结束录音
const closePopup = () => {
popupRef.value.close();
}
const stopRecord = async (errrStatus='') => {
};
const stopRecord2 = async (errrStatus = '') => {
clearTimeout(pressTimer.value);
if (!isRecording.value) return; // 未处于录音状态
if (isOutStatus.value === '03') {
status.value = 'voice_to_text' //主状态设置为转文字
voice_to_text_status.value = 'init'
} else if(isOutStatus.value === '01') {
status.value = 'voice_send_ing' //主状态设置为语音发送中
status.value = 'voice_to_text'; //主状态设置为转文字
voice_to_text_status.value = 'init';
} else if (isOutStatus.value === '01') {
status.value = 'voice_send_ing'; //主状态设置为语音发送中
}
if(['01', '03'].includes(isOutStatus.value)) { // 向后端发送抬手动作
ws.value && ws.value.send({ data: ProtocolCodec.pack(MessageType.CONTROL_CMD, { type: ControlCode.FRONT_TO_SERVER_OVER})});
if (['01', '03'].includes(isOutStatus.value)) {
// 向后端发送抬手动作
ws.value &&
ws.value.send({
data: ProtocolCodec.pack(MessageType.CONTROL_CMD, { type: ControlCode.FRONT_TO_SERVER_OVER })
});
}
const recordDurationMs = Date.now() - recordStartTime.value;
if (isOutStatus.value !== '02') { // 取消的时候,不校验最低时间
if (isOutStatus.value !== '02') {
// 取消的时候,不校验最低时间
// 核心:计算录音总时长(毫秒转秒,保留1位小数)
if (recordDurationMs < 600) {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve()
}, 600 - recordDurationMs)
})
resolve();
}, 600 - recordDurationMs);
});
}
}
isRecording.value = false;
if (isOutStatus.value === '02' || errrStatus === 'networkError') { // 取消的时候自己主动关闭websocket,其他的时候需要等待后端的消息关闭
ws.value && ws.value.close({
code: 1000,
reason: '挂断',
complete: () => {
console.log('挂断Ws');
wsStatus.value = false;
}
});
if (isOutStatus.value === '02' || errrStatus === 'networkError') {
// 取消的时候自己主动关闭websocket,其他的时候需要等待后端的消息关闭
ws.value &&
ws.value.close({
code: 1000,
reason: '挂断',
complete: () => {
console.log('挂断Ws');
wsStatus.value = false;
}
});
}
stopAudioRecord(); // 关掉录音
if (isOutStatus.value !== '03' || errrStatus === 'networkError') { // 转文字时候不关遮罩层,网络错误必须关遮罩层
if (isOutStatus.value !== '03' || errrStatus === 'networkError') {
// 转文字时候不关遮罩层,网络错误必须关遮罩层
popupRef.value.close();
// 关掉弹窗后的提示
if(errrStatus === 'networkError') {
return showErrorTip(ErrorCode.NetworkError)
} else if (isOutStatus.value !== '02' && recordDurationMs <= 1200) { // 取消的时候,不校验最低时间
return showErrorTip(ErrorCode.ShortRecord)
if (errrStatus === 'networkError') {
return showErrorTip(ErrorCode.NetworkError);
} else if (isOutStatus.value !== '02' && recordDurationMs <= 1200) {
// 取消的时候,不校验最低时间
return showErrorTip(ErrorCode.ShortRecord);
}
}
if(isOutStatus.value === '01' && status.value == 'voice_send_ing') {
emit('sendLoading', {recordId:recordId.value})
if (isOutStatus.value === '01' && status.value == 'voice_send_ing') {
emit('sendLoading', { recordId: recordId.value });
// 如果socket长时间没有返回,这里兜底一下
setTimeout(() => {
if(status.value === 'default') return;
status.value = 'default'; // 恢复成默认状态
emit('submitVoice', { ossKey:'', text:'', recordId: recordId.value });
}, 5000)
}
};
const stopRecord = async (errrStatus = '') => {
clearTimeout(pressTimer.value);
if (!isRecording.value) return; // 未处于录音状态
const _isOutStatus = (props.mode === 'text-only' && isOutStatus.value === '01')?"03":isOutStatus.value;
console.log('_isOutStatus', _isOutStatus);
// 拖动到转文字按钮上抬手或者仅文字模式的发送也强行算他转文字
if (_isOutStatus === '03' ) {
status.value = 'voice_to_text'; //主状态设置为转文字
voice_to_text_status.value = 'init';
} else if (_isOutStatus === '01') {
status.value = 'voice_send_ing'; //主状态设置为语音发送中
}
if (['01', '03'].includes(_isOutStatus)) {
// 向后端发送抬手动作
ws.value &&
ws.value.send({
data: ProtocolCodec.pack(MessageType.CONTROL_CMD, { type: ControlCode.FRONT_TO_SERVER_OVER })
});
}
const recordDurationMs = Date.now() - recordStartTime.value;
if (_isOutStatus !== '02') {
// 取消的时候,不校验最低时间
// 核心:计算录音总时长(毫秒转秒,保留1位小数)
if (recordDurationMs < 600) {
await new Promise<void>((resolve) => {
setTimeout(() => {
resolve();
}, 600 - recordDurationMs);
});
}
}
isRecording.value = false;
if (_isOutStatus === '02' || errrStatus === 'networkError') {
// 取消的时候自己主动关闭websocket,其他的时候需要等待后端的消息关闭
ws.value &&
ws.value.close({
code: 1000,
reason: '挂断',
complete: () => {
console.log('挂断Ws');
wsStatus.value = false;
}
});
}
stopAudioRecord(); // 关掉录音
if (_isOutStatus !== '03' || errrStatus === 'networkError') {
// 转文字时候不关遮罩层,网络错误必须关遮罩层
popupRef.value.close();
// 关掉弹窗后的提示
if (errrStatus === 'networkError') {
return showErrorTip(ErrorCode.NetworkError);
} else if (_isOutStatus !== '02' && recordDurationMs <= 1200) {
// 取消的时候,不校验最低时间
return showErrorTip(ErrorCode.ShortRecord);
}
}
if (_isOutStatus === '01' && status.value == 'voice_send_ing') {
emit('sendLoading', { recordId: recordId.value });
// 如果socket长时间没有返回,这里兜底一下
setTimeout(() => {
if(status.value === 'default') return;
status.value = 'default'; // 恢复成默认状态
emit('submitVoice', { ossKey:'', text:'', recordId: recordId.value });
}, 5000)
}
};
// 发送文本
const showKeyboard = () => {
@@ -349,29 +476,30 @@
isInputVisible.value = !isInputVisible.value;
}
};
// 切换键盘语音
const changeBtn = () => {
if (props.isDisabled) return;
isInputVisible.value = !isInputVisible.value;
inputText.value = '';
};
// 禁用时点击给的提示
const disabled_click = () => {
console.log('禁用时点击给的提示');
if (props.isDisabled) common.msg(props.disabledText);
};
const send_msg = () => {
console.log('点击发送');
}
setupKeyboardHeightListener((height:number) => {
const _height = Math.max(height - 100, 0)
pageBoxMarginBottom.value = `${_height}px`;
};
setupKeyboardHeightListener((height: number) => {
const _height = Math.max(height - 100, 0);
pageBoxMarginBottom.value = `${_height}px`;
});
// 外面调用放弃这次
const give_up = () => {
console.log('调用结束语音回答');
@@ -379,19 +507,17 @@
};
// 外部调用,清理输入框数据
const clearinputText = (text = '') => {
const clearInputText = (text = '') => {
const old_text = inputText.value;
inputText.value = text;
return old_text;
};
defineExpose({ clearinputText, give_up });
defineExpose({ clearInputText, give_up });
</script>
<style lang="scss" scoped>
@import "./style/index.scss";
@import "./style/popup.scss";
@import './style/index.scss';
@import './style/popup.scss';
.white-bg-box {
height: 365rpx;
@@ -420,8 +546,7 @@
}
}
::v-deep .uv-input__content__field-wrapper__field {
padding-right: 60rpx;
}
</style>
</style>
+31 -4
View File
@@ -67,7 +67,7 @@
<view class="fixed-box font_pf" :style="{ marginBottom: popup_input_bottom }">
<view class="touch-btn-div" :class="{ show: showTouchBtn }">
<TouchBtnOnlyVoice
<!-- <TouchBtnOnlyVoice
v-if="answerMethod === '03'"
class="talk-btns"
ref="touchBtnRef"
@@ -79,7 +79,7 @@
:isDisabled="false"
:onlyVoice="true"
:answerMethod="answerMethod"
/>
/> -->
<!-- <TouchBtn
v-else
class="talk-btns"
@@ -92,10 +92,12 @@
:isDisabled="false"
:answerMethod="answerMethod"
/> -->
<touch-btn
v-else
class="talk-btns"
ref="touchBtnRef"
@sendLoading="sendLoading"
@submitVoice="submitVoice"
@uploadVoice="touchBtnSubmit('voice', $event)"
@submitAnswer="touchBtnSubmit('text', $event)"
:isLoading="touchIsDisabled"
@@ -331,7 +333,32 @@
return Promise.reject(error);
});
};
// 录音组件提交中转圈
const sendLoading = () => {
const topic = topicList[questionNumber.value];
console.log('录音组件提交中转圈', topic.es_status);
if (topic.es_status === '00') return;
topic.es_status = '00'; // 00转圈
}
// 新录音组件语音提交
const submitVoice = (voiceObj) => {
console.log('新录音组件语音提交');
const topic = topicList[questionNumber.value];
touchBtnRef.value?.clearInputText(); // 清除发送框数据
const _content = voiceObj.text;
if (_content === '') {
topic.es_status = ''; // 取消转圈
return common.msg('未识别到文字');
} else {
topic.es_status = '02';
topic.my_answer = {
anserResult: _content,
ossKey: voiceObj.ossKey
};
}
}
// 录音组件提交
const touchBtnSubmit = (type, submitObj) => {
const topic = topicList[questionNumber.value];