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

153 lines
3.6 KiB
Vue
Raw Normal View History

2019-11-08 09:13:38 +08:00
<template>
<div class="device">
<div class="device__head">
<div class="device__head--title">
2019-11-08 18:15:52 +08:00
{{ $t(titleI18n) }}<span>-{{ hasPlc? $t('trainRoom.plcGatewayOnline') : $t('trainRoom.plcGatewayOffline') }}</span>
2019-11-08 09:13:38 +08:00
</div>
<div class="device__head--add">
2019-11-08 18:15:52 +08:00
<el-button v-if="userId == room.creatorId" icon="el-icon-plus" circle plain @click="handleAddDevice()" />
2019-11-08 09:13:38 +08:00
</div>
</div>
<div class="device__container">
<ul class="device__container--list">
<li v-for="(node, index) in options" :key="index">
2019-11-08 18:15:52 +08:00
<span>{{ realDeviceType[node.deviceType] }}</span>
<i v-if="userId == room.creatorId" class="el-icon-close delete" @click="handleDelDevice(node, index)" />
2019-11-08 09:13:38 +08:00
<div style="float: right; margin-right: 15px;">
2019-11-08 18:15:52 +08:00
<el-select
2019-11-08 09:13:38 +08:00
v-model="node.deviceCode"
:placeholder="$t('global.choose')"
2019-11-08 18:15:52 +08:00
size="mini"
2019-11-08 09:13:38 +08:00
:disabled="userId != room.creatorId"
2019-11-08 18:15:52 +08:00
@change="handleUpdDevice(node, index)"
>
<el-option
v-for="item in deviceList"
:key="item.code"
:label="item.name"
:value="item.code"
:disabled="item.disabled"
style="margin-left: 10px"
/>
</el-select>
2019-11-08 09:13:38 +08:00
</div>
</li>
</ul>
</div>
</div>
</template>
<script>
2019-11-08 18:15:52 +08:00
import { RealDeviceType } from '@/scripts/ConstDic';
2019-11-08 09:13:38 +08:00
export default {
props: {
titleI18n: {
type: String,
required: true
},
room: {
type:Object,
required: true
},
options: {
type: Array,
required: true
},
2019-11-08 18:15:52 +08:00
deviceType: {
type: String,
default: ''
},
deviceList: {
2019-11-08 09:13:38 +08:00
type: Array,
default() {
return [];
}
},
hasPlc: {
type: Boolean,
default: false
}
},
data() {
return {
2019-11-08 18:15:52 +08:00
realDeviceType: RealDeviceType
2019-11-08 09:13:38 +08:00
};
},
2019-11-08 18:15:52 +08:00
computed: {
userId() {
return this.$store.state.user ? this.$store.state.user.id : '';
}
},
2019-11-08 09:13:38 +08:00
methods: {
handleAddDevice() {
2019-11-08 18:15:52 +08:00
this.$emit('addDevice', { deviceType: this.deviceType });
2019-11-08 09:13:38 +08:00
},
2019-11-08 18:15:52 +08:00
handleUpdDevice(node, index) {
this.$emit('changeDevice', { deviceType: this.deviceType, device: node, deviceList: this.deviceList });
2019-11-08 09:13:38 +08:00
},
handleDelDevice(node, index) {
2019-11-08 18:15:52 +08:00
this.$emit('delDevice', { deviceType: this.deviceType, device: node, deviceList: this.deviceList });
2019-11-08 09:13:38 +08:00
}
}
};
</script>
<style scoped lang="scss">
ul,
li {
list-style: none;
padding: 0;
margin: 0;
}
.device {
border: 1px solid #ccc;
height: 200px;
display: flex;
flex-direction: column;
justify-content: space-between;
position: relative;
&__head {
border-bottom: 1px solid #ccc;
background: #f0f0f0;
display: flex;
justify-content: space-between;
align-items: center;
padding: 3px;
&--title {
font-size: 14px;
font-weight: bold;
2019-11-18 17:11:40 +08:00
margin-left:10px;
2019-11-08 09:13:38 +08:00
}
&--add {
2019-11-18 17:11:40 +08:00
margin-right:2px;
2019-11-08 09:13:38 +08:00
/deep/ .el-button.is-circle {
padding: 5px;
}
}
}
&__container {
flex-grow: 1;
&--list {
li {
height: 30px;
line-height: 30px;
padding-left: 10px;
2019-11-12 14:56:53 +08:00
display: flow-root;
2019-11-08 09:13:38 +08:00
}
.delete {
float: right;
margin-right: 10px;
margin-top: 7px;
cursor: pointer;
}
}
}
}
</style>