From b85dcb41dc142eb66ceb7b6a7b5c9325dfdd6912 Mon Sep 17 00:00:00 2001 From: zyy <1787816799@qq.com> Date: Tue, 15 Dec 2020 11:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=81=93=E5=B2=94=E7=94=9F?= =?UTF-8?q?=E6=88=90=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jmapNew/utils/parser.js | 21 +- .../newMapdraft/mapoperate/section/create.vue | 52 ++--- .../newMapdraft/mapoperate/switch/create.vue | 181 ++++++++++++------ 3 files changed, 165 insertions(+), 89 deletions(-) diff --git a/src/jmapNew/utils/parser.js b/src/jmapNew/utils/parser.js index 34742137b..ae1c91b28 100644 --- a/src/jmapNew/utils/parser.js +++ b/src/jmapNew/utils/parser.js @@ -183,14 +183,22 @@ export function parser(data, skinCode, showConfig) { if (sectionParent) { sectionParent['switch'] = mapDevice[elem.code]; } + let sectionCStar, sectionCEnd; + if (handleResetPoint(rnodeSection.points)) { + sectionCStar = rnodeSection.points[0]; + sectionCEnd = rnodeSection.points[1]; + } else { + sectionCStar = rnodeSection.points[1]; + sectionCEnd = rnodeSection.points[0]; + } if (cnodeSection.points[0].x == lnodeSection.points[lnodeSection.points.length - 1].x && cnodeSection.points[0].y == lnodeSection.points[lnodeSection.points.length - 1].y) { mapDevice[elem.code].intersection = { x: cnodeSection.points[0].x, y: cnodeSection.points[0].y }; mapDevice[elem.code].skew = { - x: rnodeSection.points[rnodeSection.points.length - 2].x, - y: rnodeSection.points[rnodeSection.points.length - 2].y + x: sectionCStar.x, + y: sectionCStar.y }; } else if (cnodeSection.points[cnodeSection.points.length - 1].x == lnodeSection.points[0].x && cnodeSection.points[cnodeSection.points.length - 1].y == lnodeSection.points[0].y) { mapDevice[elem.code].intersection = { @@ -198,8 +206,8 @@ export function parser(data, skinCode, showConfig) { y: cnodeSection.points[cnodeSection.points.length - 1].y }; mapDevice[elem.code].skew = { - x: rnodeSection.points[1].x, - y: rnodeSection.points[1].y + x: sectionCEnd.x, + y: sectionCEnd.y }; } @@ -254,6 +262,11 @@ export function parser(data, skinCode, showConfig) { return mapDevice; } +// 重置坐标点 +function handleResetPoint(points) { + return (points[points.length - 1].x >= points[0].x) && (points[points.length - 1].y >= points[0].y); +} + // 同步绘制数据到原始数据 export function updateForList(model, state, lstName) { const list = state.map[lstName]; diff --git a/src/views/newMap/newMapdraft/mapoperate/section/create.vue b/src/views/newMap/newMapdraft/mapoperate/section/create.vue index 3af9ba21a..dff9f0e94 100644 --- a/src/views/newMap/newMapdraft/mapoperate/section/create.vue +++ b/src/views/newMap/newMapdraft/mapoperate/section/create.vue @@ -260,33 +260,33 @@ export default { const end_x = endModel.points[0].x; const start_y = startModel.points[startModel.points.length - 1].y; const end_y = endModel.points[0].y; - if (end_x > start_x) { - if (this.createModel.leftSectionCode === this.createModel.rightSectionCode) { - this.$messageBox('左关联区段不能和右关联区段相同'); - return; - } - if (start_x === end_x && start_y === end_y) { - this.$messageBox('左关联区段终点不能和右关联区段起点相同'); - return; - } - model.points = [ - { x: start_x, y: start_y }, - { x: end_x, y: end_y } - ]; - const models = []; - model.leftSectionCode = this.createModel.leftSectionCode; - startModel.rightSectionCode = model.code; - endModel.leftSectionCode = model.code; - model.rightSectionCode = this.createModel.rightSectionCode; - models.push(model); - models.push(startModel); - models.push(endModel); - this.$emit('updateMapModel', models); - } else { - this.$messageBox('画图顺序应左往右绘制, 请求重新定义左右关联区段'); - this.createModel.rightSectionCode = ''; - this.createModel.leftSectionCode = ''; + // if (end_x > start_x) { + if (this.createModel.leftSectionCode === this.createModel.rightSectionCode) { + this.$messageBox('左关联区段不能和右关联区段相同'); + return; } + if (start_x === end_x && start_y === end_y) { + this.$messageBox('左关联区段终点不能和右关联区段起点相同'); + return; + } + model.points = [ + { x: start_x, y: start_y }, + { x: end_x, y: end_y } + ]; + const models = []; + model.leftSectionCode = this.createModel.leftSectionCode; + startModel.rightSectionCode = model.code; + endModel.leftSectionCode = model.code; + model.rightSectionCode = this.createModel.rightSectionCode; + models.push(model); + models.push(startModel); + models.push(endModel); + this.$emit('updateMapModel', models); + // } else { + // this.$messageBox('画图顺序应左往右绘制, 请求重新定义左右关联区段'); + // this.createModel.rightSectionCode = ''; + // this.createModel.leftSectionCode = ''; + // } }, // 创建区段 create() { diff --git a/src/views/newMap/newMapdraft/mapoperate/switch/create.vue b/src/views/newMap/newMapdraft/mapoperate/switch/create.vue index c5f8bde37..832eb1a4b 100644 --- a/src/views/newMap/newMapdraft/mapoperate/switch/create.vue +++ b/src/views/newMap/newMapdraft/mapoperate/switch/create.vue @@ -23,15 +23,21 @@ export default { methods:{ create() { // 一键生成道岔 const createArr = []; // 创建model列表 - const changeSectionList = this.changeSectionAttr(); + const changeSectionList = this.changeSectionAttr(); // 找道岔中心点 changeSectionList.forEach(section => { - if (!section.rightSectionCode) { // 右侧关联关系为空 且 道岔区段 - const list = this.findSectionA(section.points[section.points.length - 1].x, section.points[section.points.length - 1].y); + if (section['typeModel'] && section['typeModel'] == 'start') { // 右侧关联关系为空 且 道岔区段 + const list = this.findSectionA(section.points[section.points.length - 1].x, section.points[section.points.length - 1].y, changeSectionList, section.code); let sectionB = {}; let sectionC = {}; if (list.length >= 2) { list.forEach(item => { - if ((item.points[1].y == section.points[section.points.length - 1].y) || (item.points[1].x == section.points[section.points.length - 1].x)) { // 是否水平拿第二个点判断 + let sectionEnd; + if (this.handleResetPoint(item.points)) { + sectionEnd = item.points[item.points.length - 1]; + } else { + sectionEnd = item.points[0]; + } + if ((sectionEnd.y == section.points[section.points.length - 1].y) || (sectionEnd.x == section.points[section.points.length - 1].x)) { // 是否水平拿第二个点判断 sectionB = item; } else { sectionC = item; @@ -40,6 +46,18 @@ export default { if (section.code && sectionB.code && sectionC.code) { const uname = 'W' + section.name.replace('T', ''); const switchModel = getModel('Switch'); + let intersection; + if (this.handleResetPoint(section.points)) { + intersection = section.points[section.points.length - 1]; + } else { + intersection = section.points[0]; + } + let skew; + if (this.handleResetPoint(sectionC.points)) { + skew = sectionC.points[sectionC.points.length - 1]; + } else { + skew = sectionC.points[0]; + } const data = { code: getUID('W', [...this.switchList, ...createArr]), name: uname, @@ -50,12 +68,12 @@ export default { sectionCCode: sectionC.code, turnTime: 3, intersection: { - x: section.points[section.points.length - 1].x, - y: section.points[section.points.length - 1].y + x: intersection.x, + y: intersection.y }, skew: { - x: sectionC.points[1].x, - y: sectionC.points[1].y + x: skew.x, + y: skew.y }, normalPosition: 1 // 默认状态定位 }; @@ -65,13 +83,19 @@ export default { } } } - if (!section.leftSectionCode) { // 左侧关联关系为空 且 道岔区段 - const list = this.findSectionB(section.points[0].x, section.points[0].y); + if (section['typeModel'] && section['typeModel'] == 'end') { // 左侧关联关系为空 且 道岔区段 + const list = this.findSectionB(section.points[0].x, section.points[0].y, changeSectionList, section.code); let sectionB = {}; let sectionC = {}; if (list.length >= 2) { list.forEach(item => { - if ((item.points[item.points.length - 2].y == section.points[0].y) || (item.points[item.points.length - 2].x == section.points[0].x)) { // 是否水平拿倒数第二个点判断 + let sectionStart; + if (this.handleResetPoint(item.points)) { + sectionStart = item.points[0]; + } else { + sectionStart = item.points[item.points.length - 1]; + } + if ((sectionStart.y == section.points[0].y) || (sectionStart.x == section.points[0].x)) { // 是否水平拿倒数第二个点判断 sectionB = item; } else { sectionC = item; @@ -80,6 +104,18 @@ export default { if (section.code && sectionB.code && sectionC.code) { const uname = 'W' + section.name.replace('T', ''); const switchModel = getModel('Switch'); + let intersection; + if (this.handleResetPoint(section.points)) { + intersection = section.points[0]; + } else { + intersection = section.points[section.points.length - 1]; + } + let skew; + if (this.handleResetPoint(sectionC.points)) { + skew = sectionC.points[0]; + } else { + skew = sectionC.points[sectionC.points.length - 1]; + } const data = { code: getUID('W', [...this.switchList, ...createArr]), name: uname, @@ -90,12 +126,12 @@ export default { sectionCCode: sectionC.code, turnTime: 3, intersection: { - x: section.points[0].x, - y: section.points[0].y + x: intersection.x, + y: intersection.y }, skew: { - x: sectionC.points[sectionC.points.length - 2].x, - y: sectionC.points[sectionC.points.length - 2].y + x: skew.x, + y: skew.y }, normalPosition: 1 // 默认状态定位 }; @@ -121,20 +157,36 @@ export default { this.$message( this.$t('tip.cancelGeneration')); }); }, - findSectionA(pointX, pointY) { + findSectionA(pointX, pointY, lists, code) { const list = []; - this.sectionList.forEach(item => { - if (item.points[0].x == pointX && item.points[0].y == pointY) { - list.push(item); + lists.forEach(item => { + if (item.code != code) { + if (this.handleResetPoint(item.points)) { + if (item.points[0].x == pointX && item.points[0].y == pointY) { + list.push(item); + } + } else { + if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) { + list.push(item); + } + } } }); return list; }, - findSectionB(pointX, pointY) { + findSectionB(pointX, pointY, lists, code) { const list = []; - this.sectionList.forEach(item => { - if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) { - list.push(item); + lists.forEach(item => { + if (item.code != code) { + if (this.handleResetPoint(item.points)) { + if (item.points[item.points.length - 1].x == pointX && item.points[item.points.length - 1].y == pointY) { + list.push(item); + } + } else { + if (item.points[0].x == pointX && item.points[0].y == pointY) { + list.push(item); + } + } } }); return list; @@ -154,6 +206,10 @@ export default { } return rtn; }, + // 重置坐标点 + handleResetPoint(points) { + return (points[points.length - 1].x >= points[0].x) && (points[points.length - 1].y >= points[0].y); + }, // 修改区段属性 changeSectionAttr() { const changeSectionList = []; // 改变的区段列表 @@ -163,48 +219,55 @@ export default { const oneSectionStar = section.points[0]; let countA = 0; let countB = 0; - console.log(changeSectionList); this.sectionList.forEach(elem => { - if (elem.type == '01') { - const twoSection = elem.points[0]; - const twoSectionEnd = elem.points[elem.points.length - 1]; + if (elem.type == '01' && section.code != elem.code) { + let twoSection, twoSectionEnd; + if (this.handleResetPoint(elem.points)) { + twoSection = elem.points[0]; + twoSectionEnd = elem.points[elem.points.length - 1]; + } else { + twoSection = elem.points[elem.points.length - 1]; + twoSectionEnd = elem.points[0]; + } if (oneSection.x == twoSection.x && oneSection.y == twoSection.y) { countA++; if (countA >= 2) { - if (!this.checkAddListA(oneSection, section.code)) { // 右侧关系清空 - const sectionModel = deepAssign({}, section); - sectionModel.rightSectionCode = ''; - sectionModel.sepTypeRight = '00'; // 分隔符 - sectionModel.type = '03'; - const list = this.findSectionA(sectionModel.points[sectionModel.points.length - 1].x, sectionModel.points[sectionModel.points.length - 1].y); - list.forEach(elem => { - const sectionModelElem = deepAssign({}, elem); - sectionModelElem.leftSectionCode = ''; - sectionModelElem.sepTypeLeft = '00'; - sectionModelElem.type = '03'; - changeSectionList.push(sectionModelElem); - }); - changeSectionList.push(sectionModel); - } + // if (!this.checkAddListA(oneSection, section.code)) { // 右侧关系清空 + const sectionModel = deepAssign({}, section); + sectionModel.rightSectionCode = ''; + sectionModel.sepTypeRight = '00'; // 分隔符 + sectionModel.type = '03'; + const list = this.findSectionA(sectionModel.points[sectionModel.points.length - 1].x, sectionModel.points[sectionModel.points.length - 1].y, this.sectionList, sectionModel.code); + list.forEach(elem => { + const sectionModelElem = deepAssign({}, elem); + sectionModelElem.leftSectionCode = ''; + sectionModelElem.sepTypeLeft = '00'; + sectionModelElem.type = '03'; + changeSectionList.push(sectionModelElem); + }); + sectionModel['typeModel'] = 'start'; + changeSectionList.push(sectionModel); + // } } } else if (oneSectionStar.x == twoSectionEnd.x && oneSectionStar.y == twoSectionEnd.y) { countB++; if (countB >= 2) { - if (!this.checkAddListB(oneSectionStar, section.code)) { // 左侧关系清空 - const sectionModel = deepAssign({}, section); - sectionModel.leftSectionCode = ''; - sectionModel.sepTypeLeft = '00'; - sectionModel.type = '03'; - const list = this.findSectionB(sectionModel.points[0].x, sectionModel.points[0].y); - list.forEach(elem => { - const sectionModelElem = deepAssign({}, elem); - sectionModelElem.rightSectionCode = ''; - sectionModelElem.sepTypeRight = '00'; // 分隔符 - sectionModelElem.type = '03'; - changeSectionList.push(sectionModelElem); - }); - changeSectionList.push(sectionModel); - } + // if (!this.checkAddListB(oneSectionStar, section.code)) { // 左侧关系清空 + const sectionModel = deepAssign({}, section); + sectionModel.leftSectionCode = ''; + sectionModel.sepTypeLeft = '00'; + sectionModel.type = '03'; + const list = this.findSectionB(sectionModel.points[0].x, sectionModel.points[0].y, this.sectionList, sectionModel.code); + list.forEach(elem => { + const sectionModelElem = deepAssign({}, elem); + sectionModelElem.rightSectionCode = ''; + sectionModelElem.sepTypeRight = '00'; // 分隔符 + sectionModelElem.type = '03'; + changeSectionList.push(sectionModelElem); + }); + sectionModel['typeModel'] = 'end'; + changeSectionList.push(sectionModel); + // } } } } @@ -213,7 +276,7 @@ export default { }); return changeSectionList; }, - checkAddListA(points, code) { // 判断是否添加list + checkAddListA(points, code) { // 判断是否添加list (暂时不用) let flag = false; this.sectionList.forEach(section => { section.points.forEach((point, index) => { @@ -227,7 +290,7 @@ export default { }); return flag; }, - checkAddListB(points, code) { // 判断是否添加list + checkAddListB(points, code) { // 判断是否添加list (暂时不用) let flag = false; this.sectionList.forEach(section => { section.points.forEach((point, index) => {