rt-sim-training-client/src/views/trainRoom/e-roles.vue

563 lines
19 KiB
Vue
Raw Normal View History

2019-11-08 09:13:38 +08:00
<template>
<div class="roles">
<div class="roles__head">
<div class="roles__head--title">
<div class="label">人员分配</div>
<div class="notes">{{ room.permissionRest }} / {{ room.permissionNum - 1 }}</div>
</div>
<div class="roles__head--reset">
2019-11-08 20:25:04 +08:00
<!--<el-button size="mini" round>重置</el-button>-->
2019-11-08 09:13:38 +08:00
</div>
</div>
<div class="roles__container">
<el-scrollbar wrap-class="scrollbar-wrapper" :style="{height: rolesHeight+'px', width: '100%'}">
<div class="roles">
2019-11-08 18:15:52 +08:00
<e-role
class="role"
title-i18n="trainRoom.dispatcher"
role-type="Dispatcher"
:room="room"
:options="dispatcherList"
@addUser="handleAddUser"
@changeUser="handleUpdUser"
@delUser="handleDelUser"
/>
<e-role
class="role"
title-i18n="trainRoom.stationAttendant"
role-type="Attendant"
:room="room"
:options="attendantList"
:device-list="stationListForAttendant"
@addUser="handleAddUser"
@changeUser="handleUpdUser"
@delUser="handleDelUser"
/>
<e-role
class="role"
title-i18n="trainRoom.teacher"
role-type="Instructor"
:room="room"
:options="instructorList"
@addUser="handleAddUser"
@changeUser="handleUpdUser"
@delUser="handleDelUser"
/>
<e-role
class="role"
title-i18n="trainRoom.universalAccount"
role-type="Repair"
:room="room"
:options="repairList"
@addUser="handleAddUser"
@changeUser="handleUpdUser"
@delUser="handleDelUser"
/>
<e-role
class="role"
title-i18n="trainRoom.driver"
role-type="Driver"
:room="room"
:options="driverList"
@addUser="handleAddUser"
@changeUser="handleUpdUser"
@delUser="handleDelUser"
/>
<e-role
class="role"
title-i18n="trainRoom.ibp"
role-type="IBP"
:room="room"
:options="ibpList"
:device-list="stationListForIBP"
@addUser="handleAddUser"
@changeUser="handleUpdUser"
@delUser="handleDelUser"
/>
<e-role
v-if="isGzbProject"
class="role"
title-i18n="trainRoom.interlock"
role-type="CI"
:room="room"
:options="ciList"
@addUser="handleAddUser"
@changeUser="handleUpdUser"
@delUser="handleDelUser"
/>
2019-11-08 18:15:52 +08:00
<e-device
2020-01-03 11:18:18 +08:00
v-if="isXtyProject"
2019-11-08 18:15:52 +08:00
class="role"
title-i18n="trainRoom.realDevice"
device-type="StationStand"
:room="room"
:options="standList"
:device-list="doorList"
:has-plc="hasPlc"
@addDevice="handleAddDevice"
@changeDevice="handleUpdDevice"
@delDevice="handleDelDevice"
/>
2019-11-08 09:13:38 +08:00
</div>
</el-scrollbar>
</div>
<div class="roles__footer">
2019-11-25 18:21:56 +08:00
<el-button v-if="userId == room.creatorId" style="margin-left: 10px" type="danger" :disabled="disabled" @click="handleExit">{{ $t('trainRoom.destroyRoom') }}</el-button>
2020-03-31 18:50:16 +08:00
<el-button v-if="userId == room.creatorId && !isLocal" style="margin-left: 10px" type="success" :disabled="disabled" @click="handlePostQrcode">{{ $t('trainRoom.generatingQRCode') }}</el-button>
<el-button v-if="userId == room.creatorId && isLocal" style="margin-left: 10px" type="success" :disabled="disabled" @click="handleGetGroup">{{ $t('trainRoom.getGroupId') }}</el-button>
2019-11-08 09:13:38 +08:00
<template v-if="!starting">
2019-11-25 18:21:56 +08:00
<el-button v-if="userId == room.creatorId" style="margin-left: 10px" type="primary" :disabled="disabled" @click="handleStart"> {{ $t('trainRoom.startSimulation') }}</el-button>
2019-11-08 09:13:38 +08:00
</template>
<template v-else>
2019-11-25 18:21:56 +08:00
<el-button type="primary" style="margin-left: 10px" :disabled="disabled" @click="handleJoin"> {{ $t('trainRoom.enterSimulation') }}</el-button>
<el-button v-if="userId == room.creatorId" style="margin-left: 10px" type="warning" :disabled="disabled" @click="handleStop"> {{ $t('trainRoom.endSimulation') }}</el-button>
2019-11-08 09:13:38 +08:00
</template>
2019-11-25 18:21:56 +08:00
<el-button type="" :disabled="disabled" @click="handleBack">{{ $t('global.back') }}</el-button>
2019-11-08 09:13:38 +08:00
</div>
2019-11-08 18:15:52 +08:00
<add-person ref="addPerson" :audience-list="audienceList" @dispatch="handleDispatchUser" />
<qr-code ref="qrCode" />
2019-11-08 09:13:38 +08:00
</div>
</template>
<script>
import eRole from './e-role';
import eDevice from './e-device';
import AddPerson from './add-person';
2019-11-08 18:15:52 +08:00
import QrCode from '@/components/QrCode';
import { getJoinTrainCode, startJointTraining, deljointTrainRoom, putJointTrainingExit, putJointTrainingSimulation, putUserRoles, setRealDevice, delRealDevice } from '@/api/chat';
2020-03-16 15:29:26 +08:00
import { getJoinTrainCodeNew, startJointTrainingNew, deljointTrainRoomNew, putUserRolesNew, putJointTrainingExitNew, putJointTrainingSimulationNew, setRealDeviceNew, delRealDeviceNew } from '@/api/jointTraining';
2019-11-08 18:15:52 +08:00
import { getPlcGateway } from '@/api/simulation';
2020-01-03 11:18:18 +08:00
import { getSessionStorage } from '@/utils/auth';
2019-11-08 09:13:38 +08:00
export default {
components : {
eRole,
eDevice,
2019-11-08 18:15:52 +08:00
AddPerson,
QrCode
2019-11-08 09:13:38 +08:00
},
props: {
room: {
type: Object,
required: true
},
members: {
type: Array,
required: true
},
height: {
type: Number,
required: true
2019-11-08 18:15:52 +08:00
},
stationList: {
type: Array,
default() {
return [];
}
},
availableStationList:{
type: Array,
default() {
return [];
}
},
2019-11-08 18:15:52 +08:00
standList: {
type: Array,
default() {
return [];
}
},
doorList: {
type: Array,
default() {
return [];
}
2019-11-08 09:13:38 +08:00
}
},
data() {
return {
2019-11-25 18:21:56 +08:00
disabled: false,
2019-11-08 09:13:38 +08:00
hasPlc: false
};
},
computed: {
rolesHeight() {
return this.height - 100;
},
2020-01-03 11:18:18 +08:00
isXtyProject() {
return getSessionStorage('project').endsWith('xty');
},
isGzbProject() {
return getSessionStorage('project').endsWith('gzb');
},
2020-03-31 18:50:16 +08:00
isLocal() {
return process.env.VUE_APP_PRO === 'local';
},
2019-11-08 18:15:52 +08:00
group() {
return this.$route.query.group;
},
2020-03-16 15:29:26 +08:00
drawWay() {
2020-03-27 13:52:14 +08:00
return this.$route.query.drawWay + '';
2020-03-16 15:29:26 +08:00
},
2019-11-08 18:15:52 +08:00
userId() {
return this.$store.state.user ? this.$store.state.user.id : '';
},
starting() {
return this.room.state == '02';
},
stationListForAttendant() {
if (this.drawWay === 'true') {
return this.availableStationList;
} else {
return this.stationList.filter(elem => { return elem.centralized; }).map(item => {
const elem = { code: item.code, name: item.name, disabled: false };
this.attendantList.forEach(nor => {
if (elem.code == nor.deviceCode) {
elem.disabled = true;
}
});
return elem;
2019-11-08 18:15:52 +08:00
});
}
2019-11-08 18:15:52 +08:00
},
stationListForIBP() {
return this.stationList.map(item => {
const elem = { value: item.code, label: item.name, children: [{value: 'left', label: this.$t('trainRoom.left')}, {value: 'right', label: this.$t('trainRoom.right')}] };
return elem;
});
},
2019-11-08 09:13:38 +08:00
dispatcherList() {
2020-03-17 14:54:03 +08:00
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('DISPATCHER'); });
2019-11-08 09:13:38 +08:00
},
attendantList() {
2020-03-17 14:54:03 +08:00
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('ATTENDANT') || [elem.userRole.toUpperCase()].includes('STATION_SUPERVISOR'); });
2019-11-08 09:13:38 +08:00
},
instructorList() {
2020-03-17 14:54:03 +08:00
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('INSTRUCTOR'); });
2019-11-08 09:13:38 +08:00
},
repairList() {
2020-03-17 18:44:49 +08:00
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('REPAIR') || [elem.userRole.toUpperCase()].includes('MAINTAINER'); });
2019-11-08 09:13:38 +08:00
},
driverList() {
2020-03-17 14:54:03 +08:00
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('DRIVER'); });
2019-11-08 09:13:38 +08:00
},
ibpList() {
2020-03-17 14:54:03 +08:00
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('IBP'); });
2019-11-08 09:13:38 +08:00
},
audienceList() {
2020-03-17 14:54:03 +08:00
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('AUDIENCE'); });
},
ciList() {
return this.members.filter(elem => { return [elem.userRole.toUpperCase()].includes('CI'); });
2019-11-08 09:13:38 +08:00
}
},
2019-11-08 18:15:52 +08:00
async mounted() {
await this.checkPlcGateway();
2019-11-08 09:13:38 +08:00
},
methods: {
2019-11-08 18:15:52 +08:00
async checkPlcGateway() {
try {
const resp = await getPlcGateway(this.group);
this.hasPlc = !!resp.data;
} catch (e) {
this.hasPlc = false;
this.$messageBox(this.$t('error.inquiryPLCDeviceFailed'));
}
},
async handleAddDevice({deviceType}) {
const roomDeviceVo = {id: '', deviceType: 'ScreenDoor', deviceCode: ''};
if (this.standList.findIndex(elem => { return elem.deviceType == roomDeviceVo.deviceType; }) > -1) {
this.$message.info(this.$t('error.theDeviceTypeAlreadyExists'));
return;
}
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
await setRealDeviceNew(this.group, roomDeviceVo);
} else {
await setRealDevice(this.group, roomDeviceVo);
}
2019-11-08 18:15:52 +08:00
},
async handleUpdDevice({deviceType, device}) {
try {
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
await setRealDeviceNew(this.group, device);
} else {
await setRealDevice(this.group, device);
}
2019-11-08 18:15:52 +08:00
} catch (e) {
this.$messageBox(this.$t('error.connectToRealDeviceFailed'));
}
},
async handleDelDevice({deviceType, device}) {
try {
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
await delRealDeviceNew(device.id, this.group);
} else {
await delRealDevice(device.id, this.group);
}
2019-11-08 18:15:52 +08:00
} catch (e) {
this.$messageBox(this.$t('error.deleteRealDeviceFailed'));
}
2019-11-08 09:13:38 +08:00
},
2019-11-08 18:15:52 +08:00
async handleAddUser({roleType}) {
2019-11-08 09:13:38 +08:00
this.$refs.addPerson.doShow(roleType);
},
2019-11-08 18:15:52 +08:00
async handleDelUser({roleType, user}) {
const params = [{
id: user.id,
nickName: user.nickName,
userRole: 'Audience',
deviceCode: ''
}];
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-17 14:54:03 +08:00
params[0].userRole = 'AUDIENCE';
2020-03-16 15:29:26 +08:00
await putUserRolesNew(params, this.group);
} else {
await putUserRoles(params, this.group);
}
2019-11-08 09:13:38 +08:00
},
2019-11-08 18:15:52 +08:00
async handleUpdUser({roleType, user, deviceList}) {
let deviceCode = '';
if (roleType === 'IBP') {
user.ibpPart = user.deviceCode[1];
deviceCode = user.deviceCode[0];
} else {
user.ibpPart = '';
deviceCode = user.deviceCode;
}
2019-11-08 09:13:38 +08:00
2019-11-08 18:15:52 +08:00
const params = [{
id: user.id,
nickName: user.nickName,
userRole: roleType,
deviceCode: deviceCode,
ibpPart: user.ibpPart
}];
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-17 14:54:03 +08:00
params[0].userRole = roleType.toUpperCase();
if (roleType === 'Attendant') {
params[0].userRole = 'STATION_SUPERVISOR';
2020-03-17 18:44:49 +08:00
} else if (roleType === 'Repair') {
params[0].userRole = 'MAINTAINER';
2020-03-17 14:54:03 +08:00
}
2020-03-16 15:29:26 +08:00
await putUserRolesNew(params, this.group);
} else {
await putUserRoles(params, this.group);
}
2019-11-08 18:15:52 +08:00
this.stationList.forEach(item => {
item.disabled = false;
deviceList.forEach(nor => {
if (item.code === nor.deviceCode) {
item.disabled = true;
}
});
});
},
async handleDispatchUser({roleType, userList}) {
2020-03-17 14:54:03 +08:00
if (userList.length) {
2019-11-08 18:15:52 +08:00
try {
2020-03-17 14:54:03 +08:00
let list = [];
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-17 14:54:03 +08:00
if (roleType === 'Attendant') {
list = userList.map(elem => { return { id: elem.id, nickName: elem.nickName, userRole: 'STATION_SUPERVISOR' }; });
2020-03-17 18:44:49 +08:00
} else if (roleType === 'Repair') {
list = userList.map(elem => { return { id: elem.id, nickName: elem.nickName, userRole: 'MAINTAINER'}; });
2020-03-17 14:54:03 +08:00
} else {
list = userList.map(elem => { return { id: elem.id, nickName: elem.nickName, userRole: roleType.toUpperCase() }; });
}
2020-03-16 15:29:26 +08:00
await putUserRolesNew(list, this.group);
} else {
2020-03-17 14:54:03 +08:00
list = userList.map(elem => { return { id: elem.id, nickName: elem.nickName, userRole: roleType }; });
2020-03-16 15:29:26 +08:00
await putUserRoles(list, this.group);
}
2019-11-08 18:15:52 +08:00
list.forEach(item => {
this.treeData.forEach(nor => {
if (item.id == nor.id) {
nor.userRole = item.userRole;
}
});
});
} catch (error) {
if (error.code == 500009) {
this.messageInfo({error:'error', message: this.$t('error.exceededTheTotalNumberOfAssignableRoles')} );
}
}
}
},
2019-11-25 18:21:56 +08:00
async handlePostQrcode() {
this.disabled = true;
2020-03-16 15:29:26 +08:00
let res = '';
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
res = await getJoinTrainCodeNew({}, this.group);
} else {
res = await getJoinTrainCode({}, this.group);
}
2019-11-25 18:21:56 +08:00
if (res.code == '200') {
const param = {
url: res.data,
title: this.$t('trainRoom.distributeTheRoomQRCode'),
group: this.group
2019-11-25 18:21:56 +08:00
};
if (this.$refs) {
this.$refs.qrCode.doShow(param);
}
}
this.disabled = false;
},
async handleJoin() {
try {
this.disabled = true;
this.$emit('joinTraining');
} catch (e) {
console.error(e);
}
},
2019-11-08 18:15:52 +08:00
async handleStart() {
2019-11-25 18:21:56 +08:00
this.disabled = true;
2019-11-08 18:15:52 +08:00
if (this.attendantList.findIndex(item => { return !item.deviceCode; }) < 0) {
try {
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
await startJointTrainingNew(this.group);
} else {
await startJointTraining(this.group);
}
2019-11-08 18:15:52 +08:00
} catch (error) {
this.$emit('message', {type:'error', message: this.$t('error.startedComprehensiveDrillFailure')});
2019-11-25 18:21:56 +08:00
this.disabled = false;
2019-11-08 18:15:52 +08:00
}
} else {
this.$emit('message', {type:'error', message: this.$t('error.stationAttendantStationCannotBeEmpty')});
2019-11-25 18:21:56 +08:00
this.disabled = false;
2019-11-08 18:15:52 +08:00
}
2019-11-08 09:13:38 +08:00
},
async handleStop() {
2019-11-25 18:21:56 +08:00
try {
this.disabled = true;
2020-03-16 15:29:26 +08:00
let res = '';
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
res = await putJointTrainingSimulationNew(this.group);
} else {
res = await putJointTrainingSimulation(this.group);
}
2019-11-25 18:21:56 +08:00
this.mapId = res.data.mapId;
} catch (e) {
console.error(e);
} finally {
this.disabled = false;
}
2019-11-08 09:13:38 +08:00
},
async handleExit() {
2019-11-25 18:21:56 +08:00
this.disabled = true;
2019-11-08 18:15:52 +08:00
this.$confirm( this.$t('tip.destroyRoomHint'), this.$t('tip.hint'), {
confirmButtonText: this.$t('global.confirm'),
cancelButtonText: this.$t('global.cancel'),
type: 'warning'
}).then(async () => {
try {
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
await deljointTrainRoomNew(this.group);
} else {
await deljointTrainRoom(this.group);
}
2019-11-08 18:15:52 +08:00
} catch (error) {
this.$emit('message', {type:'error', message: this.$t('error.destroyedRoomFailed')});
2019-11-25 18:21:56 +08:00
} finally {
this.disabled = false;
2019-11-08 18:15:52 +08:00
}
2019-11-25 18:21:56 +08:00
}).catch(() => {
this.disabled = false;
2019-11-08 18:15:52 +08:00
});
2019-11-08 09:13:38 +08:00
},
2020-03-31 18:50:16 +08:00
handleGetGroup() {
this.$messageBox(this.group, this.$t('trainRoom.groupId'), 'success');
},
2019-11-08 09:13:38 +08:00
async handleBack() {
try {
2019-11-25 18:21:56 +08:00
this.disabled = true;
2020-03-27 13:52:14 +08:00
if (this.drawWay === 'true') {
2020-03-16 15:29:26 +08:00
await putJointTrainingExitNew(this.group);
} else {
await putJointTrainingExit(this.group);
}
2020-01-15 13:20:48 +08:00
this.$emit('clearSubscribe');
2019-11-25 18:21:56 +08:00
this.$router.go(-1);
2019-11-08 09:13:38 +08:00
} catch (error) {
2019-11-25 18:21:56 +08:00
this.disabled = false;
2019-11-08 18:15:52 +08:00
this.$emit('message', {type:'error', message: this.$t('error.operationFailure')});
2019-11-08 09:13:38 +08:00
}
}
}
};
</script>
<style scoped lang="scss">
.roles {
display: flex;
flex-direction: column;
background: #fff;
&__head {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 30px;
border-top: 1px solid #ccc;
box-shadow: 0 3px 3px #ccc;
background: #F0F0F0;
&--title {
display: flex;
align-items: flex-end;
2019-11-18 17:11:40 +08:00
padding: 10px 0px;
2019-11-08 09:13:38 +08:00
.label {
font-size: 16px;
font-weight: bold;
border-left: 5px solid #CF2727;
padding: 0 5px
}
.notes {
font-size: 12px;
padding: 0 5px
}
}
&--reset {
.el-button {
background: #CF2727;
color: #fff;
}
}
}
&__container {
display: flex;
flex-grow: 1;
padding: 5px 10px;
.roles {
display: flex;
justify-content: space-around;
flex-flow: row wrap;
flex-grow: 1;
.role {
display: flex;
flex-basis: 340px;
margin-top: 20px;
}
}
}
&__footer {
height: 60px;
display: flex;
padding: 0 30px;
align-items: center;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
}
</style>