import deviceType from '@/jmap/constant/deviceType'; import Vue from 'vue'; /** * 查询向上受影响的Devices * @param {Object} map * @param {Object} device * @param {Array} effectedDeviceList */ function queryEffectedModels(map, device, effectedDeviceList) { 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) { queryEffectedModels(map, elem, effectedDeviceList); } }); } // 查询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; } } } function saveMapDeviceDefaultConvert(state) { if (state && state.map) { const map = state.map; const deviceMap = Vue.prototype.$jlmap.mapDevice; // 是否集中站 if (map.stationControlList && map.stationControlList.length) { map.stationControlList.forEach(elem => { const station = deviceMap[elem.stationCode] ? deviceMap[elem.stationCode].model : null; 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) => { const stopPoint = deviceMap[stand.stopPointCode] ? deviceMap[stand.stopPointCode].model : null; 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 => { const sectiona = deviceMap[elem.sectionACode] ? deviceMap[elem.sectionACode].model : null; if (sectiona && sectiona.type !== '03') { sectiona.nameShow = false; sectiona.isSwitchSection = true; sectiona.relSwitchCode = elem.code; } const sectionb = deviceMap[elem.sectionBCode] ? deviceMap[elem.sectionBCode].model : null; if (sectionb && sectiona.type !== '03') { sectionb.nameShow = false; sectionb.isSwitchSection = true; sectionb.relSwitchCode = elem.code; } const sectionc = deviceMap[elem.sectionCCode] ? deviceMap[elem.sectionCCode].model : null; if (sectionc && sectiona.type !== '03') { sectionc.nameShow = false; sectionc.isSwitchSection = true; sectionc.relSwitchCode = elem.code; } }); } } } /** * 实训状态数据 */ const map = { namespaced: true, state: { map: {}, // 地图数据 mapList: {}, // 地图数据列表 mapViewLoadedCount: 0, // 地图视图加载完成标识 mapDataLoadedCount: 0, // 地图数据加载完成标识 trainDetails: null // 列车详情显示 }, getters: { mapList: (state) => { return state.mapList; }, map: (state) => { return state.map; }, skinStyle: (state) => { if (state.map && state.map.skinVO) { return state.map.skinVO.code; } }, 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 []; } }, viewTrainList: (state) => { // const trainList = []; // const trainLevel = Vue.prototype.$jlmap.getTrainView(); // if (trainLevel) { // trainLevel.eachChild((viewGroup) => { // viewGroup.eachChild((train) => { // if (train && train._type === deviceType.Train) { // trainList.push(train.model); // } // }, this); // }, this); // } // return trainList; }, trainDetails: (state) => { return state.trainDetails; }, getDeviceByCode: () => (code) => { if (Vue.prototype.$jlmap) { return Vue.prototype.$jlmap.getDeviceByCode(code); } }, // 查询区段关联的计数器 getCounterBySectionCode: (state) => (code, type) => { let device = null; if (Vue.prototype.$jlmap) { var section = Vue.prototype.$jlmap.mapDevice[code]; if (section) { state.map.counterList.forEach(counter => { if (counter.stationCode === section.model.stationCode && type == counter.type) { device = Vue.prototype.$jlmap.mapDevice[counter.code]; return; } }); } } return device; }, // 查询信号机关联的计数器 getCounterBySingalCode: (state) => (code, type) => { let device = null; if (Vue.prototype.$jlmap) { var signal = Vue.prototype.$jlmap.mapDevice[code]; if (signal) { state.map.counterList.forEach(counter => { if (counter.stationCode === signal.model.stationCode && type == counter.type) { device = Vue.prototype.$jlmap.mapDevice[counter.code]; return; } }); } } return device; }, // 查询所属车站关联的控制模式 getStationControlByStationCode: (state) => (code) => { let device = null; if (Vue.prototype.$jlmap && code && state.map && state.map.stationControlList && state.map.stationControlList.length) { state.map.stationControlList.forEach(elem => { if (elem.stationCode == code) { device = Vue.prototype.$jlmap.mapDevice[elem.code]; } }); } return device; } }, mutations: { setMapData: (state, map) => { state.map = map; }, mapRender: (devices) => { Vue.prototype.$jlmap && Vue.prototype.$jlmap.render(devices); }, 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) => { state.map = {}; Vue.prototype.$jlmap && Vue.prototype.$jlmap.clear(); } }, actions: { mapClear: ({ commit }) => { commit('mapClear'); }, setMapData: ({ commit }, map) => { commit('setMapData', map); }, setTrainDetails: ({ commit }, message) => { commit('setTrainDetails', message); }, setMapDataList: ({ state }, map) => { const skinVO = map.skinVO; if (skinVO && skinVO.code) { state.mapList[`mapDate_${skinVO.code}`] = map; } }, updateMapDevices: ({ commit }, models) => { return new Promise((resolve) => { if (!(models instanceof Array)) { models = [models]; } commit('mapRender', models); resolve(models); }); }, deleteMapDevices: ({ commit, state }, models) => { return new Promise((resolve) => { if (!(models instanceof Array)) { models = [models]; } // 查找向上关联需要一起删除的设备 const effectedModelList = []; models.forEach((device) => { queryEffectedModels(state.map, device, effectedModelList); }); commit('mapRender', effectedModelList); resolve(effectedModelList); }); }, saveMapDeviceDefaultConvert({ state }) { saveMapDeviceDefaultConvert(state); }, mapViewLoaded: ({ commit }) => { commit('mapViewLoadedCountIncrement'); }, mapDataLoaded: ({ commit }) => { commit('mapDataLoadedCountIncrement'); }, clearJlmapTrainView: () => { if (Vue.prototype.$jlmap) { Vue.prototype.$jlmap.clearTrainView(); } }, setTrainWindowShow: ({state}) => { console.log('设置车次窗隐藏'); }, operateTrainModel: ({ commit }, { model, type }) => { commit('operateTrainModel', { model, type }); } } }; export default map;