rt-sim-training-client/src/views/newMap/newMapdraft/mapoperate/line.vue

345 lines
13 KiB
Vue
Raw Normal View History

2019-11-29 12:51:58 +08:00
<template>
<el-tabs v-model="activeName" class="card">
2020-04-30 14:50:27 +08:00
<el-tab-pane class="view-control" :label="$t('map.property')" name="first" :lazy="lazy">
2019-11-29 12:51:58 +08:00
<div style="height: calc(100% - 46px);">
<el-scrollbar wrap-class="scrollbar-wrapper">
<config-list ref="form" :form="form" :form-model="editModel" :rules="rules" />
</el-scrollbar>
</div>
<el-button-group class="map-draft-group">
<el-button type="primary" size="small" @click="edit">{{ $t('map.updateObj') }}</el-button>
<el-button type="danger" size="small" @click="deleteObj">{{ $t('map.deleteObj') }}</el-button>
</el-button-group>
</el-tab-pane>
2020-04-30 14:50:27 +08:00
<el-tab-pane class="view-control" :label="$t('map.newConstruction')" name="second" :lazy="lazy">
2019-11-29 12:51:58 +08:00
<div style="height: calc(100% - 46px);">
<el-scrollbar wrap-class="scrollbar-wrapper">
<el-form ref="make" label-width="120px" :model="addModel" size="mini" :rules="makeRules">
<el-form-item :label="$t('map.lineType')" prop="type">
<el-select v-model="addModel.type" filterable>
<el-option
v-for="item in LineTypeList"
:key="item.code"
:label="item.name"
:value="item.code"
/>
</el-select>
</el-form-item>
<el-form-item :label="$t('map.lineWidth')" prop="width">
<el-input-number v-model="addModel.width" :min="1" />px
</el-form-item>
2020-03-24 10:05:51 +08:00
<el-form-item :label="$t('map.lineColor')" prop="lineColor">
<el-color-picker v-model="addModel.lineColor" show-alpha />
</el-form-item>
<el-form-item :label="$t('map.showConditions')" prop="showConditions">
<el-radio-group v-model="addModel.showConditions">
<el-radio v-for="each in showConditionsList" :key="each.value" :label="each.value">{{ each.label }}</el-radio>
</el-radio-group>
</el-form-item>
2019-11-29 12:51:58 +08:00
<div class="coordinate">
<span class="title">{{ $t('map.linePoint') }}</span>
<div class="point-section">
<template v-for="(point, index) in addModel.points">
<div :key="index" style="overflow: hidden;">
<el-form-item
label=""
:prop="'points[' + index + '].x'"
style="display: table; float: left;"
label-width="0px"
>
<el-input-number v-model="point.x" />
</el-form-item>
<span style="display: table; margin-left: 8px; float: left; line-height: 28px;">
, </span>
<el-form-item
label=""
:prop="'points[' + index + '].y'"
style="display: table; float: left; margin-right: 5px;"
label-width="10px"
>
<el-input-number v-model="point.y" />
</el-form-item>
<el-button
icon="el-icon-plus"
circle
class="point-button"
2020-03-24 10:05:51 +08:00
@click="addPointAddModel(index)"
2019-11-29 12:51:58 +08:00
/>
<el-button
icon="el-icon-minus"
:disabled="index == 0 || index == addModel.points.length - 1"
circle
class="point-button"
2020-03-24 10:05:51 +08:00
@click="delPointAddModel(index)"
2019-11-29 12:51:58 +08:00
/>
</div>
</template>
</div>
</div>
</el-form>
</el-scrollbar>
</div>
<el-button-group class="map-draft-group">
<el-button type="primary" size="small" @click="create">{{ $t('map.create') }}</el-button>
</el-button-group>
</el-tab-pane>
</el-tabs>
</template>
<script>
import ConstConfig from '@/scripts/ConstConfig';
import Cookies from 'js-cookie';
2019-11-29 12:51:58 +08:00
import { mapGetters } from 'vuex';
2019-12-06 10:31:19 +08:00
import { getUID } from '@/jmapNew/utils/Uid';
2019-11-29 12:51:58 +08:00
import ConfigList from './config/list';
import { deepAssign } from '@/utils/index';
export default {
name: 'StationStandDraft',
components: {
ConfigList
},
props: {
selected: {
type: Object,
default: function () {
return null;
}
}
},
data() {
return {
activeName: 'first',
2020-04-30 14:50:27 +08:00
lazy: true,
2019-11-29 12:51:58 +08:00
LineTypeList: [],
editModel: {
code: '',
type: '',
width: 1,
2020-03-19 16:17:34 +08:00
lineColor: '',
showConditions: '01',
2019-11-29 12:51:58 +08:00
points: []
},
addModel: {
type: '',
width: 1,
showConditions: '01',
2020-03-24 10:05:51 +08:00
lineColor: 'rgba(255, 255, 255, 1)',
2019-11-29 12:51:58 +08:00
points: [
{ x: 0, y: 0 },
{ x: 100, y: 100 }
]
},
rules: {
code: [
{ required: true, message: this.$t('rules.pleaseSelectLine'), trigger: 'blur' }
],
type: [
{ required: true, message: this.$t('rules.pleaseSelectLineType'), trigger: 'blur' }
],
width: [
{ required: true, message: this.$t('rules.pleaseSelectLineWidth'), trigger: 'blur' }
]
},
makeRules: {
code: [
{ required: true, message: this.$t('rules.pleaseSelectLine'), trigger: 'blur' }
],
type: [
{ required: true, message: this.$t('rules.pleaseSelectLineType'), trigger: 'blur' }
],
width: [
{ required: true, message: this.$t('rules.pleaseSelectLineWidth'), trigger: 'blur' }
]
}
};
},
computed: {
...mapGetters('map', [
'lineList',
'stationList',
'lineCode'
]),
showConditionsList() {
const showConditionsList = ConstConfig.ConstSelect.showConditionsList;
return Cookies.get('user_lang') == 'en'
? showConditionsList.map(elem => { return { value: elem.value, label: elem.enlabel }; })
: showConditionsList.map(elem => { return { value: elem.value, label: elem.label }; });
},
2019-11-29 12:51:58 +08:00
form() {
const form = {
labelWidth: '120px',
items: {
code: {
name: '',
item: []
},
draw: {
name: this.$t('map.drawData'),
item: [
{ prop: 'code', label: this.$t('map.lineCoding'), type: 'select', optionLabel: 'code', optionValue: 'code', options: this.lineList, change: true, deviceChange: this.deviceChange },
{ prop: 'type', label: this.$t('map.lineType'), type: 'select', optionLabel: 'name', optionValue: 'code', options: this.LineTypeList },
2020-03-19 16:17:34 +08:00
{ prop: 'lineColor', label: this.$t('map.lineColor'), type: 'color' },
2019-11-29 12:51:58 +08:00
{ prop: 'width', label: this.$t('map.lineWidth'), type: 'number', min: 1, placeholder: 'px' },
{ prop: 'showConditions', label: this.$t('map.showConditions'), type: 'radio', optionLabel: 'label', optionValue:'value', radioList: this.showConditionsList},
2019-11-29 12:51:58 +08:00
{ prop: 'points', label: this.$t('map.segmentCoordinates'), type: 'points', width: '100px', isHidden: !this.isPointsShow, addPoint: this.addPoint, delPoint: this.delPoint }
]
},
map: {
name: this.$t('map.mapData'),
item: [
]
}
}
};
return form;
},
isPointsShow() {
return this.editModel.points.length > 0;
}
},
watch: {
// selected(val, oldVal) {
// this.deviceSelect(val);
// }
2019-11-29 12:51:58 +08:00
},
mounted() {
this.$Dictionary.lineType().then(list => {
this.LineTypeList = list;
});
},
methods: {
deviceChange(code) {
this.$emit('setCenter', code);
this.deviceSelect(this.$store.getters['map/getDeviceByCode'](code));
},
deviceSelect(selected) {
if (selected && selected._type.toUpperCase() === 'Line'.toUpperCase()) {
2020-05-18 17:08:21 +08:00
this.$refs.form && this.$refs.form.resetFields();
this.$refs.make && this.$refs.make.resetFields();
2019-11-29 12:51:58 +08:00
this.activeName = 'first';
this.editModel = deepAssign(this.editModel, selected);
}
},
addPoint(index) {
const data = { x: 0, y: 0 };
this.editModel.points.splice(index + 1, 0, data);
},
delPoint(index) {
this.editModel.points.splice(index, 1);
2019-11-29 12:51:58 +08:00
},
2020-03-24 10:05:51 +08:00
addPointAddModel(index) {
const data = { x: 0, y: 0};
this.addModel.points.splice(index + 1, 0, data);
},
delPointAddModel(index) {
this.addModel.points.splice(index, 1);
},
2019-11-29 12:51:58 +08:00
create() {
this.$refs['make'].validate((valid) => {
if (valid) {
if (JSON.stringify(this.addModel.points[0]) !== JSON.stringify(this.addModel.points[this.addModel.points.length - 1])) {
const pointArr = JSON.stringify(this.addModel.points);
const model = {
_type: 'Line',
2019-12-06 10:31:19 +08:00
code: getUID('Line', this.lineList),
2019-11-29 12:51:58 +08:00
type: this.addModel.type,
width: this.addModel.width,
2020-03-24 10:05:51 +08:00
showConditions: this.addModel.showConditions,
lineColor: this.addModel.lineColor,
2019-11-29 12:51:58 +08:00
points: JSON.parse(pointArr)
};
this.$emit('updateMapModel', model);
2020-05-18 17:08:21 +08:00
this.$refs.make && this.$refs.make.resetFields();
2019-11-29 12:51:58 +08:00
} else {
this.$message.console.error(this.$t('tip.cannotCoincide'));
}
}
});
},
// 修改对象
edit() {
this.$refs['form'].validate((valid) => {
if (valid) {
const data = Object.assign({_type: 'Line'}, this.editModel);
this.$emit('updateMapModel', data);
}
});
},
// 删除对象
deleteObj() {
const selected = this.$store.getters['map/getDeviceByCode'](this.editModel.code);
if (selected && selected._type.toUpperCase() === 'Line'.toUpperCase()) {
this.$confirm(this.$t('tip.confirmDeletion'), this.$t('tip.hint'), {
confirmButtonText: this.$t('tip.confirm'),
cancelButtonText: this.$t('tip.cancel'),
type: 'warning'
}).then(() => {
2020-05-18 17:08:21 +08:00
this.$emit('updateMapModel', {...selected, _dispose: true});
this.$refs.form && this.$refs.form.resetFields();
2019-11-29 12:51:58 +08:00
}).catch(() => {
2020-05-18 17:08:21 +08:00
this.$message.info(this.$t('tip.cancelledDelete'));
2019-11-29 12:51:58 +08:00
});
}
}
}
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/mixin.scss";
.view-control{
height: 100%;
overflow-y: auto;
}
.card {
height: 100%;
}
.coordinate {
overflow: hidden;
.title {
text-align: right;
font-size: 14px;
color: #606266;
line-height: 40px;
padding: 0 12px 0 0;
-webkit-box-sizing: border-box;
box-sizing: border-box;
line-height: 28px;
width: 120px;
font-weight: bold;
display: block;
float: left;
}
}
.point-section {
2020-03-24 10:05:51 +08:00
/*float: left;*/
position: absolute;
left: 120px;
2019-11-29 12:51:58 +08:00
width: calc(100% - 120px);
}
.point-button {
width: 28px;
height: 28px;
display: flex;
align-items: center;
justify-content: center;
float: left;
/deep/ {
.el-icon-plus,
.el-icon-minus {
transform: translateY(-5px);
}
}
}
.el-input-number--mini {
width: 110px;
}
</style>