104 lines
4.0 KiB
JavaScript
104 lines
4.0 KiB
JavaScript
import store from '@/store/index_APP_TARGET';
|
||
import { getPublishMapVersionById, getPublishMapDetailById} from '@/api/jmap/map';
|
||
// getNewMapDataByMapId
|
||
// import { getNewMapDataByGroup } from '@/api/simulation';
|
||
|
||
// 获取地图版本数据,和store里面的map版本做比较,如果不同
|
||
// 获取发布的地图数据
|
||
// 先设置地图数据
|
||
// 清除列车数据
|
||
export function loadMapDataById(mapId, type = 'mapPreview') {
|
||
return new Promise((resolve, reject) => {
|
||
getPublishMapVersionById(mapId).then(resp => {
|
||
var version = resp.data;
|
||
var mapData = store.state.map.mapIdList[`mapData_${mapId}`];
|
||
if (mapData && mapData.version == version) {
|
||
if (type == 'mapPreview') {
|
||
store.dispatch('map/setMapData', mapData.graphDataNew).then(() => {
|
||
store.dispatch('map/clearJlmapTrainView').then(() => {
|
||
resolve();
|
||
});
|
||
});
|
||
} else {
|
||
covertData(mapData, 'Group', resolve);
|
||
}
|
||
} else {
|
||
getPublishMapDetailById(mapId).then(res => {
|
||
mapData = res.data;
|
||
mapData.version = version;
|
||
mapData.mapId = mapId;
|
||
store.dispatch('map/setMapDataIdList', {mapData:mapData});
|
||
if (type == 'mapPreview') {
|
||
store.dispatch('map/setMapData', mapData.graphDataNew).then(() => {
|
||
store.dispatch('map/clearJlmapTrainView').then(() => {
|
||
resolve();
|
||
});
|
||
});
|
||
} else {
|
||
covertData(res.data, 'Group', resolve);
|
||
}
|
||
}).catch(error => {
|
||
reject(error);
|
||
});
|
||
}
|
||
}).catch(error => {
|
||
reject(error);
|
||
});
|
||
});
|
||
}
|
||
|
||
export function loadNewMapDataByMapId(mapId) {
|
||
return new Promise((resolve, reject) => {
|
||
getPublishMapDetailById(mapId).then(resp => {
|
||
covertData(resp.data, 'mapId', resolve);
|
||
}).catch(error => {
|
||
reject(error);
|
||
});
|
||
});
|
||
}
|
||
|
||
// export function loadNewMapDataByGroup(group) {
|
||
// return new Promise((resolve, reject) => {
|
||
// getNewMapDataByGroup(group).then(resp => {
|
||
// covertData(resp, 'Group', resolve);
|
||
// }).catch(error => {
|
||
// reject(error);
|
||
// });
|
||
// });
|
||
// }
|
||
|
||
export function covertData(resp, type, resolve) {
|
||
resp.graphDataNew && resp.graphDataNew.trainList && resp.graphDataNew.trainList.forEach(item => {
|
||
item.code = item.groupNumber;
|
||
});
|
||
const mapData = resp.graphDataNew;
|
||
mapData.signalApproachSectionList = resp.logicDataNew.signalApproachSectionList;
|
||
if (type == 'Group') {
|
||
store.dispatch('map/setMapData', mapData).then(() => {
|
||
store.dispatch('map/clearJlmapTrainView').then(() => {
|
||
resolve();
|
||
});
|
||
});
|
||
} else if (type == 'mapId') {
|
||
store.dispatch('map/setMapData', mapData).then(() => {
|
||
resolve();
|
||
});
|
||
}
|
||
|
||
const routeData = resp.logicDataNew.routeList; // 设置进路数据
|
||
const overlapData = resp.logicDataNew.overlapList;
|
||
const autoReentryData = resp.logicDataNew.autoReentryList; // 自动折返数据
|
||
const signalApproachSectionData = resp.logicDataNew.signalApproachSectionList; // 信号机接近区段数据
|
||
overlapData.forEach(item => {
|
||
item._type = 'OverAp';
|
||
});
|
||
store.commit('map/setRouteData', routeData);
|
||
store.dispatch('map/setOverlapData', overlapData);
|
||
store.dispatch('map/setAutoReentryData', autoReentryData);
|
||
store.dispatch('map/setSignalApproachSectionData', signalApproachSectionData);
|
||
const mapConfig = resp.configVO;
|
||
store.commit('map/setMapConfig', mapConfig);
|
||
store.dispatch('map/setMapVersion', resp.version);
|
||
}
|
||
|