rt-sim-training-client/src/jmapNew/shape/Switch/EMouse.js

129 lines
4.6 KiB
JavaScript
Raw Normal View History

2019-11-29 12:51:58 +08:00
import Group from 'zrender/src/container/Group';
import Rect from 'zrender/src/graphic/shape/Rect';
2020-04-01 13:47:29 +08:00
import store from '@/store/index_APP_TARGET';
2019-11-29 12:51:58 +08:00
class EMouse extends Group {
2020-03-24 18:01:10 +08:00
constructor(device) {
super();
this.device = device;
this.create();
this.craeteSwitchBorder();
}
create() {
if (this.device.name) {
// 创建锁闭框
const rect = this.device.name.getNameText().getBoundingRect();
let textWidth = rect.width * 0.8;
if (this.device.triangle.drictx !== 1) {
// rect.x += rect.width;
textWidth = -textWidth;
}
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
this.textRect = new Rect({
zlevel: this.device.zlevel,
z: this.device.z,
silent: true,
shape: {
x: rect.x,
y: rect.y,
width: textWidth,
height: rect.height
},
style: {
lineWidth: 1,
lineDash: [3, 3],
stroke: this.device.style.Switch.mouseOverStyle.borderColor,
fill: this.device.style.Switch.mouseOverStyle.borderBackgroundColor
}
});
this.add(this.textRect);
this.textRect.hide();
}
}
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
// 创建道岔边框
craeteSwitchBorder() {
const sectionA = this.getInstanceByCode(this.device.model.sectionACode);
const sectionB = this.getInstanceByCode(this.device.model.sectionBCode);
const sectionC = this.getInstanceByCode(this.device.model.sectionCCode);
const rect = this.device.getBoundingRect();
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
sectionA && rect.union(sectionA.getBoundingRect());
sectionB && rect.union(sectionB.getBoundingRect());
sectionC && rect.union(sectionC.getBoundingRect());
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
this.switchBorder = new Rect({
zlevel: this.device.model.zlevel,
z: this.device.z,
silent: true,
shape: Object.assign({ r: 4 }, rect),
style: {
lineDash: [3, 3],
stroke: this.device.style.Switch.mouseOverStyle.borderColor,
fill: this.device.style.transparentColor
}
});
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
this.add(this.switchBorder);
this.switchBorder.hide();
}
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
getInstanceByCode(code) {
return (store.getters['map/getDeviceByCode'](code) || {}).instance;
}
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
mouseout(e) {
if (!this.device.model.down) {
this.switchBorder && this.switchBorder.hide();
this.device.setTextStyle({
textFill: this.device.style.backgroundColor
});
this.textRect && this.textRect.hide();
this.device.setState(this.device.model);
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
const section = store.getters['map/getDeviceByCode'](this.device.model.sectionACode) || {};
const parentSection = store.getters['map/getDeviceByCode'](section.parentCode) || {};
const instance = this.getInstanceByCode(parentSection.trainWindowCode);
if (instance && instance.mouseEvent && instance.mouseEvent.mouseLeave) {
instance.mouseEvent.mouseLeave(e);
}
}
}
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
mouseover(e) {
this.switchBorder && this.switchBorder.show();
// this.device.setLossAction(false);
// this.device.setSwitchCoreColor(this.device.style.Switch.mouseOverStyle.borderBackgroundColor);
this.device.setTextStyle({
textFill: '#000'
});
this.textRect && this.textRect.show();
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
const section = store.getters['map/getDeviceByCode'](this.device.model.sectionACode) || {};
const parentSection = store.getters['map/getDeviceByCode'](section.parentCode) || {};
const instance = this.getInstanceByCode(parentSection.trainWindowCode);
if (instance && instance.mouseEvent && instance.mouseEvent.mouseEnter) {
instance.mouseEvent.mouseEnter(e);
}
}
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
mouseEnter(e) {
this.switchBorder && this.switchBorder.show();
// this.device.setLossAction(false);
// this.device.setSwitchCoreColor(this.device.style.Switch.mouseOverStyle.borderBackgroundColor);
this.device.setTextStyle({
textFill: '#000'
});
this.textRect && this.textRect.show();
}
2019-11-29 12:51:58 +08:00
2020-03-24 18:01:10 +08:00
mouseLeave(e) {
this.switchBorder && this.switchBorder.hide();
this.device.setTextStyle({
textFill: this.device.style.backgroundColor
});
this.textRect && this.textRect.hide();
this.device.setState(this.device.model);
}
2019-11-29 12:51:58 +08:00
}
export default EMouse;