发送文字替换发送语音

This commit is contained in:
fan 2022-12-06 14:05:07 +08:00
parent 2f5444e27f
commit d73bc4d577
11 changed files with 291 additions and 98 deletions

View File

@ -907,6 +907,10 @@ export const menuOperate = {
Chat: {
operation: OperationEvent.Conversation.Chat.menu.operation,
cmdType: CMD.Conversation.CMD_Conversation_Chat_Text
},
Record: {
operation: OperationEvent.Conversation.Chat.record.operation,
cmdType: CMD.Conversation.CMD_Conversation_Chat_Audio_Base64
}
}

View File

@ -4189,6 +4189,10 @@ export const OperationEvent = {
sideButton: {
operation: '1402',
domId: '_Tips-Conversation-Chat-sideButton'
},
record: {
operation: '1403',
domId: '_Tips-Conversation-Chat-record'
}
}
},

View File

@ -2,7 +2,9 @@ import ValidateHandler from './newValidateHandler';
import store from '@/store/index';
import { sendCommandNew, endTrainingStep } from '@/api/jmap/training';
import router from '@/router/index';
import { OperationEvent } from '@/scripts/cmdPlugin/OperationHandler';
import {UserOperationType} from '@/scripts/ConstDic';
import CMD from '@/scripts/cmdPlugin/CommandEnum';
class Handler {
constructor() {
this.operations = [];
@ -95,6 +97,10 @@ class Handler {
const operateOrder = store.state.trainingNew.operateOrder;
return stepInfo.operations.length <= operateOrder + 1;
}
// 是否未特殊语音执行步骤列表的最后一步
isLastVoiceStep() {
return store.state.trainingNew.voiceStepList.length <= store.state.trainingNew.voiceStepIndex + 1;
}
// 计算当前步骤得分
computedScoring() {
const stepInfo = store.state.trainingNew.stepInfo;
@ -116,5 +122,61 @@ class Handler {
console.error('进入下一步失败!', e);
});
}
// 判定是否转换特殊语音消息步骤列表 如果是跳过当前操作 进入特殊语音执行序列
judgeIsTextSendOperation() {
const stepInfo = store.state.trainingNew.stepInfo;
const operateOrder = store.state.trainingNew.operateOrder;
const operation = stepInfo.operations[operateOrder];
if (operation.domId === OperationEvent.Conversation.Chat.menu.operation) {
this.handleVoiceStepList();
}
}
// 处理特殊语音消息步骤列表
handleVoiceStepList() {
const stepInfo = store.state.trainingNew.stepInfo;
const operateOrder = store.state.trainingNew.operateOrder;
const operation = stepInfo.operations[operateOrder];
const operation1 = {
userOperationType: UserOperationType.LEFTCLICK,
domId: OperationEvent.Conversation.Chat.sideButton.operation,
params: { chatBoxMin: true }
};
const step1 = {
description: '点击打开聊天室',
memberId: stepInfo.memberId,
operations: [operation1],
tipPosition: { deviceCode: '', domId: operation1.domId, operateIndex: 0 }
};
const operation2 = {
userOperationType: UserOperationType.LEFTCLICK,
domId: OperationEvent.Conversation.Chat.record.operation,
params: {}
};
const step2 = {
description: '点击录制语音',
memberId: stepInfo.memberId,
operations: [operation2],
tipPosition: { deviceCode: '', domId: operation2.domId, operateIndex: 0 }
};
const operation3 = {
userOperationType: UserOperationType.LEFTCLICK,
domId: OperationEvent.Conversation.Chat.record.operation,
operationType: CMD.Conversation.CMD_Conversation_Chat_Audio_Base64.value,
params: {
fileBase64Str: 'no'
}
};
const step3 = {
description: `请说出“${operation.params.content}”后,再次点击发送语音!`,
memberId: stepInfo.memberId,
operations: [operation3],
tipPosition: { deviceCode: '', domId: operation3.domId, operateIndex: 0 }
};
if (store.state.training.chatBoxMin) {
store.dispatch('trainingNew/setVoiceStepList', [step1, step2, step3]);
} else {
store.dispatch('trainingNew/setVoiceStepList', [step2, step3]);
}
}
}
export default new Handler();

View File

@ -23,8 +23,12 @@ class ValidateHandler {
}
// 判断实训操作正确性
judgeTraining(operate) {
const stepOperation = Handler.getTrainingOperation();
console.log(operate, stepOperation, 'judgeTraining');
let stepOperation = {};
if (store.state.trainingNew.voiceStepIndex > -1) {
stepOperation = store.state.trainingNew.voiceStepList[store.state.trainingNew.voiceStepIndex].operations[0];
} else {
stepOperation = Handler.getTrainingOperation();
}
let valid = true;
if (operate.cmdType || stepOperation.operationType) {
const cmd = operate.cmdType ? operate.cmdType.value : '';
@ -40,14 +44,17 @@ class ValidateHandler {
valid = (operate.userOperationType === stepOperation.userOperationType) && valid;
}
const opParam = operate.param === undefined ? {} : operate.param;
if (opParam || stepOperation.params) {
if ((opParam || stepOperation.params) && !opParam.hasOwnProperty('fileBase64Str')) {
valid = objectIsEqual(opParam, stepOperation.params) && valid;
}
if (valid && Handler.isLastOperation()) {
if (valid && store.state.trainingNew.voiceStepIndex > -1) {
!Handler.isLastVoiceStep() && store.dispatch('trainingNew/voiceStepIndexIncrease');
} else if (valid && Handler.isLastOperation()) {
Handler.nextStep();
} else if (valid) {
store.dispatch('trainingNew/operateOrderIncrease');
Handler.judgeIsTextSendOperation();
} else {
console.error('校验失败;');
}

View File

@ -50,7 +50,8 @@ const training = {
runPathList:[], // 运行线 (宁波三号线)
domConfig: {}, // 线路功能前端配置项
simulationUserType: '', // 仿真用户角色
simulationCreator: false
simulationCreator: false,
chatBoxMin: true // 聊天框最小化
},
getters: {
@ -324,6 +325,9 @@ const training = {
},
setDomConfig: (state, domConfig) => {
state.domConfig = domConfig;
},
setChatBoxMin: (state, chatBoxMin) => {
state.chatBoxMin = chatBoxMin;
}
},
@ -661,6 +665,9 @@ const training = {
},
setOperate: ({ commit }, operate) => {
commit('setOperate', operate);
},
setChatBoxMin: ({ commit }, chatBoxMin) => {
commit('setChatBoxMin', chatBoxMin);
}
}
};

View File

@ -1,4 +1,4 @@
import NewHandler from '@/scripts/cmdPlugin/newHandler';
import Handler from '@/scripts/cmdPlugin/newHandler';
import store from '@/store/index';
const training = {
namespaced: true,
@ -15,7 +15,9 @@ const training = {
operateOrder: 0, // 操作order
operateErrMsg: '',
scoreList: [], // 实训得分
draftStepList: null // 显示的步骤列表
draftStepList: null, // 显示的步骤列表
voiceStepList: [], // 实训特殊语音步骤列表
voiceStepIndex: -1
},
getters: {
teachMode: (state) => {
@ -71,7 +73,7 @@ const training = {
},
setStepInfo: (state, stepInfo) => {
state.stepInfo = state.stepList.find(step => step.id === stepInfo.stepId);
console.log(state.stepInfo, stepInfo, state.stepList, 'dsdf');
Handler.judgeIsTextSendOperation();
},
clearTrainingData: (state) => {
state.teachMode = '';
@ -89,6 +91,18 @@ const training = {
},
editDraftStepList: (state, draftStepList) => {
state.draftStepList = draftStepList;
},
setVoiceStepList: (state, voiceStepList) => {
state.voiceStepIndex = 0;
state.voiceStepList = voiceStepList;
console.log(voiceStepList, state.voiceStepIndex);
},
voiceStepIndexIncrease: (state) => {
state.voiceStepIndex++;
},
clearVoiceStepList: (state) => {
state.voiceStepIndex = -1;
state.voiceStepList = [];
}
},
actions: {
@ -129,7 +143,7 @@ const training = {
if (!store.state.training.roles) {
reject({message: '您目前无仿真成员角色!'});
} else {
NewHandler.handle(operate).then(rtn => {
Handler.handle(operate).then(rtn => {
resolve(rtn);
}).catch(e => {
reject(e);
@ -152,6 +166,30 @@ const training = {
},
editDraftStepList: ({ commit }, draftStepList) => {
commit('editDraftStepList', draftStepList);
},
setVoiceStepList: ({ commit }, voiceStepList) => {
commit('setVoiceStepList', voiceStepList);
},
voiceStepIndexIncrease: ({ commit }) => {
commit('voiceStepIndexIncrease');
},
clearVoiceStepList: ({ commit }) => {
commit('clearVoiceStepList');
},
handleMatchVoice: ({ commit }, info) => {
console.log(info);
if (info && info.content === 'true') {
if (Handler.isLastOperation()) {
Handler.nextStep();
commit('clearVoiceStepList');
} else {
commit('clearVoiceStepList');
commit('operateOrderIncrease');
Handler.judgeIsTextSendOperation();
}
} else if (info && info.content === 'false') {
Handler.handleVoiceStepList();
}
}
}
};

View File

@ -180,6 +180,9 @@ function handle(data) {
case 'Simulation_Training_Step_Tip':
store.dispatch('trainingNew/setStepInfo', msg);
break;
case 'Simulation_Training_Audio_MATCH_RESULT':
store.dispatch('trainingNew/handleMatchVoice', msg);
break;
}
}
// 仿真内部聊天

View File

@ -1,9 +1,9 @@
<template>
<div v-quickMenuDrag class="voice-chat-box">
<div v-if="min" :id="sideButtonDom.domId" @click="clickBtn">
<div v-if="chatBoxMin" :id="sideButtonDom.domId" @click="clickBtn">
<el-button circle style="color: #0C161A;" icon="el-icon-mic" />
</div>
<div v-show="!min" class="chat-box-main">
<div v-show="!chatBoxMin" class="chat-box-main">
<div class="chat-box-header">
<div style="margin-right: 10px;cursor: pointer;">
<i class="el-icon-minus" style="color: #000;" @click="minimize" />
@ -36,7 +36,7 @@
<div class="chat-box-footer">
<el-input v-model="textContent" size="small" placeholder="请输入会话文字点击T发送" style="flex: 1; margin-left: 5px;" :rows="1" />
<el-button :id="sendTextId" size="mini" class="chat-box-footer-create" :disabled="contentSend" @click="sendText">T</el-button>
<el-button class="chat-box-footer-create chat-box-footer-send" :class="{'active': recordSending}" :disabled="audioPlay" size="mini" type="primary" @click="startRecording()">
<el-button :id="recordVoice" class="chat-box-footer-create chat-box-footer-send" :class="{'active': recordSending}" :disabled="audioPlay || (trainingDesign && !trainingSwitch)" size="mini" type="primary" @click="startRecording()">
<el-progress id="voice_progress_bar" type="circle" :show-text="false" :percentage="100/60*seconds" :width="40" :stroke-width="2" status="success" />
<i v-if="recordSending" class="el-icon-close close_icon" @click.stop="cancelRecording()" />
<span class="iconfont icon-yuyin">&#xe62b;</span>
@ -49,10 +49,11 @@
<script>
import RecordRTC from 'recordrtc';
import {sendChatAudioBase64, getAllConversition} from '@/api/chat';
import {getAllConversition} from '@/api/chat';
import { OperationEvent } from '@/scripts/cmdPlugin/OperationHandler';
import {menuOperate, commitOperate} from '@/jmapNew/theme/components/utils/menuOperate';
import {UserOperationType} from '@/scripts/ConstDic';
import CMD from '@/scripts/cmdPlugin/CommandEnum';
export default {
name: 'ChatBox',
data() {
@ -64,16 +65,19 @@ export default {
microphone:null,
audioPlay:false,
textContent: '',
min: true,
messageList: [], //
currentAudioList:[],
currentMessage: {}
currentMessage: {},
trainingDesign: false
};
},
computed:{
group() {
return this.$route.query.group;
},
chatBoxMin() {
return this.$store.state.training.chatBoxMin;
},
contentSend() {
return !this.textContent;
},
@ -86,18 +90,26 @@ export default {
sendTextId() {
return OperationEvent.Conversation.Chat.menu.domId;
},
recordVoice() {
return OperationEvent.Conversation.Chat.record.domId;
},
sideButtonDom() {
return OperationEvent.Conversation.Chat.sideButton;
},
trainingSwitch() {
return this.$store.state.trainingNew.trainingSwitch;
}
},
watch: {
'$store.state.socket.simulationReset': function () { // 仿
this.messageList = [];
},
'$store.state.training.domConfig': function(val) {
this.trainingDesign = val.trainingDesign;
},
'$store.state.socket.conversationMessage':function (val) { // 仿
const message = {...val};
this.messageList.push(message);
console.log(val, '----------');
if (val.memberId != this.myMemberId) {
this.currentAudioList.push(message);
if (!this.isPlay) {
@ -105,21 +117,25 @@ export default {
}
}
this.scrollTop();
}
},
mounted() {
this.trainingDesign = this.$store.state.training.domConfig ? this.$store.state.training.domConfig.trainingDesign : false;
this.initConversationData();
},
methods: {
scrollTop() {
this.$nextTick(() => {
const scrollTop = this.messageList.length * 65 - 250;
document.querySelector('.chat-box-content').scrollTop = scrollTop;
});
},
initConversationData() {
getAllConversition(this.group).then(resp => {
if (resp.data && resp.data.length) {
const conversation = resp.data.find(con => con.id === 'chat_room_key');
this.messageList = conversation ? conversation.messageList : [];
this.scrollTop();
} else {
this.messageList = [];
}
@ -166,14 +182,18 @@ export default {
clickBtn() {
const operate = {
operation: this.sideButtonDom.operation,
param: { min: this.min },
param: { chatBoxMin: this.chatBoxMin },
userOperationType: UserOperationType.LEFTCLICK
};
this.min = false;
this.$store.dispatch('trainingNew/next', operate);
this.$store.dispatch('training/setChatBoxMin', false);
if (this.$store.state.trainingNew.trainingSwitch) {
this.$nextTick(() => {
this.$store.dispatch('trainingNew/next', operate);
});
}
},
minimize() {
this.min = true;
this.$store.dispatch('training/setChatBoxMin', true);
},
sendText() {
commitOperate(menuOperate.Conversation.Chat, {content: this.textContent}, 3).then(({valid})=>{
@ -202,16 +222,24 @@ export default {
const that = this;
this.recorders.stopRecording(function(blobURL) {
that.recorders.getDataURL(function(BaseURL) {
sendChatAudioBase64(that.group, {fileBase64Str: BaseURL})
.then((data) => {
const operate = {
over: true,
cmdType: CMD.Conversation.CMD_Conversation_Chat_Audio_Base64,
operation: OperationEvent.Conversation.Chat.record.operation,
userOperationType: UserOperationType.LEFTCLICK,
param: {
fileBase64Str: BaseURL
}
};
that.$store.dispatch('trainingNew/next', operate).then(({ valid }) => {
if (valid) {
that.textContent = '';
that.audioPlay = false;
})
.catch(error => {
console.log(error);
that.$message.error('语音发送失败: ' + error.message);
that.audioPlay = false;
});
}
}).catch(error => {
that.$message.error('发送会话语音失败:' + error.message);
that.audioPlay = false;
});
if (that.microphone) {
that.microphone.stop();
that.microphone = null;
@ -221,73 +249,87 @@ export default {
});
});
},
tipErrorMessage(error) {
switch (error.code || error.name) {
case 'PERMISSION_DENIED':
case 'PermissionDeniedError':
this.$message({
showClose: true,
message: '用户拒绝提供信息',
type: 'error'
});
break;
case 'NOT_SUPPORTED_ERROR':
case 'NotSupportedError':
this.$message({
showClose: true,
message: '浏览器不支持硬件设备',
type: 'error'
});
break;
case 'MANDATORY_UNSATISFIED_ERROR':
case 'MandatoryUnsatisfiedError':
this.$message({
showClose: true,
message: '无法发现指定的硬件设备',
type: 'error'
});
break;
default:
this.$message({
showClose: true,
message: '无法打开麦克风',
type: 'error'
});
break;
}
},
mediaSuccessCallback(stream) {
const StereoAudioRecorder = RecordRTC.StereoAudioRecorder;
this.microphone = stream;
this.recorders = new RecordRTC(this.microphone, {
type: 'audio',
recorderType: StereoAudioRecorder,
numberOfAudioChannels: 1,
bitsPerSecond:256000,
desiredSampRate: 16000
});
this.recorders.startRecording();
this.recordSending = true;
this.audioPlay = false;
this.inter = setInterval(() => {
if (this.seconds < 60) {
this.seconds++;
} else {
clearInterval(this.inter);
this.stopRecording();
}
}, 1000);
},
//
startRecording() {
this.audioPlay = true;
const that = this;
if (!this.recordSending) {
if (!this.recordSending && !this.recorders && !this.microphone) {
const StereoAudioRecorder = RecordRTC.StereoAudioRecorder;
navigator.getUserMedia(
{ audio: true } //
, function (stream) {
that.microphone = stream;
that.recorders = new RecordRTC(that.microphone, {
type: 'audio',
recorderType: StereoAudioRecorder,
numberOfAudioChannels: 1,
bitsPerSecond:256000,
desiredSampRate: 16000
});
that.recorders.startRecording();
that.recordSending = true;
that.audioPlay = false;
that.inter = setInterval(() => {
if (that.seconds < 60) {
that.seconds++;
} else {
clearInterval(that.inter);
that.stopRecording();
const operate = {
operation: OperationEvent.Conversation.Chat.record.operation,
userOperationType: UserOperationType.LEFTCLICK
};
this.$store.dispatch('trainingNew/next', operate).then(({ valid }) => {
if (valid) {
this.audioPlay = true;
const that = this;
if (!this.recordSending && !this.recorders && !this.microphone) {
navigator.getUserMedia(
{ audio: true } //
, function (stream) {
that.mediaSuccessCallback(stream);
}, function (error) {
that.audioPlay = false;
that.tipErrorMessage(error);
}
}, 1000);
}, function (error) {
that.audioPlay = false;
switch (error.code || error.name) {
case 'PERMISSION_DENIED':
case 'PermissionDeniedError':
that.$message({
showClose: true,
message: '用户拒绝提供信息',
type: 'error'
});
break;
case 'NOT_SUPPORTED_ERROR':
case 'NotSupportedError':
that.$message({
showClose: true,
message: '浏览器不支持硬件设备',
type: 'error'
});
break;
case 'MANDATORY_UNSATISFIED_ERROR':
case 'MandatoryUnsatisfiedError':
that.$message({
showClose: true,
message: '无法发现指定的硬件设备',
type: 'error'
});
break;
default:
that.$message({
showClose: true,
message: '无法打开麦克风',
type: 'error'
});
break;
}
);
}
);
}
}
}).catch(() => { console.error('操作失败!'); });
} else {
this.stopRecording(); //
}
@ -445,6 +487,7 @@ export default {
}
.userMessage{
position: relative;
text-align: left;
}
.messageText{
line-height: 20px;

View File

@ -9,7 +9,7 @@
<training-position-tip ref="trainingPositionTip" />
<training-menu v-if="hasTraining" ref="trainingMenu" :offset-bottom="offsetBottom" />
<training-design v-if="trainingDesign" ref="trainingDesign" />
<voice-chat-box v-if="hasVoice" :group="group" />
<chat-box v-if="hasVoice" ref="chatBox" :group="group" />
<design-training-menu v-if="trainingDesign && trainingDetail" ref="trainingMenu" :offset-bottom="offsetBottom" />
</div>
</template>
@ -27,7 +27,7 @@ import TrainingTip from './trainingList/trainingTip';
import TrainingPositionTip from './trainingList/trainingPositionTip.vue';
import TrainingMenu from './trainingList/trainingMenu';
import TrainingDesign from './trainingDesign/designPane.vue';
import VoiceChatBox from './voiceChatBox/chatBox';
import ChatBox from './chatBox';
import DesignTrainingMenu from './trainingList/designTrainingMenu';
export default {
name: 'DisplayDraft',
@ -39,7 +39,7 @@ export default {
TrainingPositionTip,
TrainingMenu,
TrainingDesign,
VoiceChatBox,
ChatBox,
DesignTrainingMenu
},
data() {

View File

@ -50,6 +50,15 @@ export default {
this.tipShow = false;
}
},
'$store.state.trainingNew.voiceStepIndex': function(val) {
if (val > -1 && this.trainingDetail && this.trainingDetail.type === 'SINGLE') {
this.tipInit();
} else {
this.tip = '';
this.popShow = false;
this.tipShow = false;
}
},
'$store.state.socket.trainingOverCount': function(val) {
this.tip = '';
this.popShow = false;
@ -73,9 +82,16 @@ export default {
if (this.teachMode === ScriptMode.TEACH) {
this.tipShow = true;
const offset = this.$store.state.config.canvasOffset;
const stepInfo = this.$store.state.trainingNew.stepInfo;
let stepInfo = {};
if (this.$store.state.trainingNew.voiceStepIndex > -1) {
stepInfo = this.$store.state.trainingNew.voiceStepList[this.$store.state.trainingNew.voiceStepIndex];
if (!stepInfo) { return; }
} else {
stepInfo = this.$store.state.trainingNew.stepInfo;
}
const distance = 5;
this.tip = stepInfo ? stepInfo.description : '';
console.log(stepInfo, this.tip, '***');
if (stepInfo.tipPosition && stepInfo.tipPosition.deviceCode) {
const position = this.getShapeTipPoint(stepInfo.tipPosition);
if (position) {
@ -92,6 +108,7 @@ export default {
this.position.y -= distance;
this.popTipShow();
}
console.log(this.popShow, this.position, this.tip, '-----');
} else {
this.popTipHide();
}
@ -145,7 +162,6 @@ export default {
//
getOtherTipPoint(tipPosition) {
const domId = OperationHandler.getDomIdByOperation(tipPosition.domId);
console.log(domId, '-------------');
if (!domId) { return null; }
return new Promise(async(resolve, reject) => {
try {
@ -172,6 +188,7 @@ export default {
y: offset.y
});
} else {
console.log('235s');
resolve(null);
}
} catch (err) {

View File

@ -31,6 +31,14 @@ export default {
this.trainingTipMessage = '';
}
},
'$store.state.trainingNew.voiceStepIndex': function(val) {
if (val > -1 && this.trainingDetail.type === 'SCENE' && (this.teachMode === ScriptMode.TEACH || this.teachMode === ScriptMode.PRACTICE)) {
const stepInfo = this.$store.state.trainingNew.voiceStepList[this.$store.state.trainingNew.voiceStepIndex];
this.trainingTipMessage = stepInfo ? stepInfo.description : this.$store.state.trainingNew.stepInfo.description;
} else {
this.trainingTipMessage = '';
}
},
'$store.state.trainingNew.trainingSwitch': function(val) {
if (!val) {
this.trainingTipMessage = '';