rt-sim-training-client/src/views/trainRoom/index.vue

385 lines
12 KiB
Vue
Raw Normal View History

2019-07-26 13:32:43 +08:00
<template>
2019-11-08 09:02:18 +08:00
<div class="room">
<div class="room__head">
<div class="room__head--title">
{{ $t('trainRoom.comprehensiveDrillRoom') }}
2019-10-18 17:15:04 +08:00
</div>
2019-11-08 09:02:18 +08:00
<div class="room__head--notes">
2019-11-08 18:15:52 +08:00
{{ $t('trainRoom.comprehensiveTrainingManager') + room.creator.nickName }}
2019-10-18 17:15:04 +08:00
</div>
</div>
2019-11-08 09:02:18 +08:00
<div class="room__container">
2019-11-08 18:15:52 +08:00
<e-members
class="room__container--members"
:room="room"
:members="members"
:height="height"
@message="messageInfo"
/>
<e-roles
class="room__container--roles"
:room="room"
:members="members"
:height="height"
:station-list="stationList"
:stand-list="standList"
:door-list="doorList"
@message="messageInfo"
@joinTraining="jumpInSimulation"
2020-01-15 13:20:48 +08:00
@clearSubscribe="clearSubscribe"
2019-11-08 18:15:52 +08:00
/>
<e-chat
class="room__container--chat"
:room="room"
:members="members"
:height="height"
@message="messageInfo"
/>
2019-07-26 13:32:43 +08:00
</div>
2019-11-08 09:02:18 +08:00
<div class="room__footer" />
2019-10-18 17:15:04 +08:00
</div>
2019-07-26 13:32:43 +08:00
</template>
<script>
2020-01-15 13:20:48 +08:00
import { getToken } from '@/utils/auth';
import { creatSubscribe, clearSubscribe, roomTopic} from '@/utils/stomp';
2019-11-08 09:02:18 +08:00
import eMembers from './e-members';
import eChat from './e-chat';
import eRoles from './e-roles';
import { postRoomDetail, getJointTrainRoomUserList, getRealDevices, putJointTrainingSimulationEntrance, getjointTraining } from '@/api/chat';
2020-03-16 15:29:26 +08:00
import { postRoomDetailNew, getJointTrainRoomUserListNew, putJointTrainingSimulationEntranceNew, getjointTrainingNew, getRealDevicesNew} from '@/api/jointTraining';
2019-11-08 18:15:52 +08:00
import { getPublishMapInfo, hasDoorStationList } from '@/api/jmap/map';
import { launchFullscreen } from '@/utils/screen';
2019-10-18 17:15:04 +08:00
import { getStationList } from '@/api/runplan';
2019-11-08 18:15:52 +08:00
import { checkLoginLine } from '@/api/login';
2019-07-26 13:32:43 +08:00
2019-10-18 17:15:04 +08:00
export default {
2019-10-30 19:36:26 +08:00
components: {
2019-11-08 09:02:18 +08:00
eMembers,
eChat,
eRoles
2019-10-30 19:36:26 +08:00
},
data() {
return {
2019-11-08 09:02:18 +08:00
room: {
2019-11-08 18:15:52 +08:00
totalNum: 0,
2019-10-30 19:36:26 +08:00
group: '',
2019-11-08 09:02:18 +08:00
mapId: '',
2019-11-08 18:15:52 +08:00
creatorId: '',
creator: {
nickName: ''
2019-11-08 09:02:18 +08:00
},
2019-11-08 18:15:52 +08:00
permissionRest: 0,
permissionNum: 0,
state: ''
},
userMap: [],
members: [],
stationList: [],
standList: [],
doorList: [],
timer: null
2019-10-30 19:36:26 +08:00
};
},
computed: {
height() {
2019-11-08 09:02:18 +08:00
return this.$store.state.app.height - 100;
2019-10-30 19:36:26 +08:00
},
2019-11-08 18:15:52 +08:00
group() {
return this.$route.query.group;
},
2020-03-16 15:29:26 +08:00
drawWay() {
return this.$route.query.drawWay;
},
2019-11-08 09:02:18 +08:00
userId() {
2019-11-08 18:15:52 +08:00
return this.$store.state.user ? this.$store.state.user.id : '';
}
},
watch: {
members: {
deep: true,
handler() {
this.room.permissionRest = this.members.filter(elem => ['Audience'].includes(elem.userRole)).length;
}
},
// 用户信息
'$store.state.socket.roleList': async function (val) {
if (val.length) {
await this.dispatchUsers(val);
}
},
// 房间消息
'$store.state.socket.jointRoomInfo': async function (val) {
if (val.creatorId) {
await this.dispatchRoomInfo(val);
2019-10-30 19:36:26 +08:00
}
2019-11-08 18:15:52 +08:00
},
// 设备信息
'$store.state.socket.realDeviceInfo': async function (val) {
await this.getStandList();
},
// 路由切换
'$route': async function() {
await this.loadInit();
2019-10-30 19:36:26 +08:00
}
},
2019-11-08 18:15:52 +08:00
async created() {
await this.loadInit();
2019-10-30 19:36:26 +08:00
},
methods: {
async loadInit() {
2020-01-15 13:20:48 +08:00
await this.subscribe();
2020-03-16 15:29:26 +08:00
if (!this.$store.state.socket.setInRoom && !this.drawWay) {
await getjointTraining(this.group);
2020-03-16 15:29:26 +08:00
} else if (!this.$store.state.socket.setInRoom && this.drawWay) {
await getjointTrainingNew(this.group);
}
await this.getRoomInfo();
await this.getUserList();
await this.getStandList();
await this.getStaionList(this.room.mapId);
await this.getDoorList(this.room.mapId, this.stationList);
if (this.timer) { clearInterval(this.timer); }
this.timer = setInterval(() => {
checkLoginLine();
}, 5000 * 60);
},
2019-11-08 18:15:52 +08:00
async getRoomInfo() {
2020-03-16 15:29:26 +08:00
let resp = '';
if (this.drawWay) {
resp = await postRoomDetailNew(this.group);
} else {
resp = await postRoomDetail(this.group);
}
2019-11-08 09:02:18 +08:00
this.room = {
2019-11-08 18:15:52 +08:00
permissionRest: 0,
totalNum: Number(resp.data.permissionNum) + Number(resp.data.audiencePermissionNum),
...resp.data || {}
2019-10-30 19:36:26 +08:00
};
2019-11-08 18:15:52 +08:00
},
async getStandList() {
2020-03-16 15:29:26 +08:00
let resp = '';
if (this.drawWay) {
resp = await getRealDevicesNew(this.group);
} else {
resp = await getRealDevices(this.group);
}
2019-11-08 18:15:52 +08:00
this.standList = resp.data || [];
},
async getStaionList(mapId) {
const resp = await getStationList(mapId);
this.stationList = resp.data || [];
},
async getDoorList(mapId, stationList) {
const doorList = [];
hasDoorStationList(mapId).then(res =>{
stationList.forEach(item => {
res.data.forEach(it =>{
if (item.code === it.stationCode) {
const direction = parseInt(it.doorLocationType) % 2 === 0 ? this.$t('trainRoom.uplinkPlatform') : this.$t('trainRoom.downlinkPlatform');
doorList.push({code: it.code, name: item.name + direction});
}
});
});
this.doorList = doorList;
}).catch(() => {
this.$messageBox(this.$t('error.getScreenDoorsListFailed'));
});
},
async getUserList() {
2020-03-16 15:29:26 +08:00
let res = '';
if (this.drawWay) {
res = await getJointTrainRoomUserListNew(this.group);
} else {
res = await getJointTrainRoomUserList(this.group);
}
2019-11-08 18:15:52 +08:00
this.members = (res.data || []).map(elem => { return this.transformUser(elem); });
},
async dispatchUsers(users) {
users.forEach(user => {
const index = this.members.findIndex(elem => { return user.id == elem.id; });
if (user.userRole) {
if (index >= 0) {
2019-11-08 19:32:21 +08:00
this.checkUserState(user, this.members[index]);
2019-11-12 14:56:53 +08:00
this.members.splice(index, 1, this.transformUser(user));
2019-11-08 18:15:52 +08:00
} else {
2019-11-08 19:32:21 +08:00
this.checkUserState(user, null);
2019-11-08 18:15:52 +08:00
this.members.push(this.transformUser(user));
}
} else {
2020-01-16 16:15:58 +08:00
if (this.members[index]) {
this.checkUserState(user, this.members[index]);
this.members.splice(index, 1);
}
2019-11-08 18:15:52 +08:00
}
});
},
async dispatchRoomInfo(room) {
Object.assign(this.room, room);
switch (room.state) {
case '03': // 房间销毁
2020-01-15 13:20:48 +08:00
{ this.clearSubscribe();
2019-11-25 18:21:56 +08:00
this.$router.go(-1);
2020-01-15 13:20:48 +08:00
break; }
2019-11-08 18:15:52 +08:00
case '02': // 开始仿真
2020-01-15 13:20:48 +08:00
{
// this.clearSubscribe();
2019-11-25 18:21:56 +08:00
await this.jumpInSimulation();
2020-01-15 13:20:48 +08:00
break; }
2019-11-08 18:15:52 +08:00
}
// 清空房间信息
this.$store.dispatch('socket/setJointRoomInfo');
},
2019-11-08 19:32:21 +08:00
async checkUserState(user, old) {
const message = {
join: true,
id: user.id,
userName: user.nickName,
userRole: user.userRole,
name: user.name,
roomTip: '',
chatInfo: true,
inSimulation: user.inSimulation,
inRoom: user.inRoom,
session: 'session',
oneself: user.id === this.$store.state.user.id
};
if (old) {
2019-11-12 13:39:52 +08:00
if (!user.userRole) {
this.$store.dispatch('socket/setChatContent', {...message, roomTip: `${user.nickName}被提出房间`});
if (this.userId == user.id) {
2019-11-25 18:21:56 +08:00
await this.jumpOutRoom();
2019-11-12 13:39:52 +08:00
}
} else if (old.userRole) {
2019-11-12 14:56:53 +08:00
if (old.inRoom && !user.inRoom) {
2019-11-12 13:39:52 +08:00
this.$store.dispatch('socket/setChatContent', {...message, roomTip: `${user.nickName}离线`});
2019-11-08 19:32:21 +08:00
if (this.userId == user.id) {
2019-11-25 18:21:56 +08:00
await this.jumpOutRoom();
2019-11-08 19:32:21 +08:00
}
}
if (!old.inRoom && user.inRoom) {
2019-11-12 13:39:52 +08:00
this.$store.dispatch('socket/setChatContent', {...message, roomTip: `${user.nickName}在线`});
2019-11-08 18:15:52 +08:00
}
2019-12-05 18:01:09 +08:00
if (!old.inSimulation && user.inSimulation) {
2019-11-08 19:32:21 +08:00
this.$store.dispatch('socket/setChatContent', {...message, roomTip: `${user.nickName}进入仿真`});
if (this.userId == user.id) {
2019-11-25 18:21:56 +08:00
await this.jumpInSimulation();
2019-11-08 19:32:21 +08:00
}
}
2019-11-08 18:15:52 +08:00
}
2019-11-08 19:32:21 +08:00
} else {
this.$store.dispatch('socket/setChatContent', {...message, roomTip: `${user.nickName}进入房间`});
2019-11-08 18:15:52 +08:00
}
},
async jumpInSimulation() {
const room = this.room;
2020-03-16 15:29:26 +08:00
if (this.drawWay) {
await putJointTrainingSimulationEntranceNew(room.group);
} else {
await putJointTrainingSimulationEntrance(room.group);
}
2019-11-08 18:15:52 +08:00
const rest = await getPublishMapInfo(room.mapId);
2020-01-03 11:18:18 +08:00
const query = { lineCode: rest.data.lineCode, mapId: room.mapId, group: room.group, roomId: room.id };
if (this.$route.query.drawWay) {
this.$router.replace({ path: `/jointTrainingNew`, query: query});
} else {
this.$router.replace({ path: `/jointTraining`, query: query });
}
2019-11-08 18:15:52 +08:00
// 清空房间信息
this.$store.dispatch('socket/setJointRoomInfo');
2019-11-25 18:21:56 +08:00
launchFullscreen();
2019-11-08 18:15:52 +08:00
},
async jumpOutRoom() {
2019-11-25 18:21:56 +08:00
this.$router.go(-1);
2019-11-08 18:15:52 +08:00
this.messageInfo({error: 'warning', message: this.$t('tip.beKickedOut')});
},
transformUser(user) {
// 根据用户角色专用数据数据
switch (user.userRole) {
case 'IBP':
user.deviceCode = [user.deviceCode || '', user.ibpPart || ''];
break;
}
2019-07-26 13:32:43 +08:00
2019-11-08 18:15:52 +08:00
return user;
},
messageInfo(info) {
this.$message({ showClose: true, ...info });
2020-01-15 13:20:48 +08:00
},
async subscribe() {
if (!this.$store.state.socket.roomIsSubscribe) {
this.clearSubscribe();
const header = { group: this.group || '', 'X-Token': getToken() };
creatSubscribe(`${roomTopic}\/${this.group}`, header);
await this.$store.dispatch('socket/setRoomSubscribe', true);
}
},
async clearSubscribe() {
clearSubscribe(`${roomTopic}\/${this.group}`);
await this.$store.dispatch('socket/setRoomSubscribe', false);
2019-10-30 19:36:26 +08:00
}
}
2019-10-18 17:15:04 +08:00
};
2019-07-26 13:32:43 +08:00
</script>
<style scoped lang="scss">
2019-11-08 09:02:18 +08:00
.room {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
background: #f0f0f0;
&__head {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background: #000;
color: #fff;
padding: 10px;
position: relative;
&--title {
font-size: 22px;
font-weight: bold;
}
&--notes {
position: absolute;
left: 10px;
bottom: 5px;
}
}
&__container {
display: flex;
flex-grow: 1;
padding: 10px;
&--members {
flex-shrink: 1;
flex-grow: 1;
}
&--roles {
flex-grow: 5;
flex-shrink: 5;
}
&--chat {
flex-basis: 360px;
}
}
&__footer {
height: 20px;
}
}
2019-07-26 13:32:43 +08:00
</style>