417 lines
17 KiB
Vue
417 lines
17 KiB
Vue
<template>
|
|
<el-tabs v-model="activeName" class="card">
|
|
<el-tab-pane class="view-control" :label="$t('map.property')" name="first" :lazy="lazy">
|
|
<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>
|
|
<div class="button_box">
|
|
<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>
|
|
</div>
|
|
</el-tab-pane>
|
|
<el-tab-pane class="view-control" :label="$t('map.batchOperation')" name="second" :lazy="lazy">
|
|
<div style="height: 100%; padding: 10px; box-sizing: border-box">
|
|
<el-scrollbar wrap-class="scrollbar-wrapper">
|
|
<div class="view-content" style="text-align:center;">
|
|
<span class="title-center">创建</span>
|
|
<el-button type="primary" size="big" style="margin-top:10px" @click="createTrainWindow">{{ $t('map.createTrainWindow') }}</el-button>
|
|
</div>
|
|
<div class="view-content" style="text-align:center;">
|
|
<span class="title-center">删除</span>
|
|
<el-button type="" size="big" @click="removeTrainWindow">{{ $t('map.deleteTrainWindow') }}</el-button>
|
|
</div>
|
|
<div class="view-content">
|
|
<span class="title-center">修改</span>
|
|
<el-form ref="addForm" label-width="130px" :model="addModel" size="mini" :rules="mergeRules">
|
|
<el-form-item label="车次窗编码:" prop="modelList">
|
|
<el-select v-model="addModel.modelList" filterable multiple>
|
|
<el-option
|
|
v-for="item in trainWindowList"
|
|
:key="item.code"
|
|
:label="item.code"
|
|
:value="item.code"
|
|
/>
|
|
</el-select>
|
|
<el-button
|
|
:type="field === 'trainWindowCode' ? 'danger' : 'primary'"
|
|
size="small"
|
|
@click="hover('trainWindowCode')"
|
|
>{{ $t('map.activate') }}</el-button>
|
|
</el-form-item>
|
|
<el-form-item label="Y轴坐标:" prop="pointY">
|
|
<el-input-number v-model="addModel.pointY" style="width: 178px;" />
|
|
</el-form-item>
|
|
<el-form-item label="车次窗宽度:" prop="width">
|
|
<el-input-number v-model="addModel.width" style="width: 178px;" />
|
|
</el-form-item>
|
|
<el-form-item label="车次窗高度:" prop="height">
|
|
<el-input-number v-model="addModel.height" style="width: 178px;" />
|
|
</el-form-item>
|
|
<el-form-item>
|
|
<el-button-group>
|
|
<el-button type="primary" size="small" @click="editTrainWindow">{{ $t('map.updateObj') }}</el-button>
|
|
</el-button-group>
|
|
</el-form-item>
|
|
</el-form>
|
|
</div>
|
|
</el-scrollbar>
|
|
</div>
|
|
</el-tab-pane>
|
|
</el-tabs>
|
|
</template>
|
|
|
|
<script>
|
|
import { mapGetters } from 'vuex';
|
|
import { getUID } from '@/jmapNew/utils/Uid';
|
|
import JTriangle from '@/jmapNew/utils/JTriangle';
|
|
import ConfigList from './config/list';
|
|
import { deepAssign } from '@/utils/index';
|
|
|
|
export default {
|
|
name: 'TrainWindowDraft',
|
|
components: {
|
|
ConfigList
|
|
},
|
|
props: {
|
|
selected: {
|
|
type: Object,
|
|
default: function () {
|
|
return null;
|
|
}
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
activeName: 'first',
|
|
lazy: true,
|
|
mapData: null,
|
|
addList: [],
|
|
editModel: {
|
|
code: '',
|
|
point: {
|
|
x: 0,
|
|
y: 0
|
|
},
|
|
width: 0,
|
|
height: 0,
|
|
reversal: false
|
|
},
|
|
rules: {
|
|
code: [
|
|
{ required: true, message: this.$t('rules.pleaseReSelectDevice'), trigger: 'blur' }
|
|
],
|
|
'point.x': [
|
|
{ required: true, message: this.$t('rules.trainPositionX'), trigger: 'blur' }
|
|
],
|
|
'point.y': [
|
|
{ required: true, message: this.$t('rules.trainPositionY'), trigger: 'blur' }
|
|
],
|
|
width: [
|
|
{ required: true, message: this.$t('rules.trainWindowWidth'), trigger: 'blur' }
|
|
],
|
|
height: [
|
|
{ required: true, message: this.$t('rules.trainWindowHeight'), trigger: 'blur' }
|
|
]
|
|
},
|
|
field: '',
|
|
addModel: {
|
|
pointY: '',
|
|
width: 40,
|
|
height: 15,
|
|
modelList: []
|
|
},
|
|
mergeRules: {
|
|
pointY: [
|
|
{ required: true, message: '请输入', trigger: 'blur' }
|
|
],
|
|
modelList: [
|
|
{ required: true, message: '请选择', trigger: 'change' }
|
|
],
|
|
width: [
|
|
{ required: true, message: this.$t('rules.trainWindowWidth'), trigger: 'blur' }
|
|
],
|
|
height: [
|
|
{ required: true, message: this.$t('rules.trainWindowHeight'), trigger: 'blur' }
|
|
]
|
|
}
|
|
};
|
|
},
|
|
computed: {
|
|
...mapGetters('map', [
|
|
'sectionList',
|
|
'switchList',
|
|
'trainWindowList'
|
|
]),
|
|
filterSectionList() {
|
|
let list = [];
|
|
if (this.sectionList && this.sectionList.length) {
|
|
list = this.sectionList.filter(elem => { return !(elem.type == '03' && elem.parentCode); });
|
|
}
|
|
return list;
|
|
},
|
|
form() {
|
|
const form = {
|
|
labelWidth: '120px',
|
|
items: {
|
|
code: {
|
|
name: '',
|
|
item: []
|
|
},
|
|
draw: {
|
|
name: this.$t('map.drawData'),
|
|
item: [
|
|
{ prop: 'code', label: this.$t('map.trainWindowCode'), type: 'select', optionLabel: 'code', optionValue: 'code', options: this.trainWindowList, change: true, deviceChange: this.deviceChange },
|
|
{ prop: 'width', label: this.$t('map.trainWindowWidth'), type: 'number', min: 0, placeholder: 'px' },
|
|
{ prop: 'height', label: this.$t('map.trainWindowHeight'), type: 'number', min: 0, placeholder: 'px' },
|
|
{ prop: 'point', label: this.$t('map.trainWindowPoints'), type: 'coordinate', width: '110px', children: [
|
|
{ prop: 'point.x', firstLevel: 'point', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '20px', disabled: false },
|
|
{ prop: 'point.y', firstLevel: 'point', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '20px', disabled: false }
|
|
] }
|
|
]
|
|
},
|
|
map: {
|
|
name: this.$t('map.mapData'),
|
|
item: [
|
|
{ prop: 'reversal', label: '车头翻转', type: 'checkbox' }
|
|
]
|
|
}
|
|
}
|
|
};
|
|
return form;
|
|
},
|
|
style() {
|
|
return this.$jlmap.style;
|
|
}
|
|
},
|
|
watch: {
|
|
// selected: function (val, oldVal) {
|
|
// this.deviceSelect(val);
|
|
// }
|
|
},
|
|
methods: {
|
|
filterSections(query, item) {
|
|
return item.pinyin.indexOf(query) > -1;
|
|
},
|
|
deviceChange(code) {
|
|
this.$emit('setCenter', code);
|
|
this.deviceSelect(this.$store.getters['map/getDeviceByCode'](code));
|
|
},
|
|
hover(field) {
|
|
this.field = field == this.field ? '' : field;
|
|
},
|
|
deviceSelect(selected) {
|
|
this.$refs.form && this.$refs.form.resetFields();
|
|
if (selected && selected._type.toUpperCase() === 'TrainWindow'.toUpperCase()) {
|
|
this.activeName = 'first';
|
|
this.editModel = deepAssign(this.editModel, selected);
|
|
if (this.field == 'trainWindowCode') {
|
|
if (this.addModel.modelList.indexOf(selected.code) == -1) {
|
|
this.addModel.modelList.push(selected.code);
|
|
}
|
|
this.activeName = 'second';
|
|
}
|
|
}
|
|
},
|
|
createModel(opts) {
|
|
const model = {
|
|
_type: 'TrainWindow',
|
|
code: getUID('TrainWindow', [...this.trainWindowList, ...this.addList]),
|
|
trainWindowShow: true,
|
|
point: {},
|
|
reversal: false
|
|
};
|
|
|
|
if (opts) {
|
|
var width = this.style.trainWindowWidth;
|
|
var height = this.style.trainWindowHeight;
|
|
const section = opts.section;
|
|
if (section) {
|
|
if (section.type !== '04' && opts.triangle) {
|
|
model.point = opts.triangle.middlePoint();
|
|
if (opts.triangle.getCosRate() == 1 && opts.triangle.absx < width) {
|
|
width = opts.triangle.absx;
|
|
}
|
|
|
|
if (opts.triangle.getCosRate() !== 0 && opts.triangle.getCosRate() !== 1) {
|
|
model.point.x = section.points[0].x;
|
|
model.point.y = section.points[section.points.length - 1].y;
|
|
}
|
|
} else {
|
|
model.point = {
|
|
x: section.namePosition.x,
|
|
y: section.namePosition.y
|
|
};
|
|
}
|
|
|
|
const distance = (this.style.trainDistance + this.style.trainConflictR * 2 + height);
|
|
let offsetx = 0;
|
|
let offsety = 0;
|
|
if (opts.triangle) {
|
|
if (opts.triangle.getCosRate() == 1 || opts.triangle.getCosRate() == 0) {
|
|
offsetx = distance * opts.triangle.getSinRate();
|
|
offsety = distance * opts.triangle.getCosRate();
|
|
} else {
|
|
offsetx = distance;
|
|
offsety = distance;
|
|
}
|
|
} else {
|
|
offsetx = 0;
|
|
offsety = distance;
|
|
}
|
|
if (section.trainPosType == '01') {
|
|
model.point.y = model.point.y - height - offsety;
|
|
model.point.x = model.point.x - offsetx;
|
|
} else {
|
|
model.point.x = model.point.x + offsetx;
|
|
model.point.y = model.point.y + offsety;
|
|
}
|
|
model.height = height;
|
|
model.width = width;
|
|
}
|
|
}
|
|
return model;
|
|
},
|
|
// 一键删除车次窗
|
|
removeTrainWindow() {
|
|
this.$confirm(this.$t('tip.confirmDeletion'), this.$t('tip.hint'), {
|
|
confirmButtonText: this.$t('tip.confirm'),
|
|
cancelButtonText: this.$t('tip.cancel'),
|
|
type: 'warning'
|
|
}).then(() => {
|
|
const remove = [];
|
|
if (this.trainWindowList && this.trainWindowList.length) {
|
|
this.trainWindowList.forEach(elem => {
|
|
remove.push({
|
|
_type: 'TrainWindow',
|
|
code: elem.code,
|
|
_dispose: true
|
|
});
|
|
});
|
|
this.sectionList.forEach(elem => {
|
|
if (elem.trainWindowCode) {
|
|
const section = deepAssign({}, elem);
|
|
section.trainWindowCode = '';
|
|
remove.push(section);
|
|
}
|
|
});
|
|
this.$emit('updateMapModel', remove);
|
|
}
|
|
}).catch(() => {
|
|
this.$message.info(this.$t('tip.cancelledDelete'));
|
|
});
|
|
},
|
|
// 一键创建车次窗
|
|
createTrainWindow() {
|
|
const models = [];
|
|
this.addList = []; // 为生成名字 code需要list
|
|
if (this.sectionList && this.sectionList.length) {
|
|
this.sectionList.forEach(elem => {
|
|
// elem.type !== '03' // 更宽泛的匹配条件 !elem.switchSection 严格匹配条件
|
|
if (elem.type !== '04' && !elem.switchSection && !elem.trainWindowCode && ( !elem.logicSectionCodeList || elem.logicSectionCodeList.length === 0)) {
|
|
const triangle = new JTriangle(elem.points[0], elem.points[elem.points.length - 1]);
|
|
const param = this.createModel({
|
|
triangle: triangle,
|
|
section: elem
|
|
});
|
|
models.push(param);
|
|
const section = deepAssign(elem, { trainWindowCode: param.code });
|
|
models.push(section);
|
|
this.addList.push(param);
|
|
} else if (elem.type === '04' && !elem.trainWindowCode) {
|
|
const param = this.createModel({
|
|
section: elem
|
|
});
|
|
models.push(param);
|
|
const section = deepAssign(elem, { trainWindowCode: param.code });
|
|
models.push(section);
|
|
this.addList.push(param);
|
|
}
|
|
});
|
|
}
|
|
|
|
this.$emit('updateMapModel', models);
|
|
},
|
|
// 修改对象
|
|
edit() {
|
|
this.$refs['form'].validate((valid) => {
|
|
if (valid) {
|
|
const data = Object.assign({_type: 'TrainWindow'}, this.editModel);
|
|
this.$emit('updateMapModel', data);
|
|
}
|
|
});
|
|
},
|
|
// 删除对象
|
|
deleteObj() {
|
|
const selected = this.$store.getters['map/getDeviceByCode'](this.editModel.code);
|
|
if (selected && selected._type.toUpperCase() === 'TrainWindow'.toUpperCase()) {
|
|
this.$confirm(this.$t('tip.confirmDeletion'), this.$t('tip.hint'), {
|
|
confirmButtonText: this.$t('tip.confirm'),
|
|
cancelButtonText: this.$t('tip.cancel'),
|
|
type: 'warning'
|
|
}).then(() => {
|
|
const models = [];
|
|
this.sectionList.forEach(elem => {
|
|
if (elem.trainWindowCode == selected.code) {
|
|
const section = deepAssign({}, elem);
|
|
section.trainWindowCode = '';
|
|
models.push(section);
|
|
}
|
|
});
|
|
models.push(deepAssign(selected, { _dispose: true }));
|
|
this.$emit('updateMapModel', models);
|
|
this.$refs.form && this.$refs.form.resetFields();
|
|
}).catch(() => {
|
|
this.$message.info(this.$t('tip.cancelledDelete'));
|
|
});
|
|
}
|
|
},
|
|
editTrainWindow() {
|
|
this.$refs['addForm'].validate((valid) => {
|
|
if (valid) {
|
|
const models = [];
|
|
this.addModel.modelList.forEach(code => {
|
|
const model = this.$store.getters['map/getDeviceByCode'](code);
|
|
const modelData = deepAssign({}, model);
|
|
modelData.point.y = this.addModel.pointY;
|
|
modelData.height = this.addModel.height;
|
|
modelData.width = this.addModel.width;
|
|
models.push(modelData);
|
|
});
|
|
this.$emit('updateMapModel', models);
|
|
this.addModel.modelList = [];
|
|
this.field = '';
|
|
}
|
|
});
|
|
}
|
|
}
|
|
};
|
|
</script>
|
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
|
@import "src/styles/mixin.scss";
|
|
.view-control{
|
|
height: 100%;
|
|
}
|
|
|
|
.card {
|
|
height: 100%;
|
|
}
|
|
.view-content{
|
|
position: relative;
|
|
border: 1px solid #ccc;
|
|
padding: 10px;
|
|
margin-top: 10px;
|
|
.title-center{
|
|
position: absolute;
|
|
top: -10px;
|
|
left: 20px;
|
|
padding: 3px 10px;
|
|
background: #fff;
|
|
font-size: 14px;
|
|
}
|
|
}
|
|
</style>
|