优化IBP盘代码

This commit is contained in:
ival 2019-09-03 15:46:16 +08:00
parent 6eb0ac89b8
commit dfcdb5628f
7 changed files with 119 additions and 261 deletions

View File

@ -4,78 +4,99 @@ const deviceRender = {};
/** IbpText渲染配置*/
deviceRender[deviceType.IbpText] = {
_type: deviceType.IbpText,
zlevel: 3
};
/** SquareButton渲染配置*/
deviceRender[deviceType.SquareButton] = {
_type: deviceType.SquareButton,
zlevel: 3
};
/** WarnButton渲染配置*/
deviceRender[deviceType.WarnButton] = {
_type: deviceType.WarnButton,
zlevel: 3
};
/** Arrow渲染配置*/
deviceRender[deviceType.Arrow] = {
_type: deviceType.Arrow,
zlevel: 2
};
/** RotatingButton渲染配置*/
deviceRender[deviceType.RotatingButton] = {
_type: deviceType.RotatingButton,
zlevel: 3
};
/** TipBox渲染配置*/
deviceRender[deviceType.TipBox] = {
_type: deviceType.TipBox,
zlevel: 2,
z: 2
};
/** BackGround渲染配置*/
deviceRender[deviceType.Background] = {
_type: deviceType.Background,
zlevel: 0
};
/** CircularLamp渲染配置 */
deviceRender[deviceType.CircularLamp] = {
_type: deviceType.CircularLamp,
zlevel: 3
};
/** AppendageBox渲染配置 */
deviceRender[deviceType.AppendageBox] = {
_type: deviceType.AppendageBox,
zlevel: 1
};
/** IbpLine渲染配置 */
deviceRender[deviceType.IbpLine] = {
_type: deviceType.IbpLine,
zlevel: 1
};
/** Elevator 渲染配置 */
deviceRender[deviceType.Elevator] = {
_type: deviceType.Elevator,
zlevel: 2,
z: 1
};
/** Key 渲染配置 */
deviceRender[deviceType.Key] = {
_type: deviceType.Key,
zlevel: 4
};
/** TeleTerminal 渲染配置 */
deviceRender[deviceType.TeleTerminal] = {
_type: deviceType.TeleTerminal,
zlevel: 3
};
/** Clock 渲染配置*/
deviceRender[deviceType.Clock] = {
_type: deviceType.Clock,
zlevel: 3
};
/** RotateTip 渲染配置 */
deviceRender[deviceType.RotateTip] = {
_type: deviceType.RotateTip,
zlevel: 3
};
/** Alarm */
deviceRender[deviceType.Alarm] = {
_type: deviceType.Alarm,
zlevel: 3
};

View File

@ -6,7 +6,7 @@ import MouseController from './mouseController';
import Painter from './painter';
import deviceState from '../jmap/constant/deviceState';
import deviceType from './constant/deviceType';
import {calculateDCenter, createBoundingRect, modelFactory} from './utils/parser';
import {calculateDCenter, createBoundingRect, deviceFactory} from './utils/parser';
import { updateIbpData } from './utils/parser';
const renderer = 'canvas';
@ -135,7 +135,7 @@ class IbpPan {
const code = elem.code;
const type = elem._type;
updateIbpData(elem);
const oDevice = this.ibpDevice[code] || {instance: null, event: null, model: modelFactory(type, elem)};
const oDevice = this.ibpDevice[code] || {instance: null, event: null, model: deviceFactory(type, elem)};
const nDevice = {instance: null, event: null, model: Object.assign(oDevice.model || {}, elem)};
this.$painter.delete(oDevice);
if (!elem._dispose) {

View File

@ -59,13 +59,17 @@ class Painter {
* @param {*} device
*/
add(device, draggable) {
device = Object.assign(device, { event: this.$ibp.$mouseController });
const instance = shapefactory(device, this.$ibp);
if (instance) {
device.instance = instance;
draggable?instance.setDraggable():'';
this.$transformHandle.transformView(instance);
this.ibpInstanceLevel[device.model._type].add(instance);
try {
device = Object.assign(device, { event: this.$ibp.$mouseController });
const instance = shapefactory(device, this.$ibp);
if (instance) {
device.instance = instance;
draggable?instance.setDraggable():'';
this.$transformHandle.transformView(instance);
this.ibpInstanceLevel[device.model._type].add(instance);
}
} catch (error) {
console.error(error);
}
}

View File

@ -29,324 +29,139 @@ export function calculateDCenter(viewRect, zrbound) {
return { dx: dx, dy: dy };
}
export function modelFactory(type, elem) {
return Object.assign(elem, { _type: type }, deviceRender[type]);
}
export function createModel(type, model, propConvert) {
const tempModel = modelFactory(type, model);
return { instance: null, event: null, model: propConvert ? propConvert.initPrivateProps(tempModel) : tempModel };
export function deviceFactory(type, elem) {
return Object.assign({instance: null, event: null, model: Object(elem, deviceRender[type])});
}
export function parser(data) {
var ibpDevice = {};
const propConvert = null;
// var propConvert = skinCode ? Vue.prototype.$theme.loadPropConvert(skinCode): null;
if (data) {
Object.assign(data.background);
ibpDevice[data.background.code] = createModel(deviceType.Background, data.background, propConvert);
ibpDevice[data.background.code] = deviceFactory(deviceType.Background, data.background);
zrUtil.each(data.textList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.IbpText, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.IbpText, elem);
}, this);
zrUtil.each(data.squareButtonList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.SquareButton, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.SquareButton, elem);
}, this);
zrUtil.each(data.circularLampList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.CircularLamp, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.CircularLamp, elem);
}, this);
zrUtil.each(data.alarmList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.Alarm, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.Alarm, elem);
}, this);
zrUtil.each(data.arrowList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.Arrow, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.Arrow, elem);
}, this);
zrUtil.each(data.rotatingButtonList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.RotatingButton, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.RotatingButton, elem);
}, this);
zrUtil.each(data.tipBoxList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.TipBox, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.TipBox, elem);
}, this);
zrUtil.each(data.ibpLineList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.IbpLine, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.IbpLine, elem);
}, this);
zrUtil.each(data.appendageBoxList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.AppendageBox, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.AppendageBox, elem);
}, this);
zrUtil.each(data.elevatorList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.Elevator, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.Elevator, elem);
}, this);
zrUtil.each(data.keyList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.Key, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.Key, elem);
}, this);
zrUtil.each(data.teleTerminalList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.TeleTerminal, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.TeleTerminal, elem);
}, this);
zrUtil.each(data.clockList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.Clock, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.Clock, elem);
});
zrUtil.each(data.rotateTipList || [], elem => {
ibpDevice[elem.code] = createModel(deviceType.RotateTip, elem, propConvert);
ibpDevice[elem.code] = deviceFactory(deviceType.RotateTip, elem);
});
}
return ibpDevice;
}
function updateIbpListByDevice(ibp, name, device) {
var list = ibp[name];
if (list) {
const index = list.findIndex(elem => { return elem.code == device.code; });
if (index >= 0) {
list[index].dispose ? list.splice(index, 1) : list[index] = device;
} else {
list.push(device);
}
} else {
ibp[name] = [device];
}
return list;
}
export function updateIbpData(device) {
const ibpData = store.getters['ibp/ibp'];
switch (device._type) {
case deviceType.Background : {
case deviceType.Background :
ibpData.background = device;
break;
}
case deviceType.IbpText : {
if (ibpData.textList && ibpData.textList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.textList.length; i++) {
if (device.code === ibpData.textList[i].code) {
device.dispose ? ibpData.textList.splice(i, 1) :ibpData.textList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.textList.push(device);
}
} else {
ibpData.textList = [device];
}
case deviceType.IbpText :
updateIbpListByDevice(ibpData, 'textList', device);
break;
}
case deviceType.SquareButton : {
if (ibpData.squareButtonList && ibpData.squareButtonList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.squareButtonList.length; i++) {
if (device.code === ibpData.squareButtonList[i].code) {
device.dispose ? ibpData.squareButtonList.splice(i, 1):ibpData.squareButtonList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.squareButtonList.push(device);
}
} else {
ibpData.squareButtonList = [device];
}
case deviceType.SquareButton :
updateIbpListByDevice(ibpData, 'squareButtonList', device);
break;
}
case deviceType.Arrow : {
if (ibpData.arrowList && ibpData.arrowList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.arrowList.length; i++) {
if (device.code === ibpData.arrowList[i].code) {
device.dispose ? ibpData.arrowList.splice(i, 1):ibpData.arrowList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.arrowList.push(device);
}
} else {
ibpData.arrowList = [device];
}
case deviceType.Arrow :
updateIbpListByDevice(ibpData, 'arrowList', device);
break;
}
case deviceType.RotatingButton : {
if (ibpData.rotatingButtonList && ibpData.rotatingButtonList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.rotatingButtonList.length; i++) {
if (device.code === ibpData.rotatingButtonList[i].code) {
device.dispose ? ibpData.rotatingButtonList.splice(i, 1):ibpData.rotatingButtonList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.rotatingButtonList.push(device);
}
} else {
ibpData.rotatingButtonList = [device];
}
case deviceType.RotatingButton :
updateIbpListByDevice(ibpData, 'rotatingButtonList', device);
break;
}
case deviceType.TipBox : {
if (ibpData.tipBoxList && ibpData.tipBoxList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.tipBoxList.length; i++) {
if (device.code === ibpData.tipBoxList[i].code) {
device.dispose ? ibpData.tipBoxList.splice(i, 1):ibpData.tipBoxList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.tipBoxList.push(device);
}
} else {
ibpData.tipBoxList = [device];
}
case deviceType.TipBox :
updateIbpListByDevice(ibpData, 'tipBoxList', device);
break;
}
case deviceType.CircularLamp : {
if (ibpData.circularLampList && ibpData.circularLampList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.circularLampList.length; i++) {
if (device.code === ibpData.circularLampList[i].code) {
device.dispose ? ibpData.circularLampList.splice(i, 1):ibpData.circularLampList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.circularLampList.push(device);
}
} else {
ibpData.circularLampList = [device];
}
case deviceType.CircularLamp :
updateIbpListByDevice(ibpData, 'circularLampList', device);
break;
}
case deviceType.IbpLine : {
if (ibpData.ibpLineList && ibpData.ibpLineList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.ibpLineList.length; i++) {
if (device.code === ibpData.ibpLineList[i].code) {
device.dispose ? ibpData.ibpLineList.splice(i, 1):ibpData.ibpLineList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.ibpLineList.push(device);
}
} else {
ibpData.ibpLineList = [device];
}
case deviceType.IbpLine :
updateIbpListByDevice(ibpData, 'ibpLineList', device);
break;
}
case deviceType.AppendageBox : {
if (ibpData.appendageBoxList && ibpData.appendageBoxList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.appendageBoxList.length; i++) {
if (device.code === ibpData.appendageBoxList[i].code) {
device.dispose ? ibpData.appendageBoxList.splice(i, 1):ibpData.appendageBoxList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.appendageBoxList.push(device);
}
} else {
ibpData.appendageBoxList = [device];
}
case deviceType.AppendageBox :
updateIbpListByDevice(ibpData, 'appendageBoxList', device);
break;
}
case deviceType.Alarm : {
if (ibpData.alarmList && ibpData.alarmList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.alarmList.length; i++) {
if (device.code === ibpData.alarmList[i].code) {
device.dispose ? ibpData.alarmList.splice(i, 1):ibpData.alarmList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.alarmList.push(device);
}
} else {
ibpData.alarmList = [device];
}
case deviceType.Alarm :
updateIbpListByDevice(ibpData, 'alarmList', device);
break;
}
case deviceType.Elevator : {
if (ibpData.elevatorList && ibpData.elevatorList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.elevatorList.length; i++) {
if (device.code === ibpData.elevatorList[i].code) {
device.dispose ? ibpData.elevatorList.splice(i, 1):ibpData.elevatorList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.elevatorList.push(device);
}
} else {
ibpData.elevatorList = [device];
}
case deviceType.Elevator :
updateIbpListByDevice(ibpData, 'elevatorList', device);
break;
}
case deviceType.Key : {
if (ibpData.keyList && ibpData.keyList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.keyList.length; i++) {
if (device.code === ibpData.keyList[i].code) {
device.dispose ? ibpData.keyList.splice(i, 1):ibpData.keyList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.keyList.push(device);
}
} else {
ibpData.keyList = [device];
}
case deviceType.Key :
updateIbpListByDevice(ibpData, 'keyList', device);
break;
}
case deviceType.TeleTerminal : {
if (ibpData.teleTerminalList && ibpData.teleTerminalList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.teleTerminalList.length; i++) {
if (device.code === ibpData.teleTerminalList[i].code) {
device.dispose ? ibpData.teleTerminalList.splice(i, 1):ibpData.teleTerminalList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.teleTerminalList.push(device);
}
} else {
ibpData.teleTerminalList = [device];
}
case deviceType.TeleTerminal :
updateIbpListByDevice(ibpData, 'teleTerminalList', device);
break;
case deviceType.Clock :
updateIbpListByDevice(ibpData, 'clockList', device);
break;
case deviceType.RotateTip:
updateIbpListByDevice(ibpData, 'rotateTipList', device);
break;
}
case deviceType.Clock : {
if (ibpData.clockList && ibpData.clockList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.clockList.length; i++) {
if (device.code === ibpData.clockList[i].code) {
device.dispose ? ibpData.clockList.splice(i, 1):ibpData.clockList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.clockList.push(device);
}
} else {
ibpData.clockList = [device];
}
}
case deviceType.RotateTip: {
if (ibpData.rotateTipList && ibpData.rotateTipList.length > 0) {
let newDevice = true;
for (let i=0; i<ibpData.rotateTipList.length; i++) {
if (device.code === ibpData.rotateTipList[i].code) {
device.dispose ? ibpData.rotateTipList.splice(i, 1): ibpData.rotateTipList[i] = device;
newDevice = false;
}
}
if (newDevice) {
ibpData.rotateTipList.push(device);
}
} else {
ibpData.rotateTipList = [device];
}
}
}
store.dispatch('ibp/setIbpData', ibpData);
}

View File

@ -4,107 +4,125 @@ const deviceRender = {};
/** link渲染配置*/
deviceRender[deviceType.Link] = {
_type: deviceType.Link,
zlevel: 1
// progressive: 1
};
/** Section渲染配置*/
deviceRender[deviceType.Section] = {
_type: deviceType.Section,
zlevel: 1
// progressive: 2
};
/** Signal渲染配置*/
deviceRender[deviceType.Signal] = {
_type: deviceType.Signal,
zlevel: 1
// progressive: 3
};
/** Switch渲染配置*/
deviceRender[deviceType.Switch] = {
_type: deviceType.Switch,
zlevel: 1
// progressive: 5
};
/** Station渲染配置*/
deviceRender[deviceType.Station] = {
_type: deviceType.Station,
zlevel: 1
// progressive: 4
};
/** StationStand渲染配置*/
deviceRender[deviceType.StationStand] = {
_type: deviceType.StationStand,
zlevel: 1
// progressive: 5
};
/** StationControl渲染配置*/
deviceRender[deviceType.StationControl] = {
_type: deviceType.StationControl,
zlevel: 1
// progressive: 4
};
/** ImageControl渲染配置*/
deviceRender[deviceType.ImageControl] = {
_type: deviceType.ImageControl,
zlevel: 1
// progressive: 5
};
/** ZcControl渲染配置*/
deviceRender[deviceType.ZcControl] = {
_type: deviceType.ZcControl,
zlevel: 1
// progressive: 6
};
/** LcControl渲染配置*/
deviceRender[deviceType.LcControl] = {
_type: deviceType.LcControl,
zlevel: 1
// progressive: 6
};
/** LimitControl渲染配置*/
deviceRender[deviceType.LimitControl] = {
_type: deviceType.LimitControl,
zlevel: 1
// progressive: 5
};
/** StationDelayUnlock渲染配置*/
deviceRender[deviceType.StationDelayUnlock] = {
_type: deviceType.StationDelayUnlock,
zlevel: 1
// progressive: 6
};
/** Train渲染配置*/
deviceRender[deviceType.Train] = {
_type: deviceType.Train,
zlevel: 1
// progressive: 9
};
/** TrainWindow渲染配置*/
deviceRender[deviceType.TrainWindow] = {
_type: deviceType.TrainWindow,
zlevel: 1
// progressive: 8
};
/** Line渲染配置*/
deviceRender[deviceType.Line] = {
_type: deviceType.Line,
zlevel: 1
// progressive: 7
};
/** Text渲染配置*/
deviceRender[deviceType.Text] = {
_type: deviceType.Text,
zlevel: 1
// progressive: 7
};
/** TrainWindow渲染配置*/
deviceRender[deviceType.TrainWindow] = {
_type: deviceType.TrainWindow,
zlevel: 1
// progressive: 4
};
/** Train渲染配置*/
deviceRender[deviceType.TRain] = {
_type: deviceType.TRain,
zlevel: 1
// progressive: 4
};

View File

@ -30,7 +30,7 @@ export function calculateDCenter(viewRect, zrbound) {
}
export function deviceFactory(type, elem) {
return Object.assign({ _type: type }, deviceRender[type], elem);
return {...deviceRender[type], ...elem};
}
export function createDevice(type, model, propConvert) {

View File

@ -2,7 +2,7 @@
<div>
<div class="display-draft">
<el-button-group>
<el-button v-if="isIBP" type="warning" @click="jumpIbp">IBP盘</el-button>
<el-button v-if="isAdmin || isIBP" type="warning" @click="jumpIbp">IBP盘</el-button>
<el-button v-if="isDriver" type="jumpjlmap3d" @click="jumpjlmap3d">司机视角</el-button>
<template v-if="isAdmin">
<el-button type="success" :disabled="isDisable" @click="selectBeginTime">按计划行车</el-button>