rt-sim-training-client/src/utils/loaddata.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-07-26 13:32:43 +08:00
import store from '@/store';
2019-08-29 17:16:33 +08:00
import { getPublishMapVersion, getPublishMapDetail, getPublishMapVersionById, getPublishMapDetailById} from '@/api/jmap/map';
2019-07-26 13:32:43 +08:00
// 获取地图版本数据和store里面的map版本做比较如果不同
// 获取发布的地图数据
// 先设置地图数据
// 清除列车数据
2019-08-29 17:16:33 +08:00
export function loadMapData(skinCode) {
2019-07-26 15:52:50 +08:00
return new Promise((resolve, reject) => {
2019-08-29 17:16:33 +08:00
getPublishMapVersion(skinCode).then(resp => {
2019-07-26 15:52:50 +08:00
var version = resp.data;
2019-08-29 17:16:33 +08:00
var mapData = store.state.map.mapList[`mapDate_${skinCode}`];
2019-07-26 15:52:50 +08:00
if (mapData && mapData.version == version) {
store.dispatch('map/setMapData', mapData).then(() => {
store.dispatch('map/clearJlmapTrainView').then(() => {
resolve();
});
});
} else {
2019-08-29 17:16:33 +08:00
getPublishMapDetail(skinCode).then(res => {
2019-07-26 15:52:50 +08:00
mapData = res.data;
store.dispatch('map/setMapDataList', mapData);
store.dispatch('map/setMapData', mapData).then(() => {
store.dispatch('map/clearJlmapTrainView').then(() => {
resolve();
});
});
}).catch(error => {
reject(error);
});
}
}).catch(error => {
reject(error);
});
});
2019-07-26 13:32:43 +08:00
}
2019-08-29 17:16:33 +08:00
export function loadMapDataById(mapId) {
return new Promise((resolve, reject) => {
getPublishMapVersionById(mapId).then(resp => {
var version = resp.data;
var mapData = store.state.map.mapIdList[`mapDate_${mapId}`];
if (mapData && mapData.version == version) {
store.dispatch('map/setMapData', mapData).then(() => {
store.dispatch('map/clearJlmapTrainView').then(() => {
resolve();
});
});
} else {
getPublishMapDetailById(mapId).then(res => {
mapData = res.data;
store.dispatch('map/setMapDataIdList', {mapData, mapId});
store.dispatch('map/setMapData', mapData).then(() => {
store.dispatch('map/clearJlmapTrainView').then(() => {
resolve();
});
});
}).catch(error => {
reject(error);
});
}
}).catch(error => {
reject(error);
});
});
}