修改道岔生成逻辑

This commit is contained in:
zyy 2019-12-02 13:05:25 +08:00
parent 103e8c9c49
commit 5793355e20
4 changed files with 132 additions and 177 deletions

View File

@ -3,10 +3,10 @@ export function getBaseUrl() {
let BASE_API; let BASE_API;
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
// BASE_API = 'https://joylink.club/jlcloud'; // BASE_API = 'https://joylink.club/jlcloud';
// BASE_API = 'https://test.joylink.club/jlcloud'; BASE_API = 'https://test.joylink.club/jlcloud';
// BASE_API = 'http://192.168.3.5:9000'; // 袁琪 // BASE_API = 'http://192.168.3.5:9000'; // 袁琪
// BASE_API = 'http://192.168.3.6:9000'; // 旭强 // BASE_API = 'http://192.168.3.6:9000'; // 旭强
BASE_API = 'http://192.168.3.41:9000'; // 张赛 // BASE_API = 'http://192.168.3.41:9000'; // 张赛
// BASE_API = 'http://192.168.3.82:9000'; // 杜康 // BASE_API = 'http://192.168.3.82:9000'; // 杜康
} else { } else {
BASE_API = process.env.VUE_APP_BASE_API; BASE_API = process.env.VUE_APP_BASE_API;

View File

@ -169,8 +169,10 @@ export default {
this.linkList.forEach(link => { this.linkList.forEach(link => {
if (link && link.leftFdCode && link.leftSdCode) { // link if (link && link.leftFdCode && link.leftSdCode) { // link
linkObj[`${link.code}`] = { name: '', num: 0 }; linkObj[`${link.code}`] = { name: '', num: 0 };
linkObj[`${link.leftSdCode}`] = { name: '', num: 0 };
} else if (link && link.rightFdCode && link.rightSdCode) { // link } else if (link && link.rightFdCode && link.rightSdCode) { // link
linkObj[`${link.code}`] = { name: '', num: 0 }; linkObj[`${link.code}`] = { name: '', num: 0 };
linkObj[`${link.rightSdCode}`] = { name: '', num: 0 };
} else if (link && link.leftFdCode && !link.leftSdCode && link.rightFdCode && !link.rightSdCode) { // linklink } else if (link && link.leftFdCode && !link.leftSdCode && link.rightFdCode && !link.rightSdCode) { // linklink
linkObj[`${link.code}`] = { name: '', num: 0 }; linkObj[`${link.code}`] = { name: '', num: 0 };
} }
@ -277,8 +279,9 @@ export default {
createArr.push(item); createArr.push(item);
} }
} else { } else {
console.log(linkObj, item, sectionC, linkObj[sectionC.linkCode]);
this.questionList.push(`${this.$t('map.section')}${linkObj[sectionA.linkCode].name}${this.$t('tip.linkNoneSplit')}, ${this.$t('tip.createSwitchPortion')}`); this.questionList.push(`${this.$t('map.section')}${linkObj[sectionA.linkCode].name}${this.$t('tip.linkNoneSplit')}, ${this.$t('tip.createSwitchPortion')}`);
this.questionList.push(`${this.$t('map.section')}${linkObj[sectionC.linkCode].name}${this.$t('tip.linkNoneSplit')}, ${this.$t('tip.createSwitchPortion')}`); // this.questionList.push(`${this.$t('map.section')}${linkObj[sectionC.linkCode].name}${this.$t('tip.linkNoneSplit')}, ${this.$t('tip.createSwitchPortion')}`);
} }
}); });
this.$confirm(this.$t('tip.confirmBatchGeneration'), this.$t('tip.hint'), { this.$confirm(this.$t('tip.confirmBatchGeneration'), this.$t('tip.hint'), {

View File

@ -382,7 +382,7 @@ export default {
{ prop: 'namePosition.x', firstLevel: 'namePosition', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px' }, { prop: 'namePosition.x', firstLevel: 'namePosition', secondLevel: 'x', label: 'x:', type: 'number', labelWidth: '25px' },
{ prop: 'namePosition.y', firstLevel: 'namePosition', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px' } { prop: 'namePosition.y', firstLevel: 'namePosition', secondLevel: 'y', label: 'y:', type: 'number', labelWidth: '25px' }
] }, ] },
{ prop: 'type', label: this.$t('map.sectionType'), type: 'select', optionLabel: 'name', optionValue: 'code', options: this.SectionTypeList, disabled: true }, { prop: 'type', label: this.$t('map.sectionType'), type: 'select', optionLabel: 'name', optionValue: 'code', options: this.SectionTypeList },
{ prop: 'parentCode', label: this.$t('map.associatedSection'), type: 'select', mode: true, optionLabel: 'name&&code', optionValue: 'code', disabled: true, options: this.sectionList, isHidden: !this.isParentCode }, { prop: 'parentCode', label: this.$t('map.associatedSection'), type: 'select', mode: true, optionLabel: 'name&&code', optionValue: 'code', disabled: true, options: this.sectionList, isHidden: !this.isParentCode },
{ prop: 'isStandTrack', label: this.$t('map.isStandTrack'), type: 'checkbox', isHidden: !this.isSwitchSectionShow }, // 1 { prop: 'isStandTrack', label: this.$t('map.isStandTrack'), type: 'checkbox', isHidden: !this.isSwitchSectionShow }, // 1

View File

@ -162,135 +162,94 @@ export default {
this.editModel = deepAssign(this.editModel, selected); this.editModel = deepAssign(this.editModel, selected);
} }
}, },
findSectionA(pointX, pointY) {
const list = [];
this.sectionList.forEach(item => {
if (item.point[0].x == pointX && item.point[0].y == pointY) {
list.push(item);
}
});
return list;
},
findSectionB(pointX, pointY) {
const list = [];
this.sectionList.forEach(item => {
if (item.point[item.point.length - 1].x == pointX && item.point[item.point.length - 1].y == pointY) {
list.push(item);
}
});
return list;
},
create() { // create() { //
this.questionList = []; // // this.questionList = []; //
const models = []; // const models = [];
const linkObj = {}; const createArr = []; // model
this.linkList.forEach(link => {
if (link && link.leftFdCode && link.leftSdCode) { // link
linkObj[`${link.code}`] = { name: '', num: 0 };
} else if (link && link.rightFdCode && link.rightSdCode) { // link
linkObj[`${link.code}`] = { name: '', num: 0 };
} else if (link && link.leftFdCode && !link.leftSdCode && link.rightFdCode && !link.rightSdCode) { // linklink
linkObj[`${link.code}`] = { name: '', num: 0 };
}
});
this.sectionList.forEach(section => { this.sectionList.forEach(section => {
for (const link in linkObj) { if (!section.rightSectionCode && section.type == '03') { //
if (section.linkCode == link) { const list = this.findSectionA(section.point[section.point.length - 1].x, section.point[section.point.length - 1].y);
linkObj[link].num++; let sectionB = {};
linkObj[link].name = section.name; let sectionC = {};
} list.forEach(item => {
} if (item.point[1].y == section.point[section.point.length - 1].y) { //
const uname = 'switch_' + section.name.replace('section_', ''); sectionB = item;
const link = this.findLinkData(section.linkCode); } else {
if (link && link.leftFdCode && link.leftSdCode) { sectionC = item;
const node = this.findLinkData(link.leftSdCode); // link
if (node) {
const lFdSection = this.findSectionDataByLinkCodeAndPoint(link.leftFdCode, section.points[0]);
const lSdSection = this.findSectionDataByLinkCodeAndPoint(link.leftSdCode, section.points[0]);
if (lFdSection && lSdSection) {
const model = {
_type: 'Switch',
code: getUID('Switch'),
name: uname,
nameShow: true,
timeoutShow: true,
sectionACode: section.code,
sectionBCode: lFdSection.code,
sectionCCode: lSdSection.code,
namePosition: { x: 0, y: 0 },
turnTime: 3,
tp: { x: 0, y: 0 },
lp: {
x: lFdSection.points[lFdSection.points.length - 1].x,
y: lFdSection.points[lFdSection.points.length - 1].y
},
rp: {
x: lSdSection.points[lSdSection.points.length - 2].x,
y: lSdSection.points[lSdSection.points.length - 2].y
},
intersection: {
x: section.points[0].x,
y: section.points[0].y
},
skew: {
x: lSdSection.points[lSdSection.points.length - 2].x,
y: lSdSection.points[lSdSection.points.length - 2].y
}
};
const swch = this.findSwitchData(model.sectionACode, model.sectionBCode, model.sectionCCode);
!swch && models.push(model); //
} }
} });
const uname = 'switch_' + section.name.replace('section_', '');
const model = {
_type: 'Switch',
code: getUID('Switch'),
name: uname,
nameShow: true,
timeoutShow: true,
sectionACode: section.code,
sectionBCode: sectionB.code,
sectionCCode: sectionC.code,
namePosition: { x: 0, y: 0 },
turnTime: 3,
tp: { x: 0, y: 0 }
};
const swch = this.findSwitchData(model.sectionACode, model.sectionBCode, model.sectionCCode);
!swch && createArr.push(model); //
} }
if (!section.leftSectionCode && section.type == '03') { //
if (link && link.rightFdCode && link.rightSdCode) { const list = this.findSectionB(section.point[0].x, section.point[0].y);
const node = this.findLinkData(link.rightSdCode); let sectionB = {};
if (node) { let sectionC = {};
const rFdSection = this.findSectionDataByLinkCodeAndPoint(link.rightFdCode, section.points[section.points.length - 1]); list.forEach(item => {
const rSdSection = this.findSectionDataByLinkCodeAndPoint(link.rightSdCode, section.points[section.points.length - 1]); if (item.point[item.point.length - 2].y == section.point[0].y) { //
if (rFdSection && rSdSection) { sectionB = item;
const model = { } else {
_type: 'Switch', sectionC = item;
code: getUID('Switch'),
name: uname,
nameShow: true,
timeoutShow: true,
sectionACode: section.code,
sectionBCode: rFdSection.code,
sectionCCode: rSdSection.code,
namePosition: { x: 0, y: 0 },
turnTime: 3,
tp: { x: 0, y: 0 },
lp: {
x: rFdSection.points[0].x,
y: rFdSection.points[0].y
},
rp: {
x: rSdSection.points[1].x,
y: rSdSection.points[1].y
},
intersection: {
x: section.points[section.points.length - 1].x,
y: section.points[section.points.length - 1].y
},
skew: {
x: rSdSection.points[1].x,
y: rSdSection.points[1].y
}
};
const swch = this.findSwitchData(model.sectionACode, model.sectionBCode, model.sectionCCode);
!swch && models.push(model);
} }
} });
} const uname = 'switch_' + section.name.replace('section_', '');
}); const model = {
const createArr = []; _type: 'Switch',
models.forEach((item) => { code: getUID('Switch'),
const sectionA = this.$store.getters['map/getDeviceByCode'](item.sectionACode); name: uname,
// const sectionB = this.$store.getters['map/getDeviceByCode'](item.sectionBCode); nameShow: true,
const sectionC = this.$store.getters['map/getDeviceByCode'](item.sectionCCode); timeoutShow: true,
if (linkObj[sectionA.linkCode] && linkObj[sectionC.linkCode]) { sectionACode: section.code,
if (linkObj[sectionA.linkCode].num > 1 && linkObj[sectionC.linkCode].num > 1 ) { sectionBCode: sectionB.code,
createArr.push(item); sectionCCode: sectionC.code,
} namePosition: { x: 0, y: 0 },
} else { turnTime: 3,
this.questionList.push(`${this.$t('map.section')}${linkObj[sectionA.linkCode].name}${this.$t('tip.linkNoneSplit')}, ${this.$t('tip.createSwitchPortion')}`); tp: { x: 0, y: 0 }
this.questionList.push(`${this.$t('map.section')}${linkObj[sectionC.linkCode].name}${this.$t('tip.linkNoneSplit')}, ${this.$t('tip.createSwitchPortion')}`); };
const swch = this.findSwitchData(model.sectionACode, model.sectionBCode, model.sectionCCode);
!swch && createArr.push(model); //
} }
}); });
console.log(createArr, '生成的道岔');
this.$confirm(this.$t('tip.confirmBatchGeneration'), this.$t('tip.hint'), { this.$confirm(this.$t('tip.confirmBatchGeneration'), this.$t('tip.hint'), {
confirmButtonText: this.$t('tip.confirm'), confirmButtonText: this.$t('tip.confirm'),
cancelButtonText: this.$t('tip.cancel'), cancelButtonText: this.$t('tip.cancel'),
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
for (const link in linkObj) {
if (linkObj[link].num == 1) {
this.questionList.push(`${this.$t('map.section')}${linkObj[link].name}${this.$t('tip.linkNoneSplit')}, ${this.$t('tip.createSwitchPortion')}`);
}
}
const models = this.createSwitchSection(createArr); const models = this.createSwitchSection(createArr);
models.forEach(item => { models.forEach(item => {
createArr.push(item); createArr.push(item);
@ -309,6 +268,8 @@ export default {
if (valid) { if (valid) {
const data = Object.assign({_type: 'Switch'}, this.editModel); const data = Object.assign({_type: 'Switch'}, this.editModel);
this.$emit('updateMapModel', data); this.$emit('updateMapModel', data);
} else {
this.$message('还有属性未填写,修改未生效!');
} }
}); });
}, },
@ -333,31 +294,20 @@ export default {
handleDelete(selected) { handleDelete(selected) {
const models = []; const models = [];
this.sectionList.forEach(elem => { this.sectionList.forEach(elem => {
if (elem.type == '03' && elem.relSwitchCode == selected.code) { if (elem.type == '04' && elem.relSwitchCode == selected.code) { //
models.push(deepAssign({ _type: 'Section', code: elem.code }, { _dispose: true })); models.push(deepAssign({ _type: 'Section', code: elem.code }, { _dispose: true }));
} }
if (elem.relSwitchCode == selected.code && elem.type != '03') { if (elem.relSwitchCode == selected.code && elem.type == '03') { //
elem.relSwitchCode = ''; const section = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.code));
elem.isSwitchSection = false; section.relSwitchCode = '';
models.push(elem); section.parentCode = '';
section.isSwitchSection = false;
models.push(section);
} }
}); });
models.push(deepAssign(selected, { _dispose: true })); models.push(deepAssign(selected, { _dispose: true }));
this.$emit('updateMapModel', models); this.$emit('updateMapModel', models);
}, },
findLinkData(code) {
var rtn = null;
var linkList = this.linkList;
if (linkList && linkList.length) {
for (var i = 0; i < linkList.length; ++i) {
if (code === linkList[i].code) {
rtn = linkList[i];
break;
}
}
}
return rtn;
},
findSectionDataByLinkCodeAndPoint(code, point) { findSectionDataByLinkCodeAndPoint(code, point) {
var rtn = null; var rtn = null;
var sectionList = this.sectionList; var sectionList = this.sectionList;
@ -389,34 +339,48 @@ export default {
} }
return rtn; return rtn;
}, },
// //
removeSwitchSection() {
const models = [];
if (this.sectionList && this.sectionList.length) {
this.sectionList.forEach(elem => {
// /
if (elem.type === '03' && !elem.parentCode) {
models.push(deepAssign({ _type: 'Section', code: elem.code }, { _dispose: true }));
}
if (elem.relSwitchCode) {
elem.relSwitchCode = '';
elem.isSwitchSection = false;
models.push(elem);
}
});
this.$emit('updateMapModel', models);
}
},
//
createSwitchSection(list) { createSwitchSection(list) {
const models = []; const models = [];
if (list && list.length && this.sectionList && this.sectionList.length) { if (list && list.length && this.sectionList && this.sectionList.length) {
const sectionList = [];
list.forEach(elem => { list.forEach(elem => {
const sectionb = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionBCode));
const sectiona = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionACode));
const sectionc = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionCCode));
if (sectiona && sectionb && sectionc) {
const uid = getUID('Section');
elem['uid'] = uid;
list.forEach(ele => {
const sectiona1 = deepAssign({}, this.$store.getters['map/getDeviceByCode'](ele.sectionACode));
const sectionb1 = deepAssign({}, this.$store.getters['map/getDeviceByCode'](ele.sectionBCode));
if (sectionb.points[0] == sectionb1.points[sectionb1.points.length - 1]) {
sectionList.push(elem);
}
if (sectiona1.points[0] == sectiona.points[sectiona.points.length - 1]) {
sectionList.push(elem);
}
});
sectiona.parentCode = uid;
sectionb.parentCode = uid;
sectionc.parentCode = uid;
sectiona.relSwitchCode = elem.code;
sectionb.relSwitchCode = elem.code;
sectionc.relSwitchCode = elem.code;
sectiona.isSwitchSection = true;
sectionb.isSwitchSection = true;
sectionc.isSwitchSection = true;
models.push(sectiona);
models.push(sectionb);
models.push(sectionc);
}
});
console.log(sectionList, '生成道岔计轴区段');
sectionList.forEach(elem => {
const sectiona = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionACode)); const sectiona = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionACode));
const sectionb = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionBCode)); const sectionb = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionBCode));
const sectionc = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionCCode)); const sectionc = deepAssign({}, this.$store.getters['map/getDeviceByCode'](elem.sectionCCode));
if (sectiona && sectionb && sectionc) { if (sectiona && sectionb && sectionc) {
const uid = getUID('Section');
let point = { let point = {
x: sectiona.points[sectiona.points.length - 1].x, x: sectiona.points[sectiona.points.length - 1].x,
y: sectiona.points[sectiona.points.length - 1].y y: sectiona.points[sectiona.points.length - 1].y
@ -426,9 +390,9 @@ export default {
} }
models.push({ models.push({
_type: 'Section', _type: 'Section',
code: uid, code: elem.uid,
name: sectiona.name || sectionb.name || sectionc.name, name: sectiona.name,
type: '03', type: '04',
axleShow: false, axleShow: false,
namePosition: point, namePosition: point,
isStandTrack: false, isStandTrack: false,
@ -457,21 +421,9 @@ export default {
parentCode: '', parentCode: '',
stationCode: sectiona.stationCode, stationCode: sectiona.stationCode,
trainPosType: sectiona.trainPosType, trainPosType: sectiona.trainPosType,
isCurve: false, isCurve: false
linkCode: '0'
}); });
sectiona.parentCode = uid;
sectiona.relSwitchCode = elem.code;
sectiona.isSwitchSection = true;
sectionb.parentCode = uid;
sectionb.relSwitchCode = elem.code;
sectionb.isSwitchSection = true;
sectionc.parentCode = uid;
sectionc.relSwitchCode = elem.code;
sectionc.isSwitchSection = true;
models.push(sectiona);
models.push(sectionb);
models.push(sectionc);
} }
}); });
} }