import store from '@/store/index_APP_TARGET'; import { Notification } from 'element-ui'; function handle(state, data) { // console.log(data, 'socket订阅'); const msg = data.body; const path = window.location.href; switch (data.type) { case 'Order_Pay_Result': // 订单支付结果消息 state.payOrder = msg; break; case 'JointTraining_Room': // 综合演练室-房间消息 if (!path.includes('/plan') || !path.includes('/dp/')) { 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_User': // 仿真-聊天界面用户进出仿真消息 handleSimulationUserinfo(state, msg); // 用户进出仿真消息 break; case 'Simulation_Script_Tip': // 仿真-聊天界面用户进出仿真消息 handleSimulationScriptTipInfo(state, msg); // 用户进出仿真消息 break; case 'Simulation_RunFact': // 仿真-列车实际到发车站消息 // let runFactMsg = msg; // if (runFactMsg.constructor !== Array ) { // runFactMsg = [msg]; // } if (!Array.isArray(msg)) { // console.log([msg], '列车实际到发车站消息'); state.trainStationList = [msg]; } break; case 'Simulation_Error': // 仿真-异常消息 state.simulationError = msg; break; case 'Simulation_RunAsPlan_Start': // 仿真-仿真开始按计划行车消息 state.simulationStart = msg; break; case 'Simulation_Reset': // 仿真-仿真重置消息 退出计划行车 state.simulationReset = 'reset'; break; case 'Simulation_Conversation': // 仿真-用户交互消息(聊天/命令) { handleSimulationInfo(state, msg); state.simuConversitionCount++; 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_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++; break; case 'JointTraining_Device': state.realDeviceInfo++; break; case 'Be_Logged_Out': // 重复登录被登出 state.beLogoutCount++; break; case 'Simulation_Run_Plan_Reload': // 运行图变更 state.runPlanReloadCount++; break; case 'Simulation_Control_Pause': // 暂停中 store.dispatch('scriptRecord/updateSimulationPause', msg); break; case 'BROADCAST': // 升级通知消息 Notification.warning({ title: msg.title, center: true, message: msg.message, position: 'bottom-right', showClose: msg.showClose, duration: 0 }); break; } } // 操作聊天信息 function handleRecordList(state, data) { const userId = store.state.user.id; let isSelf = false; if (data.member.id == userId) { isSelf = true; } const myDate = new Date(); const myDate1 = myDate.toLocaleDateString().replace(/\//g, '-'); const param = { join: false, value: data.message, self: isSelf, voice: data.isAudio, src: data.isAudio ? `/jlcloud/audio/${data.audioPath}` : '', other: !isSelf, userName: data.member.nickName, chatTime: data.chatTime, chatInfo: true, inSimulation: false, inRoom: true, date: +new Date(`${myDate1} ${data.chatTime}`) }; state.chatContent = param; } // 仿真内部聊天 function handleSimulationInfo(state, data) { const userId = store.state.user.id; let isSelf = false; if (data.member.userId == userId) { isSelf = true; } const myDate = new Date(); const myDate1 = myDate.toLocaleDateString().replace(/\//g, '-'); const chatTime = /\d{2}:\d{2}:\d{2}/.exec(data.chatTime)[0] || data.chatTime; const params = { id:data.conversationId, self: isSelf, message: data.message, voice: data.isAudio, src: data.isAudio ? `/jlcloud/audio/${data.audioPath}` : '', member:data.member, memberOnline:data.member.online, chatTime: data.chatTime, targetOnline:data.targetMember ? data.targetMember.online : null, targetName:data.targetMember ? data.targetMember : 'All', targetRole:data.targetMember ? data.targetMember.role : null, group: data.group, date: +new Date(`${myDate1} ${chatTime}`) }; state.simulationText = params; } // 剧本提示 function handleSimulationScriptTipInfo(state, data) { state.simulationScriptTip = data; } function handleUserinfo(state, data) { state.roleList = (data instanceof Array) ? data : [data]; } function handleSimulationUserinfo(state, data) { state.simulationRoleList = (data instanceof Array) ? data : [data]; } 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: {}, // 受邀请房间信息 chatContent: {}, // 聊天室聊天内容 roleList: [], // 设置角色信息 simulationRoleList:[], // 设置仿真的聊天角色信息 simulationScriptTip:{}, // 剧本推送提示信息 jointRoomPrepare: false, // 演练房间准备状态 equipmentStatus: [], // 仿真-设备状态消息 trainStationList: [], // 仿真-列车实际到发车站消息 simulationError: '', // 仿真-异常消息 simulationStart: '', // 仿真-开始消息 simulationReset: '', // 仿真-异常消息 simulationText: {}, // 仿真-用户交互消息(聊天/命令) // coversitionList:{}, // 历史仿真-用户消息列表 message: {}, // 仿真聊天 msgQueue: [], // 命令请求列表 msgHead: null, // 消息头 userPermit: {}, // 用户获取权限消息 userRoomKickOut: {}, // 用户被踢出房间消息 userInRoom: {}, // 用户从外部进入房间消息 userOutRoom: {}, // 用户退出房间消息 userInSimulation: {}, // 用户进入仿真消息 userBackRoom: {}, // 用户从仿真返回房间消息 roomInvite: {}, // 用户扫码信息 permissionOver: {}, // 权限结束 roomIsSubscribe:false, // 房间是否订阅 assistantIsSubscribe:false, // 综合演练仿真聊天是否订阅 isInRoom:false, // 是否己经进入房间 tipOperateCount: 0, // 任务结束提示消息 realDeviceInfo: 0, // 真实设备信息 beLogoutCount: 0, // 被登出 runPlanReloadCount: 0 // 仿真运行图变更 }, getters: { }, mutations: { setJointRoomInfo: (state, jointRoomInfo) => { state.jointRoomInfo = jointRoomInfo; }, setChatContent: (state, chatContent) => { state.chatContent = chatContent; }, 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; }, setRoomSubscribe:(state, roomIsSubscribe)=>{ state.roomIsSubscribe = roomIsSubscribe; }, setAssistantSubscribe:(state, assistantIsSubscribe)=>{ state.assistantIsSubscribe = assistantIsSubscribe; }, setInRoom:(state, isInRoom)=>{ state.isInRoom = isInRoom; } }, actions: { setStomp: ({ state }, res) => { handle(state, res); }, setChatContent: ({ commit }, chatContent) => { commit('setChatContent', chatContent); }, 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); }, setRoomSubscribe:({ commit }, msg) => { commit('setRoomSubscribe', msg); }, setAssistantSubscribe:({ commit }, msg) => { commit('setAssistantSubscribe', msg); }, setInRoom:({ commit }, msg) => { commit('setInRoom', msg); } } }; export default socket;