rt-sim-training-client/src/store/modules/map.js

551 lines
13 KiB
JavaScript
Raw Normal View History

2019-07-25 10:32:29 +08:00
import deviceType from '@/jmap/constant/deviceType';
import { parser } from '@/jmap/utils/parser';
2019-07-25 10:32:29 +08:00
import Vue from 'vue';
/**
* 查询向上受影响的Devices
* @param {Object} map
* @param {Object} device
* @param {Array} effectedDeviceList
*/
2019-07-29 17:57:00 +08:00
function queryEffectedModels(map, device, effectedDeviceList) {
2019-07-25 10:32:29 +08:00
if (device && map) {
effectedDeviceList.push(device);
switch (device._type) {
// 查询ink关联项
case deviceType.Link:
// 查询Link关联的区段
if (map.sectionList && map.sectionList.length) {
map.sectionList.forEach(elem => {
if (elem.linkCode === device.code) {
2019-07-29 17:57:00 +08:00
queryEffectedModels(map, elem, effectedDeviceList);
2019-07-25 10:32:29 +08:00
}
});
}
// 查询Link关联的信号机
if (map.signalList && map.signalList.length) {
map.signalList.forEach(elem => {
if (elem.linkCode === device.code) {
effectedDeviceList.push(elem);
}
});
}
break;
// 移除区段关联项
case deviceType.Section:
// 查询物理区段关联的逻辑区段
if (map.sectionList && map.sectionList.length && device.type === '01') {
map.sectionList.forEach(elem => {
if (elem.type !== '01' && elem.parentCode === device.code) {
effectedDeviceList.push(elem);
}
});
}
// 查询区段关联车次窗
if (map.trainWindowList && map.trainWindowList.length) {
map.trainModelList.forEach(elem => {
if (elem.sectionCode == device.code) {
effectedDeviceList.push(elem);
}
});
}
// 查询区段关联的道岔
if (map.switchList && map.switchList.length) {
map.switchList.forEach(elem => {
if (elem.sectionACode === device.code ||
elem.sectionBCode === device.code ||
elem.sectionCCode === device.code) {
effectedDeviceList.push(elem);
}
});
}
// 查询区段关联的车站
if (map.stationList && map.stationList.length) {
map.stationList.forEach(elem => {
if (elem.sectionCode === device.code) {
effectedDeviceList.push(elem);
}
});
}
break;
}
}
}
2019-08-06 17:00:24 +08:00
function saveMapDeviceDefaultRelations(state) {
2019-07-25 10:32:29 +08:00
if (state && state.map) {
const map = state.map;
2019-07-29 15:23:55 +08:00
const deviceMap = Vue.prototype.$jlmap.mapDevice;
2019-07-25 10:32:29 +08:00
// 是否集中站
if (map.stationControlList && map.stationControlList.length) {
map.stationControlList.forEach(elem => {
2019-07-30 13:29:54 +08:00
const station = deviceMap[elem.stationCode];
2019-07-25 10:32:29 +08:00
if (station) {
station.centralized = true;
}
});
}
// 设置区段关联
if (map.sectionList && map.sectionList.length) {
map.sectionList.forEach(elem => {
if (elem.type !== '03') {
const station = deviceMap[elem.parentCode];
if (station) {
elem.stationCode = station.stationCode;
}
} else {
elem.parentCode = '';
}
if (elem.type === '01') {
elem.nameShow == true;
}
});
}
// 站台轨设置
if (map.stationStandList && map.stationStandList.length && map.sectionList && map.sectionList.length) {
map.stationStandList.forEach((stand) => {
2019-07-30 13:29:54 +08:00
const stopPoint = deviceMap[stand.stopPointCode];
2019-07-25 10:32:29 +08:00
if (stopPoint) {
map.sectionList.forEach(section => {
if (section.type === '01' &&
stopPoint.linkCode === section.linkCode &&
stopPoint.offset >= section.offsetLeft &&
stopPoint.offset <= section.offsetRight) {
section.isStandTrack = true;
if (!section.standTrackName) {
section.standTrackName = section.name.replace(section.name.slice(0, 2), 'ZT');
}
if (!section.standTrackNamePosition) {
section.standTrackNamePosition = { x: 0, y: 0 };
}
}
});
}
});
}
// 折返轨设置
if (map.stopPointList && map.stopPointList.length && map.sectionList && map.sectionList.length) {
map.stopPointList.forEach(stopPoint => {
if (stopPoint.isTurningPoint) {
map.sectionList.forEach(section => {
if (section.type === '01' &&
stopPoint.linkCode === section.linkCode &&
stopPoint.offset >= section.offsetLeft &&
stopPoint.offset <= section.offsetRight) {
section.isReentryTrack = true;
if (!section.reentryTrackName) {
section.reentryTrackName = section.name.replace(section.name.slice(0, 2), 'ZF');
}
if (!section.reentryTrackNamePosition) {
section.reentryTrackNamePosition = { x: 0, y: 0 };
}
}
});
}
});
}
// 设置道岔区段
if (map.switchList && map.switchList.length && map.sectionList && map.sectionList.length) {
map.switchList.forEach(elem => {
2019-07-30 13:29:54 +08:00
const sectiona = deviceMap[elem.sectionACode];
2019-07-25 10:32:29 +08:00
if (sectiona && sectiona.type !== '03') {
sectiona.nameShow = false;
sectiona.isSwitchSection = true;
sectiona.relSwitchCode = elem.code;
}
2019-07-30 13:29:54 +08:00
const sectionb = deviceMap[elem.sectionBCode];
2019-07-25 10:32:29 +08:00
if (sectionb && sectiona.type !== '03') {
sectionb.nameShow = false;
sectionb.isSwitchSection = true;
sectionb.relSwitchCode = elem.code;
}
2019-07-30 13:29:54 +08:00
const sectionc = deviceMap[elem.sectionCCode];
2019-07-25 10:32:29 +08:00
if (sectionc && sectiona.type !== '03') {
sectionc.nameShow = false;
sectionc.isSwitchSection = true;
sectionc.relSwitchCode = elem.code;
}
2019-08-06 17:00:24 +08:00
const sectionp = deviceMap[sectiona.parentCode || sectionb.parentCode || sectionc.parentCode];
if (sectionp) {
sectionp.relSwitchCode = elem.code;
}
2019-07-25 10:32:29 +08:00
});
}
}
}
/**
* 实训状态数据
*/
const map = {
namespaced: true,
state: {
2019-07-31 09:13:37 +08:00
map: null, // 地图数据
mapDevice: {}, // 解析后的地图数据
2019-07-25 10:32:29 +08:00
mapList: {}, // 地图数据列表
mapViewLoadedCount: 0, // 地图视图加载完成标识
mapDataLoadedCount: 0, // 地图数据加载完成标识
2019-08-07 10:24:13 +08:00
trainDetails: null // 地图'列车详情'显示
2019-07-25 10:32:29 +08:00
},
getters: {
mapList: (state) => {
return state.mapList;
},
map: (state) => {
return state.map;
},
skinStyle: (state) => {
2019-07-26 10:38:57 +08:00
if (state.map && state.map.skinVO) {
return state.map.skinVO.code;
2019-07-25 10:32:29 +08:00
}
},
name: (state) => {
if (state.map) {
return state.map.name;
} else {
return null;
}
},
version: (state) => {
if (state.map) {
return state.map.version;
} else {
return null;
}
},
linkList: (state) => {
if (state.map) {
return state.map.linkList;
} else {
return [];
}
},
switchList: (state) => {
if (state.map) {
return state.map.switchList;
} else {
return [];
}
},
signalList: (state) => {
if (state.map) {
return state.map.signalList;
} else {
return [];
}
},
sectionList: (state) => {
if (state.map) {
return state.map.sectionList;
} else {
return [];
}
},
zcList: (state) => {
if (state.map) {
return state.map.zcList;
} else {
return [];
}
},
tempSpeedLimitList: (state) => {
if (state.map) {
return state.map.tempSpeedLimitList;
} else {
return [];
}
},
lcList: (state) => {
if (state.map) {
return state.map.lcList;
} else {
return [];
}
},
resourceList: (state) => {
if (state.map) {
return state.map.resourceList;
} else {
return [];
}
},
stationList: (state) => {
if (state.map) {
return state.map.stationList;
} else {
return [];
}
},
stationStandList: (state) => {
if (state.map) {
return state.map.stationStandList;
} else {
return [];
}
},
stationControlList: (state) => {
if (state.map) {
return state.map.stationControlList;
} else {
return [];
}
},
counterList: (state) => {
if (state.map) {
return state.map.counterList;
} else {
return [];
}
},
delayShowList: (state) => {
if (state.map) {
return state.map.delayShowList;
} else {
return [];
}
},
lineList: (state) => {
if (state.map) {
return state.map.lineList;
} else {
return [];
}
},
textList: (state) => {
if (state.map) {
return state.map.textList;
} else {
return [];
}
},
trainWindowList: (state) => {
if (state.map) {
return state.map.trainWindowList;
} else {
return [];
}
},
trainList: (state) => {
if (state.map) {
return state.map.trainList;
} else {
return [];
}
},
trainModelList: (state) => {
if (state.map) {
return state.map.trainModelList;
} else {
return [];
}
},
2019-07-26 10:38:57 +08:00
trainDetails: (state) => {
return state.trainDetails;
},
getDeviceByCode: (state) => (code) => {
return state.mapDevice[code];
2019-07-25 10:32:29 +08:00
},
// 查询区段关联的计数器
getCounterBySectionCode: (state) => (code, type) => {
2019-07-29 17:57:00 +08:00
let device = null;
var section = state.mapDevice[code];
if (section) {
state.map.counterList.forEach(counter => {
if (counter.stationCode === section.model.stationCode && type == counter.type) {
device = state.mapDevice[counter.code];
return;
}
});
2019-07-25 10:32:29 +08:00
}
2019-07-29 17:57:00 +08:00
return device;
2019-07-25 10:32:29 +08:00
},
// 查询信号机关联的计数器
getCounterBySingalCode: (state) => (code, type) => {
2019-07-29 17:57:00 +08:00
let device = null;
var signal = state.mapDevice[code];
if (signal) {
state.map.counterList.forEach(counter => {
if (counter.stationCode === signal.model.stationCode && type == counter.type) {
device = state.mapDevice[counter.code];
return;
}
});
2019-07-25 10:32:29 +08:00
}
2019-07-29 17:57:00 +08:00
return device;
2019-07-25 10:32:29 +08:00
},
// 查询所属车站关联的控制模式
getStationControlByStationCode: (state) => (code) => {
let device = null;
if (code &&
2019-07-29 17:57:00 +08:00
state.map &&
2019-07-25 10:32:29 +08:00
state.map.stationControlList && state.map.stationControlList.length) {
state.map.stationControlList.forEach(elem => {
if (elem.stationCode == code) {
device = state.mapDevice[elem.code];
2019-07-25 10:32:29 +08:00
}
});
}
2019-07-29 17:57:00 +08:00
2019-07-25 10:32:29 +08:00
return device;
}
},
mutations: {
2019-07-25 14:03:26 +08:00
setMapData: (state, map) => {
if (map && map.skinVO) {
state.map = map;
state.mapDevice = parser(map, map.skinVO.code);
} else {
state.mapDevice = {};
}
2019-07-25 10:32:29 +08:00
},
2019-07-30 16:47:11 +08:00
mapRender: (state, devices) => {
2019-07-25 15:44:23 +08:00
Vue.prototype.$jlmap && Vue.prototype.$jlmap.render(devices);
2019-07-25 10:32:29 +08:00
},
setTrainDetails: (state, details) => {
state.trainDetails = details;
},
mapViewLoadedCountIncrement: (state) => {
state.mapViewLoadedCount += 1;
},
mapDataLoadedCountIncrement: (state) => {
state.mapDataLoadedCount += 1;
},
operateTrainModel: (state, { model, type }) => {
if (state.map && model) {
const list = state.map.trainModelList || [];
if (type === 'ADD') {
const index = list.indexOf(list.find(elem => { return elem.code === model.code; }));
if (index < 0) {
list.push(Object.assign({}, model));
}
} else if (type === 'UPT') {
const index = list.indexOf(list.find(elem => { return elem.code === model.code; }));
if (index >= 0) {
for (var prop in model) {
list[index][prop] = model[prop];
}
}
} else if (type === 'DEL') {
const index = list.indexOf(list.find(elem => { return elem.code === model.code; }));
if (index >= 0) {
list.splice(index, 1);
}
}
}
},
mapClear: (state) => {
2019-07-31 09:13:37 +08:00
state.map = null;
state.mapDevice = {};
2019-07-25 15:44:23 +08:00
Vue.prototype.$jlmap && Vue.prototype.$jlmap.clear();
2019-07-25 10:32:29 +08:00
}
},
actions: {
mapClear: ({ commit }) => {
commit('mapClear');
},
2019-07-25 14:03:26 +08:00
setMapData: ({ commit }, map) => {
commit('setMapData', map);
2019-07-25 10:32:29 +08:00
},
setTrainDetails: ({ commit }, message) => {
commit('setTrainDetails', message);
},
setMapDataList: ({ state }, map) => {
const skinVO = map.skinVO;
if (skinVO && skinVO.code) {
state.mapList[`mapDate_${skinVO.code}`] = map;
}
},
2019-07-29 17:57:00 +08:00
updateMapDevices: ({ commit }, models) => {
2019-07-25 10:32:29 +08:00
return new Promise((resolve) => {
2019-07-29 17:57:00 +08:00
if (!(models instanceof Array)) {
models = [models];
2019-07-25 10:32:29 +08:00
}
2019-07-29 17:57:00 +08:00
commit('mapRender', models);
resolve(models);
2019-07-25 10:32:29 +08:00
});
},
2019-07-29 17:57:00 +08:00
deleteMapDevices: ({ commit, state }, models) => {
2019-07-25 10:32:29 +08:00
return new Promise((resolve) => {
2019-07-29 17:57:00 +08:00
if (!(models instanceof Array)) {
models = [models];
2019-07-25 10:32:29 +08:00
}
// 查找向上关联需要一起删除的设备
2019-07-29 17:57:00 +08:00
const effectedModelList = [];
models.forEach((device) => {
queryEffectedModels(state.map, device, effectedModelList);
2019-07-25 10:32:29 +08:00
});
effectedModelList.forEach(elem => { elem['_dispose'] = true; });
2019-07-29 17:57:00 +08:00
commit('mapRender', effectedModelList);
resolve(effectedModelList);
2019-07-25 10:32:29 +08:00
});
},
2019-08-06 17:00:24 +08:00
saveMapDeviceDefaultRelations({ state }) {
saveMapDeviceDefaultRelations(state);
2019-07-25 10:32:29 +08:00
},
mapViewLoaded: ({ commit }) => {
commit('mapViewLoadedCountIncrement');
},
mapDataLoaded: ({ commit }) => {
commit('mapDataLoadedCountIncrement');
},
2019-07-29 15:23:55 +08:00
clearJlmapTrainView: () => {
2019-07-26 17:13:03 +08:00
if (Vue.prototype.$jlmap) {
Vue.prototype.$jlmap.clearTrainView();
}
2019-07-25 10:32:29 +08:00
},
2019-07-30 16:47:11 +08:00
setTrainWindowShow: ({commit, state}, show) => {
if (state.map) {
var deviceList = [];
var trainWindowList = state.map.trainWindowList;
if (trainWindowList && trainWindowList.length) {
trainWindowList.forEach(elem => {
elem._type = deviceType.TrainWindow;
elem.trainWindowShow = show;
deviceList.push(elem);
});
}
commit('mapRender', deviceList);
}
2019-07-26 17:39:05 +08:00
},
2019-07-25 10:32:29 +08:00
operateTrainModel: ({ commit }, { model, type }) => {
commit('operateTrainModel', { model, type });
}
}
};
export default map;