2020-07-23 17:51:37 +08:00
|
|
|
<template>
|
|
|
|
<chat-box
|
|
|
|
ref="chatbox"
|
|
|
|
:group="group"
|
|
|
|
:is-show="isShow"
|
|
|
|
:tree-data="treeData"
|
|
|
|
:conversition-id="conversitionId"
|
|
|
|
:current-member-list="currentMemberList"
|
|
|
|
:chat-content-list="chatContentList"
|
|
|
|
:script-tip="scriptTip"
|
|
|
|
:is-start-record="isStartRecord"
|
|
|
|
:invite-user-name="inviteUserName"
|
|
|
|
:is-quit-show="isQuitShow"
|
|
|
|
@setScriptTip="setScriptTip"
|
|
|
|
@resetCoversition="resetCoversition"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
import ChatBox from '../chatView/chatBox.vue';
|
|
|
|
import ConstConfig from '@/scripts/ConstConfig';
|
|
|
|
import CMD from '@/scripts/cmdPlugin/CommandEnum';
|
|
|
|
import Cookies from 'js-cookie';
|
2020-08-04 10:24:45 +08:00
|
|
|
import { getSimulationMemberList} from '@/api/simulation';
|
2020-08-03 19:21:56 +08:00
|
|
|
import {getAllConversition} from '@/api/chat';
|
2020-07-23 17:51:37 +08:00
|
|
|
export default {
|
|
|
|
name:'DemonChat',
|
|
|
|
components:{
|
|
|
|
ChatBox
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
group: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
userRole: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
scriptTip:'',
|
|
|
|
isHasCoversition:false,
|
|
|
|
conversitionId:'',
|
|
|
|
currentMemberList:[],
|
|
|
|
memberData:{},
|
|
|
|
chatContentList:[],
|
2020-08-03 19:21:56 +08:00
|
|
|
activeTrainList:[],
|
2020-07-23 17:51:37 +08:00
|
|
|
isStartRecord:false,
|
|
|
|
inviteUserName:'',
|
|
|
|
createCoversition:true,
|
|
|
|
inviteUser:{},
|
|
|
|
isQuitShow:false,
|
|
|
|
treeData:[],
|
2020-08-03 19:21:56 +08:00
|
|
|
driverList:[],
|
|
|
|
simulationUsers:{}
|
2020-07-23 17:51:37 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed:{
|
|
|
|
isShow() {
|
|
|
|
return this.userRole != '' &&
|
|
|
|
this.userRole != 'ADMIN' && this.userRole != 'AUDIENCE' &&
|
|
|
|
!this.isHasCoversition && this.createCoversition;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch:{
|
2020-07-24 10:35:05 +08:00
|
|
|
'$store.state.map.mapViewLoadedCount': function (val) { // 地图视图加载完成标识 开始获取仿真成员
|
2020-07-23 17:51:37 +08:00
|
|
|
getSimulationMemberList(this.group).then(resp => {
|
|
|
|
let lastData = JSON.stringify(resp.data);
|
|
|
|
const roleTypeList = ConstConfig.ConstSelect.roleTypeNew;
|
|
|
|
roleTypeList.forEach(function(element) {
|
|
|
|
const rolename = element.value;
|
|
|
|
if (Cookies.get('user_lang') == 'en') {
|
|
|
|
lastData = lastData.replace(new RegExp(rolename, 'g'), element.enLabel);
|
|
|
|
} else {
|
|
|
|
lastData = lastData.replace(new RegExp(rolename, 'g'), element.label);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
lastData = JSON.parse(lastData);
|
|
|
|
const lastMemberList = [];
|
|
|
|
const dispatcherList = [];
|
2020-07-31 16:22:29 +08:00
|
|
|
// const electricDispatcherList = [];
|
2020-08-04 10:24:45 +08:00
|
|
|
const depotDispatcherList = [];
|
2020-07-23 17:51:37 +08:00
|
|
|
const stationSupervisorList = [];
|
|
|
|
this.driverList = [];
|
|
|
|
const maintainerList = [];
|
2020-08-10 09:47:01 +08:00
|
|
|
const driverList = [];
|
2020-07-23 17:51:37 +08:00
|
|
|
this.treeData = [];
|
|
|
|
lastData.forEach((member, index)=>{
|
|
|
|
if (member.type != '观众') {
|
|
|
|
if (!member.userId) {
|
|
|
|
member.userId = '';
|
|
|
|
member.disabled = false;
|
|
|
|
} else {
|
|
|
|
member.disabled = true;
|
|
|
|
}
|
|
|
|
const name = member.name == undefined ? '' : '-' + member.name;
|
|
|
|
if (member.deviceCode) {
|
|
|
|
const device = this.$store.getters['map/getDeviceByCode'](member.deviceCode);
|
|
|
|
if (device) {
|
|
|
|
if (device._type == 'Train') {
|
2020-08-10 15:54:38 +08:00
|
|
|
member.label = member.type + device.groupNumber + name;
|
2020-07-23 17:51:37 +08:00
|
|
|
lastMemberList.push(member);
|
2020-08-03 19:21:56 +08:00
|
|
|
if (this.activeTrainList.length > 0) {
|
|
|
|
if (this.activeTrainList.includes(member.deviceCode)) {
|
2020-08-10 09:47:01 +08:00
|
|
|
driverList.push(member);
|
2020-08-03 19:21:56 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.driverList.push(member);
|
|
|
|
}
|
2020-07-23 17:51:37 +08:00
|
|
|
} else {
|
2020-08-10 15:54:38 +08:00
|
|
|
member.label = member.type + device.name + name;
|
2020-07-23 17:51:37 +08:00
|
|
|
lastMemberList.push(member);
|
|
|
|
if (device._type == 'Station') {
|
|
|
|
stationSupervisorList.push(member);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2020-08-10 15:54:38 +08:00
|
|
|
member.label = member.type + member.deviceCode + name;
|
2020-07-23 17:51:37 +08:00
|
|
|
lastMemberList.push(member);
|
|
|
|
}
|
|
|
|
} else {
|
2020-08-10 15:54:38 +08:00
|
|
|
member.label = member.type + name;
|
2020-07-23 17:51:37 +08:00
|
|
|
if (member.type == '行调') {
|
|
|
|
dispatcherList.push(member);
|
|
|
|
} else if (member.type == '通号') {
|
|
|
|
maintainerList.push(member);
|
2020-08-04 10:24:45 +08:00
|
|
|
} else if (member.type == '车辆段调度') {
|
|
|
|
depotDispatcherList.push(member);
|
2020-07-23 17:51:37 +08:00
|
|
|
}
|
|
|
|
lastMemberList.push(member);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.treeData = [{
|
|
|
|
label: '行调',
|
|
|
|
id: 'dispatcher',
|
|
|
|
type: 'role',
|
|
|
|
children: dispatcherList
|
|
|
|
}, {
|
|
|
|
label: '车站值班员',
|
|
|
|
id: 'stationSupervisor',
|
|
|
|
type: 'role',
|
|
|
|
children: stationSupervisorList
|
|
|
|
}, {
|
|
|
|
label: '司机',
|
|
|
|
id: 'driver',
|
|
|
|
type: 'role',
|
2020-08-10 09:47:01 +08:00
|
|
|
children: driverList
|
2020-07-23 17:51:37 +08:00
|
|
|
}, {
|
|
|
|
label: '通号',
|
|
|
|
id: 'maintainer',
|
|
|
|
type: 'role',
|
|
|
|
children: maintainerList
|
2020-08-04 10:24:45 +08:00
|
|
|
}, {
|
|
|
|
label: '车辆段',
|
|
|
|
id: 'depotDispatcher',
|
|
|
|
type: 'role',
|
|
|
|
children: depotDispatcherList
|
2020-07-23 17:51:37 +08:00
|
|
|
}];
|
|
|
|
this.memberData = lastMemberList;
|
|
|
|
}).catch(() => {
|
|
|
|
this.$messageBox('获取仿真成员列表失败!');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
// 创建会话
|
|
|
|
'$store.state.socket.createConversition':function(val) {
|
|
|
|
this.scriptTip = '';
|
|
|
|
if (this.memberData.length > 0) {
|
|
|
|
const member = this.memberData.find(member=>{ return member.id == val.creatorId; });
|
|
|
|
if (member && member.userId == this.$store.state.user.id) {
|
|
|
|
// 当前用户创建的会话
|
|
|
|
this.isHasCoversition = true;
|
|
|
|
this.isStartRecord = true;
|
|
|
|
this.isQuitShow = true;
|
|
|
|
this.conversitionId = val.id;
|
|
|
|
const memberList = [];
|
|
|
|
val.memberIds.forEach(id=>{
|
|
|
|
if (val.creatorId == id) {
|
|
|
|
member.connect = true;
|
|
|
|
memberList.push(member);
|
|
|
|
} else {
|
|
|
|
const member = this.memberData.find(member=>{ return member.id == id; });
|
|
|
|
member.connect = false;
|
|
|
|
member && memberList.push(member);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.currentMemberList = memberList;
|
|
|
|
} else {
|
|
|
|
// 如果是观众看所有人的会话
|
|
|
|
if (this.userRole == 'AUDIENCE') {
|
|
|
|
this.isHasCoversition = true;
|
|
|
|
this.currentMemberList = this.memberData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 用户接受会话
|
|
|
|
'$store.state.socket.acceptConversionInvite':function(val) {
|
2020-08-04 10:24:45 +08:00
|
|
|
this.conversitionId = val.id;
|
2020-07-23 17:51:37 +08:00
|
|
|
if (this.conversitionId) {
|
|
|
|
let result = false;
|
|
|
|
// 更改成员列表里面的成员状态
|
|
|
|
const memberList = this.currentMemberList.map(member => {
|
|
|
|
if (member.id == val.memberId) {
|
|
|
|
member.connect = true;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return member;
|
|
|
|
});
|
|
|
|
// 如果该用户不在成员列表里面,就动态加进去(当前会话)
|
|
|
|
if (!result && this.conversitionId) {
|
|
|
|
const member = this.memberData.find(member=>{ return member.id == val.memberId; });
|
|
|
|
if (member) {
|
|
|
|
member.connect = true;
|
|
|
|
memberList.push(member);
|
|
|
|
// 如果是当前的用户
|
|
|
|
if (member.userId == this.$store.state.user.id) {
|
|
|
|
memberList.push(this.inviteUser);
|
|
|
|
this.isStartRecord = true;
|
2020-08-04 10:24:45 +08:00
|
|
|
if (member.userId != this.inviteUser.userId) {
|
|
|
|
this.isQuitShow = false;
|
|
|
|
} else {
|
|
|
|
this.isQuitShow = true;
|
|
|
|
}
|
|
|
|
this.inviteUser = {};
|
|
|
|
this.isHasCoversition = true;
|
2020-07-23 17:51:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.currentMemberList = memberList;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 剧本提示
|
|
|
|
'$store.state.socket.simulationScriptTip':function(val, old) {
|
|
|
|
if (val) {
|
|
|
|
if (val.type == 'Conversation') {
|
|
|
|
this.scriptTip = '请说:' + val.content;
|
2020-08-10 16:29:32 +08:00
|
|
|
} else if (val.type == 'Operation') {
|
2020-07-23 17:51:37 +08:00
|
|
|
const commandName = val.operationType;
|
|
|
|
let device = val.operationType.split('_')[0];
|
|
|
|
if (device == 'CM') {
|
|
|
|
device = 'ControlConvertMenu';
|
|
|
|
}
|
|
|
|
const operateName = Object.values(CMD[device]).find(res=>{ return res.value == commandName; });
|
|
|
|
this.$messageBox('请执行【' + operateName.label + '】操作');
|
|
|
|
} else if (val.type == 'Over_Conversation') {
|
|
|
|
this.scriptTip = '请结束当前会话';
|
|
|
|
} else if (val.type == 'Start_Conversation' ) {
|
|
|
|
const inviteMember = [];
|
|
|
|
this.createCoversition = true;
|
|
|
|
val.conversationMemberIds.forEach(id=>{
|
|
|
|
if (val.memberId != id) {
|
|
|
|
inviteMember.push((this.memberData.find(member=>{ return member.id == id; }) || {label:''}).label );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.scriptTip = '请创建会话,选择' + inviteMember.toString();
|
2020-08-10 16:29:32 +08:00
|
|
|
} else if (val.type == 'Command') {
|
|
|
|
const targetName = this.memberData.find(member=>{ return member.id == val.commandInitiateVO.targetMemberId; });
|
|
|
|
const CommandList = {
|
|
|
|
Drive_Ahead:'确认运行至前方站',
|
|
|
|
Route_Block_Drive:'进路闭塞法行车',
|
|
|
|
Drive_Through_The_Guide_Signal:'越引导信号行驶',
|
|
|
|
Drive_Through_The_Red_Light:'越红灯行驶',
|
|
|
|
Drive_In_Urm_Mode:'URM模式驾驶',
|
|
|
|
Set_Speed_Limit:'设置限速',
|
|
|
|
Open_Or_Close_Door:'开关门',
|
|
|
|
Switch_Hook_Lock: '道岔钩锁'
|
|
|
|
};
|
|
|
|
this.$messageBox('请对【' + targetName.label + '】下达【' + CommandList[val.commandInitiateVO.commandType] + '】指令');
|
2020-07-23 17:51:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 会话聊天消息
|
|
|
|
'$store.state.socket.conversationInfo':function (val, old) { // 仿真聊天
|
|
|
|
const simulationText = this.$store.state.socket.conversationInfo;
|
|
|
|
if (val.messageType == 'MESSAGE' && (this.conversitionId == val.id || this.userRole == 'AUDIENCE')) {
|
|
|
|
this.chatContentList.push(this.addContent(simulationText.message));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 按计划行车的列车列表更新(更新司机列表)
|
|
|
|
'$store.state.map.activeTrainListChange': function (val) {
|
|
|
|
const activeTrainList = this.$store.state.map.activeTrainList;
|
2020-08-03 19:21:56 +08:00
|
|
|
if (this.driverList.length > 0) {
|
|
|
|
const driverList = [];
|
|
|
|
if (activeTrainList && activeTrainList.length) {
|
|
|
|
activeTrainList.forEach(groupNumber => {
|
|
|
|
const drivers = this.driverList.find(driver=>{
|
|
|
|
return driver.deviceCode == groupNumber;
|
|
|
|
});
|
|
|
|
if (drivers) {
|
|
|
|
driverList.push(drivers);
|
|
|
|
}
|
2020-07-23 17:51:37 +08:00
|
|
|
});
|
2020-08-03 19:21:56 +08:00
|
|
|
}
|
|
|
|
this.treeData[2].children = driverList;
|
|
|
|
} else {
|
|
|
|
this.activeTrainList = activeTrainList;
|
2020-07-23 17:51:37 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
// 剧本执行完成消息
|
|
|
|
'$store.state.socket.scriptFinish':function(val, old) {
|
|
|
|
this.$message('剧本执行完成');
|
|
|
|
},
|
|
|
|
// 退出会话消息
|
|
|
|
'$store.state.socket.overConversition': function (val) {
|
|
|
|
if (val.id === this.conversitionId) {
|
|
|
|
this.conversitionId = '';
|
|
|
|
this.scriptTip = '';
|
|
|
|
this.currentMemberList = [];
|
|
|
|
this.chatContentList = [];
|
|
|
|
this.isHasCoversition = false;
|
|
|
|
this.isStartRecord = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// 邀请会话的消息
|
|
|
|
'$store.state.socket.inviteSimulationConversition':function(val) {
|
|
|
|
const member = this.memberData.find(member=>{ return member.id == val.creatorId; });
|
|
|
|
if (member) {
|
|
|
|
this.inviteUserName = member.label;
|
|
|
|
this.conversitionId = val.id;
|
|
|
|
member.connect = true;
|
2020-08-04 10:24:45 +08:00
|
|
|
member.online = true;
|
2020-07-23 17:51:37 +08:00
|
|
|
this.inviteUser = member;
|
|
|
|
this.$refs.chatbox.inviteMember();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
},
|
|
|
|
methods:{
|
|
|
|
setScriptTip(scriptTip) {
|
|
|
|
this.scriptTip = scriptTip;
|
|
|
|
},
|
|
|
|
addContent(simulationText) {
|
|
|
|
const text = {};
|
|
|
|
const member = this.currentMemberList.find(member=>{
|
|
|
|
return member.id == simulationText.memberId;
|
|
|
|
});
|
|
|
|
if (member) {
|
|
|
|
text.self = (this.$store.state.user.id == member.userId);
|
|
|
|
text.member = member;
|
|
|
|
text.chatTime = simulationText.time;
|
|
|
|
text.src = simulationText.audioPath;
|
|
|
|
text.message = simulationText.content;
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
},
|
|
|
|
clearAllData() {
|
|
|
|
this.resetCoversition();
|
|
|
|
},
|
|
|
|
resetCoversition() {
|
|
|
|
this.conversitionId = '';
|
|
|
|
this.scriptTip = '';
|
|
|
|
this.isHasCoversition = false;
|
|
|
|
this.currentMemberList = [];
|
|
|
|
this.chatContentList = [];
|
|
|
|
this.isStartRecord = false;
|
|
|
|
this.inviteUserName = '';
|
|
|
|
this.createCoversition = true;
|
|
|
|
this.inviteUser = {};
|
|
|
|
this.isQuitShow = false;
|
|
|
|
}
|
2020-08-03 19:21:56 +08:00
|
|
|
// isAudienceInitData() {
|
|
|
|
// getAllConversition(this.group).then(resp => {
|
|
|
|
// const messages = [];
|
|
|
|
// if (resp.data && resp.data.length) {
|
|
|
|
// debugger;
|
|
|
|
// resp.data.forEach(conversation => {
|
|
|
|
// (conversation.messageList || []).forEach(message => {
|
|
|
|
// const member = this.memberData[message.memberId];
|
|
|
|
// message.src = `/audio/${message.audioPath}`;
|
|
|
|
// message.members = conversation.memberList;
|
|
|
|
// if (member) {
|
|
|
|
// message.self = this.$store.state.userId == member.userId;
|
|
|
|
// }
|
|
|
|
// messages.push(message);
|
|
|
|
// });
|
|
|
|
// if (this.userRole !== 'AUDIENCE') {
|
|
|
|
// const user = this.simulationUsers[this.$store.state.user.id];
|
|
|
|
// this.isConversitionCreator = conversation.creatorId == user.memberId;
|
|
|
|
// !conversation.over && conversation.memberList.forEach(member =>{
|
|
|
|
// if (member.memberId == user.memberId && member.connect) {
|
|
|
|
// this.conversitionMemberList = conversation.memberList;
|
|
|
|
// this.conversitionId = conversation.id;
|
|
|
|
// this.messageList = [];
|
|
|
|
// conversation.messageList.forEach(message => {
|
|
|
|
// const member = this.memberData[message.memberId];
|
|
|
|
// message.src = `/audio/${message.audioPath}`;
|
|
|
|
// if (member) {
|
|
|
|
// message.self = this.$store.state.userId == member.userId;
|
|
|
|
// }
|
|
|
|
// this.privateMessageList.push(message);
|
|
|
|
// this.messageList.push(message);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// this.commonMessageList = messages.sort(this.sortByMessageTime);
|
|
|
|
// // this.initCommonMemberList();
|
|
|
|
// });
|
|
|
|
// }
|
2020-07-23 17:51:37 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|