From 83faa429fe1ba7d0a2ab4f5df75ef390cd16ebf1 Mon Sep 17 00:00:00 2001 From: zyy <1787816799@qq.com> Date: Wed, 7 Aug 2019 11:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=97=E8=BD=A6=E8=AF=A6?= =?UTF-8?q?=E6=83=85=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/jmap/map.js | 16 ++++++++++++---- src/jmap/mouseController.js | 10 ++++------ src/jmap/shape/LcControl/EMouse.js | 3 +-- src/jmap/shape/LimitControl/EMouse.js | 3 +-- src/jmap/shape/StationControl/EMouse.js | 3 +-- src/jmap/shape/StationStand/EMouse.js | 3 +-- src/jmap/shape/Switch/EMouse.js | 3 +-- src/jmap/shape/Train/TrainBody/EMouse.js | 23 +++++++++++++---------- src/jmap/shape/Train/TrainBody/index.js | 12 +++++++++--- src/jmap/shape/Train/index.js | 3 ++- src/jmap/shape/ZcControl/EMouse.js | 3 +-- 11 files changed, 46 insertions(+), 36 deletions(-) diff --git a/src/jmap/map.js b/src/jmap/map.js index 4239aa7c6..279952985 100644 --- a/src/jmap/map.js +++ b/src/jmap/map.js @@ -166,7 +166,7 @@ class Jlmap { } // 中间处理 - hookHandle(elem) { + hookHandle(oDevice, elem) { const code = elem.code; const type = elem._type; // 如果是延时计时,需要保存计数值到全局 @@ -179,7 +179,14 @@ class Jlmap { localStore(code, val); } - return elem; + for (var prop in elem) { + if (elem[prop] != oDevice[prop]) { + Object.assign(oDevice, elem); + return true; + } + } + + return false; } // 后处理 @@ -234,8 +241,9 @@ class Jlmap { if (elem.dispose) { this.$painter.delete(oDevice); } else { - const nDevice = Object.assign(oDevice, this.hookHandle(elem)); - this.$painter.update(nDevice); + if (this.hookHandle(oDevice, elem)) { + this.$painter.update(oDevice); + } } }); diff --git a/src/jmap/mouseController.js b/src/jmap/mouseController.js index c4c095ceb..e6e07b95d 100644 --- a/src/jmap/mouseController.js +++ b/src/jmap/mouseController.js @@ -152,12 +152,10 @@ class MouseController extends Eventful { moveEvent(e) { const newEm = new EventModel(e); const trainDetails = store.state.map.trainDetails; - if (trainDetails && trainDetails.model) { - if (newEm.deviceType != deviceType.Train || trainDetails.model._code != newEm.deviceCode) { - var model = trainDetails.model; - var instances = (this._viewRepo.__getViewInstancesByDeviceType(deviceType.Train) || {})._instances || {}; - var device = instances[model._code] || {}; - device.removeTrainDetail && device.removeTrainDetail(); + if (trainDetails) { + if (newEm.deviceType != deviceType.Train || trainDetails.code != newEm.deviceCode) { + var instance = (this.$jmap.getDeviceByCode(trainDetails.code) || {} ).instance; + instance && instance.removeTrainDetail && instance.removeTrainDetail(); } } } diff --git a/src/jmap/shape/LcControl/EMouse.js b/src/jmap/shape/LcControl/EMouse.js index 888078973..fdb639e95 100644 --- a/src/jmap/shape/LcControl/EMouse.js +++ b/src/jmap/shape/LcControl/EMouse.js @@ -5,7 +5,6 @@ export default class EMouse extends Group { constructor(device) { super(); this.device = device; - this.down = false; this.create(); } create() { @@ -40,7 +39,7 @@ export default class EMouse extends Group { } mouseout(e) { - if (!this.down) { + if (!this.device.model.down) { if (e.target && e.target._subType == 'Text') { this.text.hide(); } else { diff --git a/src/jmap/shape/LimitControl/EMouse.js b/src/jmap/shape/LimitControl/EMouse.js index c3059f84a..4abd12d5d 100644 --- a/src/jmap/shape/LimitControl/EMouse.js +++ b/src/jmap/shape/LimitControl/EMouse.js @@ -5,7 +5,6 @@ export default class EMouse extends Group { constructor(device) { super(); this.device = device; - this.down = false; this.create(); } create() { @@ -41,7 +40,7 @@ export default class EMouse extends Group { } mouseout(e) { - if (!this.down) { + if (!this.device.model.down) { if (e.target && e.target._subType == 'Text') { this.text.hide(); } else { diff --git a/src/jmap/shape/StationControl/EMouse.js b/src/jmap/shape/StationControl/EMouse.js index ba4d567b6..8850a1e30 100644 --- a/src/jmap/shape/StationControl/EMouse.js +++ b/src/jmap/shape/StationControl/EMouse.js @@ -5,7 +5,6 @@ export default class EMouse extends Group { constructor(device) { super(); this.device = device; - this.down = false; this.create(); } create() { @@ -56,7 +55,7 @@ export default class EMouse extends Group { } mouseout(e) { - if (!this.down) { + if (!this.device.model.down) { this.text.hide(); } } diff --git a/src/jmap/shape/StationStand/EMouse.js b/src/jmap/shape/StationStand/EMouse.js index 40e191f29..ecf66d1c9 100644 --- a/src/jmap/shape/StationStand/EMouse.js +++ b/src/jmap/shape/StationStand/EMouse.js @@ -7,7 +7,6 @@ export default class EMouse extends Group { this.device = device; this.zlevel = device.zlevel; this.style = device.style; - this.down = false; this.create(); } @@ -32,7 +31,7 @@ export default class EMouse extends Group { } mouseout(e) { - if (!this.down) { + if (!this.device.model.down) { this.border.hide(); } } diff --git a/src/jmap/shape/Switch/EMouse.js b/src/jmap/shape/Switch/EMouse.js index dcfb31d0a..89b6e57fa 100644 --- a/src/jmap/shape/Switch/EMouse.js +++ b/src/jmap/shape/Switch/EMouse.js @@ -4,7 +4,6 @@ import store from '@/store'; class EMouse extends Group { constructor(device) { super(); - this.down = false; this.device = device; this.create(); this.craeteSwitchBorder(); @@ -73,7 +72,7 @@ class EMouse extends Group { } mouseout(e) { - if (!this.down) { + if (!this.device.model.down) { this.switchBorder && this.switchBorder.hide(); this.device.setTextStyle({ textFill: this.device.style.backgroundColor diff --git a/src/jmap/shape/Train/TrainBody/EMouse.js b/src/jmap/shape/Train/TrainBody/EMouse.js index 194c95f06..1279457ad 100644 --- a/src/jmap/shape/Train/TrainBody/EMouse.js +++ b/src/jmap/shape/Train/TrainBody/EMouse.js @@ -2,15 +2,14 @@ import Group from 'zrender/src/container/Group'; import Text from 'zrender/src/graphic/Text'; class EMouse extends Group { - constructor(device, style) { + constructor(device) { super(); - this.down = false; this.device = device; this.create(); } create() { let destinationText = ''; - switch (this.device.destinationStatus) { + switch (this.device.model.destinationStatus) { case '01': destinationText = '准点'; break; case '02': destinationText = '早点'; break; case '03': destinationText = '严重早点'; break; @@ -20,17 +19,17 @@ class EMouse extends Group { } // 文字描述 this.arrowText = new Text({ - zlevel: this.device.zlevel, - z: this.device.z, + zlevel: this.device.model.zlevel, + z: this.device.model.z, style: { - x: this.device.point.x + 50, - y: this.device.point.y + 25, - text: `列车类型: 计划车\n表\0\0\0\0号: ${this.device.serviceNumber}\n车\0次\0号: ${this.device.tripNumber}\n目的地号: ${this.device.targetCode ? this.device.targetCode : ''}\n车\0组\0号: ${this.device.groupNumber}\n早\0晚\0点: ${destinationText}\n运行方向: ${this.device.directionType == '02' ? '上行' : '下行'}\n乘务组号: \n起点站名: \n终点站名: \n占用轨道: ${this.device.sectionModel ? this.device.sectionModel.trackName : ''}\n所在车站: \n车地通信: 正常\n运行等级: 4\n扣车状态: ${this.device.runControlStatus == '01' ? '正常' : this.device.runControlStatus == '03' ? '跳停' : '扣车'}\n停稳状态: ${this.device.runStatus == '02' ? '未停稳' : '停稳'}\n阻塞状态: 无\n列车速度: ${this.device.speed || 0} km/h\n列车移动授权距离: ${this.device.maLen || 0} m`, + x: this.device.model.point.x + 50, + y: this.device.model.point.y + 25, + text: `列车类型: 计划车\n表\0\0\0\0号: ${this.device.model.serviceNumber}\n车\0次\0号: ${this.device.model.tripNumber}\n目的地号: ${this.device.model.targetCode ? this.device.model.targetCode : ''}\n车\0组\0号: ${this.device.model.groupNumber}\n早\0晚\0点: ${destinationText}\n运行方向: ${this.device.model.directionType == '02' ? '上行' : '下行'}\n乘务组号: \n起点站名: \n终点站名: \n占用轨道: ${this.device.model.sectionModel ? this.device.model.sectionModel.trackName : ''}\n所在车站: \n车地通信: 正常\n运行等级: 4\n扣车状态: ${this.device.model.runControlStatus == '01' ? '正常' : this.device.model.runControlStatus == '03' ? '跳停' : '扣车'}\n停稳状态: ${this.device.model.runStatus == '02' ? '未停稳' : '停稳'}\n阻塞状态: 无\n列车速度: ${this.device.model.speed || 0} km/h\n列车移动授权距离: ${this.device.model.maLen || 0} m`, textFill: '#000', textAlign: 'letf', textFont: 10 + 'px consolas', textPadding: 3, - textBackgroundColor: this.device.style.tipBackgroundColor + textBackgroundColor: this.device.model.style.tipBackgroundColor } }); this.add(this.arrowText); @@ -38,11 +37,15 @@ class EMouse extends Group { } mouseover() { + this.device.deviceModel.down = true; this.arrowText.show(); } mouseout() { - this.arrowText.hide(); + if (this.device.deviceModel.down) { + this.arrowText.hide(); + this.device.deviceModel.down = false; + } } } diff --git a/src/jmap/shape/Train/TrainBody/index.js b/src/jmap/shape/Train/TrainBody/index.js index 7a7d2ccb8..03c58f204 100644 --- a/src/jmap/shape/Train/TrainBody/index.js +++ b/src/jmap/shape/Train/TrainBody/index.js @@ -14,16 +14,21 @@ export default class TrainBody extends Group { constructor(model) { super(); this.model = model; + this.deviceModel = model.model; this.create(); - console.log(this.model); this.createMouse(); // 鼠标事件 } createMouse() { - this.mouseEvent = new EMouse(this.model); + this.mouseEvent = new EMouse(this); this.add(this.mouseEvent); + if (this.deviceModel.down) { + store.dispatch('map/setTrainDetails', this.deviceModel); + this.mouseEvent.mouseover(); + } + this.on('mouseover', () => { - store.dispatch('map/setTrainDetails', true); + store.dispatch('map/setTrainDetails', this.deviceModel); this.mouseEvent.mouseover(); }); this.on('mouseout', () => { @@ -139,6 +144,7 @@ export default class TrainBody extends Group { removeTrainDetail() { this.mouseEvent.mouseout(); store.dispatch('map/setTrainDetails', null); + this.deviceModel.down = false; } setTrainColor(color) { this.train && this.train.setColor('fill', color); diff --git a/src/jmap/shape/Train/index.js b/src/jmap/shape/Train/index.js index 729343d18..85cf3af96 100644 --- a/src/jmap/shape/Train/index.js +++ b/src/jmap/shape/Train/index.js @@ -69,7 +69,8 @@ export default class Train extends Group { fontSize: this.fontSize, type: model.type, speed: model.speed, - maLen: model.maLen + maLen: model.maLen, + model: model }); this.trainL = new TrainHead({ style: style, diff --git a/src/jmap/shape/ZcControl/EMouse.js b/src/jmap/shape/ZcControl/EMouse.js index 4326ec949..0855053f9 100644 --- a/src/jmap/shape/ZcControl/EMouse.js +++ b/src/jmap/shape/ZcControl/EMouse.js @@ -5,7 +5,6 @@ export default class EMouse extends Group { constructor(device) { super(); this.device = device; - this.down = false; this.create(); } create() { @@ -41,7 +40,7 @@ export default class EMouse extends Group { } mouseout(e) { - if (!this.down) { + if (!this.device.model.down) { if (e.target && e.target._subType == 'Text') { this.text.hide(); } else {