2019-07-26 13:32:43 +08:00
|
|
|
|
|
|
|
import store from '@/store';
|
|
|
|
|
|
|
|
function handle(state, data) {
|
2019-07-26 17:13:03 +08:00
|
|
|
// console.log(data, 'socket订阅');
|
|
|
|
let msg = data.body;
|
|
|
|
switch (data.type) {
|
|
|
|
case 'Order_Pay_Result': { // 订单支付结果消息
|
|
|
|
state.payOrder = msg;
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_Room': { // 综合演练室-房间消息
|
|
|
|
state.jointRoomInfo = msg; // 房间信息
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_User': { // 综合演练室-用户消息
|
|
|
|
handleUserinfo(state, msg); // 分配角色权限消息
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_Chat': { // 综合演练室-群聊消息
|
|
|
|
handleRecordList(state, msg);
|
|
|
|
} break;
|
|
|
|
case 'Simulation_DeviceStatus': { // 仿真-设备状态消息
|
|
|
|
state.equipmentStatus = msg;
|
|
|
|
} break;
|
|
|
|
case 'Simulation_RunFact': { // 仿真-列车实际到发车站消息
|
|
|
|
state.trainStationList = msg;
|
|
|
|
} break;
|
|
|
|
case 'Simulation_Error': { // 仿真-异常消息
|
|
|
|
state.simulationError = msg;
|
|
|
|
} break;
|
|
|
|
case 'Simulation_RunAsPlan_Start': { // 仿真-仿真开始按计划行车消息
|
|
|
|
state.simulationStart = msg;
|
|
|
|
} break;
|
|
|
|
case 'Simulation_Reset': { // 仿真-仿真重置消息 退出计划行车
|
|
|
|
state.simulationReset = msg;
|
|
|
|
} break;
|
|
|
|
case 'Simulation_Conversation': { // 仿真-用户交互消息(聊天/命令)
|
|
|
|
handleSimulationInfo(state, msg);
|
|
|
|
} break;
|
|
|
|
case 'Simulation_PlayBack_Conversation': {// 回放-用户交互消息
|
|
|
|
handleSimulationInfo(state, msg);
|
|
|
|
} break;
|
|
|
|
case 'Simulation_ApplyHandle': { // 请求处理消息
|
|
|
|
handlePushMsgQueue(state, msg);
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_User_Permit': { // 综合演练室-用户获取权限消息
|
|
|
|
state.userPermit = msg;
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_User_RoomKickOut': { // 综合演练室-用户被踢出房间消息
|
|
|
|
state.userRoomKickOut = msg; // 没有给被踢用户发送
|
|
|
|
handleMessageInfo(state, 'userRoomKickOut', msg);
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_User_InRoom': { // 综合演练室-用户从外部进入房间消息
|
|
|
|
state.userInRoom = msg;
|
|
|
|
handleMessageInfo(state, 'userInRoom', msg);
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_User_OutRoom': { // 综合演练室-用户退出房间消息
|
|
|
|
state.userOutRoom = msg;
|
|
|
|
handleMessageInfo(state, 'userOutRoom', msg);
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_User_InSimulation': { // 综合演练室-用户进入仿真消息
|
|
|
|
state.userInSimulation = msg;
|
|
|
|
handleMessageInfoSimulation(state, 'userInSimulation', msg);
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_User_BackRoom': { // 综合演练室-用户从仿真返回房间消息
|
|
|
|
state.userBackRoom = msg;
|
|
|
|
handleMessageInfoSimulation(state, 'userBackRoom', msg);
|
|
|
|
} break;
|
|
|
|
case 'JointTraining_Room_Invite': { // 综合演练室-房间邀请消息
|
|
|
|
state.roomInvite = msg;
|
|
|
|
} break;
|
|
|
|
case 'Big_Screen_Simulation_DeviceStatus': { //大屏仿真状态数据
|
|
|
|
state.equipmentStatus = msg;
|
|
|
|
} break;
|
|
|
|
case 'Big_Screen_Simulation_RunFact': { //大屏仿真运行图状态
|
|
|
|
state.trainStationList = msg;
|
|
|
|
} break;
|
|
|
|
case 'Plan_Simulation_DeviceStatus': { //大屏仿真状态数据
|
|
|
|
state.equipmentStatus = msg;
|
|
|
|
} break;
|
|
|
|
case 'Plan_Simulation_RunFact': { //大屏仿真运行图状态
|
|
|
|
state.trainStationList = msg;
|
|
|
|
} break;
|
|
|
|
case 'Simulation_Permission_Over': { //权限结束
|
|
|
|
state.permissionOver = msg;
|
|
|
|
} break;
|
|
|
|
case 'Simulation_Quest_Finish': { //任务结束标志
|
|
|
|
state.tipOperateCount++;
|
|
|
|
}
|
|
|
|
}
|
2019-07-26 13:32:43 +08:00
|
|
|
}
|
|
|
|
// 操作聊天信息
|
|
|
|
function handleRecordList(state, data) {
|
|
|
|
let userId = store.state.user.id;
|
|
|
|
let isSelf = false;
|
|
|
|
if (data.member.id == userId) {
|
|
|
|
isSelf = true;
|
|
|
|
}
|
|
|
|
let myDate = new Date();
|
|
|
|
let myDate1 = myDate.toLocaleDateString().replace(/\//g, "-");
|
|
|
|
let param = {
|
|
|
|
join: false,
|
|
|
|
value: data.message,
|
|
|
|
self: isSelf,
|
|
|
|
voice: data.isAudio,
|
2019-07-26 17:13:03 +08:00
|
|
|
src: data.isAudio ? `${process.env.process.env.VUE_VOICE_API}/jlcloud/audio/${data.audioPath}` : '',
|
2019-07-26 13:32:43 +08:00
|
|
|
other: !isSelf,
|
|
|
|
userName: data.member.nickName,
|
|
|
|
chatTime: data.chatTime,
|
|
|
|
chatInfo: true,
|
|
|
|
inSimulation: false,
|
|
|
|
inRoom: true,
|
|
|
|
date: +new Date(`${myDate1} ${data.chatTime}`),
|
|
|
|
};
|
|
|
|
state.chatContentList = param;
|
|
|
|
}
|
|
|
|
// 仿真内部聊天
|
|
|
|
function handleSimulationInfo(state, data) {
|
|
|
|
let userId = store.state.user.id;
|
|
|
|
let isSelf = false;
|
|
|
|
if (data.member.userId == userId) {
|
|
|
|
isSelf = true;
|
|
|
|
}
|
|
|
|
let role = '';
|
|
|
|
switch (data.member.role) {
|
|
|
|
case '01': {
|
|
|
|
role = '管理员';
|
|
|
|
} break;
|
|
|
|
case '02': {
|
|
|
|
role = '教员';
|
|
|
|
} break;
|
|
|
|
case '03': {
|
|
|
|
role = `调度员`;
|
|
|
|
} break;
|
|
|
|
case '04': {
|
|
|
|
store.state.map.map.stationList.forEach(nor => {
|
|
|
|
if (nor.code == data.member.deviceCode) {
|
|
|
|
role = `${nor.name}`;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
if (!data.member.userId && data.member.deviceName) {
|
|
|
|
data.member.nickName = data.member.deviceName;
|
|
|
|
}
|
|
|
|
if (!data.targetMember.userId && data.targetMember.deviceName) {
|
|
|
|
data.targetMember.nickName = data.targetMember.deviceName;
|
|
|
|
}
|
|
|
|
let myDate = new Date();
|
|
|
|
let myDate1 = myDate.toLocaleDateString().replace(/\//g, "-");
|
|
|
|
let chatTime = /\d{2}:\d{2}:\d{2}/.exec(data.chatTime)[0] || data.chatTime;
|
|
|
|
let param = {
|
|
|
|
join: false,
|
|
|
|
value: data.message,
|
|
|
|
self: isSelf,
|
|
|
|
voice: data.isAudio,
|
2019-07-26 17:13:03 +08:00
|
|
|
src: data.isAudio ? `${process.env.process.env.VUE_VOICE_API}/jlcloud/audio/${data.audioPath}` : '',
|
2019-07-26 13:32:43 +08:00
|
|
|
other: !isSelf,
|
|
|
|
userName: '',
|
|
|
|
id: data.member.id,
|
|
|
|
chatTime: data.chatTime,
|
|
|
|
date: +new Date(`${myDate1} ${chatTime}`),
|
|
|
|
conversationId: data.conversationId,
|
|
|
|
changeVO: data.changeVO || {},
|
|
|
|
targetMember: data.targetMember,
|
|
|
|
member: data.member,
|
|
|
|
group: data.group,
|
|
|
|
};
|
|
|
|
if (data.member.role) {
|
|
|
|
param.userName = `${role}【${data.member.nickName}】`;
|
|
|
|
} else {
|
|
|
|
param.userName = `${data.member.nickName}`;
|
|
|
|
}
|
|
|
|
state.simulationText = param;
|
|
|
|
}
|
|
|
|
function handleUserinfo(state, data) {
|
|
|
|
if (data.length) { // 分配角色信息
|
|
|
|
state.roleInfo = data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function handleMessageInfo(state, type, data) {
|
|
|
|
let message = {
|
|
|
|
join: true,
|
|
|
|
id: data.id,
|
|
|
|
userName: data.nickName,
|
|
|
|
userRole: data.userRole,
|
|
|
|
name: data.name,
|
|
|
|
roomTip: '',
|
|
|
|
chatInfo: true,
|
|
|
|
inSimulation: data.inSimulation,
|
|
|
|
inRoom: data.inRoom,
|
|
|
|
session: 'session',
|
|
|
|
type: type,
|
|
|
|
oneself: data.id === store.state.user.id,
|
|
|
|
};
|
|
|
|
switch (type) {
|
|
|
|
case 'userInRoom': {
|
|
|
|
message.roomTip = `${data.nickName}进入房间`;
|
|
|
|
} break;
|
|
|
|
case 'userRoomKickOut': {
|
|
|
|
message.roomTip = `${data.nickName}被踢出房间`;
|
|
|
|
} break;
|
|
|
|
case 'userOutRoom': {
|
|
|
|
message.roomTip = `${data.nickName}退出房间`;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
state.chatContentList = message;
|
|
|
|
}
|
|
|
|
function handleMessageInfoSimulation(state, type, data) {
|
|
|
|
let message = {
|
|
|
|
join: true,
|
|
|
|
id: data.id,
|
|
|
|
userName: data.nickName,
|
|
|
|
userRole: data.userRole,
|
|
|
|
name: data.name,
|
|
|
|
simulationTip: '',
|
|
|
|
chatInfo: true,
|
|
|
|
inSimulation: data.inSimulation,
|
|
|
|
inRoom: data.inRoom,
|
|
|
|
session: 'session',
|
|
|
|
};
|
|
|
|
switch (type) {
|
|
|
|
case 'userInSimulation': {
|
|
|
|
message.simulationTip = `${data.nickName}进入仿真`;
|
|
|
|
} break;
|
|
|
|
case 'userBackRoom': {
|
|
|
|
message.simulationTip = `${data.nickName}退出仿真`;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
state.chatContentSimuList = message;
|
|
|
|
}
|
|
|
|
function handlePushMsgQueue(state, msg) {
|
|
|
|
if (msg instanceof Array) {
|
|
|
|
state.msgQueue.concat(msg);
|
|
|
|
} else {
|
|
|
|
state.msgQueue.push(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!state.msgHead) {
|
|
|
|
state.msgHead = state.msgQueue[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const socket = {
|
|
|
|
namespaced: true,
|
|
|
|
|
|
|
|
state: {
|
|
|
|
payOrder: {}, // 支付消息
|
|
|
|
jointRoomInfo: {}, // 受邀请房间信息
|
|
|
|
chatContentList: {}, // 聊天室聊天内容
|
|
|
|
roleInfo: [], // 设置角色信息
|
|
|
|
jointRoomPrepare: false, // 演练房间准备状态
|
|
|
|
equipmentStatus: [], // 仿真-设备状态消息
|
|
|
|
trainStationList: [], // 仿真-列车实际到发车站消息
|
|
|
|
simulationError: '', // 仿真-异常消息
|
|
|
|
simulationStart: '', // 仿真-开始消息
|
|
|
|
simulationReset: '', // 仿真-异常消息
|
|
|
|
simulationText: {}, // 仿真-用户交互消息(聊天/命令)
|
|
|
|
message: {}, // 仿真聊天
|
|
|
|
msgQueue: [], //命令请求列表
|
|
|
|
msgHead: null, //消息头
|
|
|
|
|
|
|
|
userPermit: {}, // 用户获取权限消息
|
|
|
|
userRoomKickOut: {}, // 用户被踢出房间消息
|
|
|
|
userInRoom: {}, // 用户从外部进入房间消息
|
|
|
|
userOutRoom: {}, // 用户退出房间消息
|
|
|
|
userInSimulation: {}, // 用户进入仿真消息
|
|
|
|
userBackRoom: {}, // 用户从仿真返回房间消息
|
|
|
|
roomInvite: {}, // 用户扫码信息
|
|
|
|
chatContentSimuList: {}, // 进入仿真,离开仿真信息
|
|
|
|
|
|
|
|
permissionOver: {}, // 权限结束
|
|
|
|
|
|
|
|
tipOperateCount: 0 // 任务结束提示消息
|
|
|
|
},
|
|
|
|
|
|
|
|
getters: {
|
|
|
|
},
|
|
|
|
mutations: {
|
|
|
|
setJointRoomInfo: (state, jointRoomInfo) => {
|
|
|
|
state.jointRoomInfo = jointRoomInfo;
|
|
|
|
},
|
|
|
|
|
|
|
|
setChatContentList: (state, chatContentList) => {
|
|
|
|
state.chatContentList = chatContentList;
|
|
|
|
},
|
|
|
|
|
|
|
|
setEquipmentStatus: (state, equipmentStatus) => {
|
|
|
|
state.equipmentStatus = equipmentStatus;
|
|
|
|
},
|
|
|
|
|
|
|
|
setTrainStationList: (state, trainStationList) => {
|
|
|
|
state.trainStationList = trainStationList;
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationError: (state, simulationError) => {
|
|
|
|
state.simulationError = simulationError;
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationStart: (state, simulationStart) => {
|
|
|
|
state.simulationStart = simulationStart;
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationReset: (state, simulationReset) => {
|
|
|
|
state.simulationReset = simulationReset;
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationTextList: (state, simulationText) => {
|
|
|
|
state.simulationText = simulationText;
|
|
|
|
},
|
|
|
|
|
|
|
|
setPayOrder: (state, payOrder) => {
|
|
|
|
state.payOrder = payOrder;
|
|
|
|
},
|
|
|
|
|
|
|
|
shiftMsgQueue: (state) => {
|
|
|
|
state.msgHead = null;
|
|
|
|
state.msgQueue.shift();
|
|
|
|
state.msgHead = state.msgQueue[0];
|
|
|
|
},
|
|
|
|
pushMsgQueue: (state, msg) => {
|
|
|
|
handlePushMsgQueue(state, msg);
|
|
|
|
},
|
|
|
|
|
|
|
|
setRoomInvite: (state, roomInvite) => {
|
|
|
|
state.roomInvite = roomInvite;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
setStomp: ({ state }, res) => {
|
|
|
|
handle(state, res);
|
|
|
|
},
|
|
|
|
|
|
|
|
setChatContentList: ({ commit }, chatContentList) => {
|
|
|
|
commit('setChatContentList', chatContentList);
|
|
|
|
},
|
|
|
|
|
|
|
|
setJointRoomInfo: ({ commit }) => {
|
|
|
|
commit('setJointRoomInfo', {});
|
|
|
|
},
|
|
|
|
|
|
|
|
setEquipmentStatus: ({ commit }) => {
|
|
|
|
commit('setEquipmentStatus', []);
|
|
|
|
},
|
|
|
|
|
|
|
|
setTrainStationList: ({ commit }) => {
|
|
|
|
commit('setTrainStationList', []);
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationError: ({ commit }) => {
|
|
|
|
commit('setSimulationError', '');
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationStart: ({ commit }) => {
|
|
|
|
commit('setSimulationStart', '');
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationReset: ({ commit }) => {
|
|
|
|
commit('setSimulationReset', '');
|
|
|
|
},
|
|
|
|
|
|
|
|
setSimulationTextList: ({ commit }) => {
|
|
|
|
commit('setSimulationTextList', {});
|
|
|
|
},
|
|
|
|
|
|
|
|
setRoomInvite: ({ commit }) => {
|
|
|
|
commit('setRoomInvite', {});
|
|
|
|
},
|
|
|
|
|
|
|
|
setMessage: ({ state }, data) => {
|
|
|
|
if (!state.message[data.key]) {
|
|
|
|
state.message[data.key] = [];
|
|
|
|
}
|
|
|
|
state.message[data.key].push(data.value);
|
|
|
|
},
|
|
|
|
|
|
|
|
setPayOrder: ({ commit }) => {
|
|
|
|
commit('setPayOrder', {});
|
|
|
|
},
|
|
|
|
|
|
|
|
shiftMsgQueue: ({ commit }) => {
|
|
|
|
commit('shiftMsgQueue');
|
|
|
|
},
|
|
|
|
|
|
|
|
pushMsgQueue: ({ commit }, msg) => {
|
|
|
|
commit('pushMsgQueue', msg);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
export default socket;
|