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

141 lines
4.9 KiB
JavaScript
Raw Normal View History

2019-07-26 13:32:43 +08:00
const runPlan = {
namespaced: true,
state: {
stations: [], //车站列表
planData: {}, //运行图原始数据
editData: {}, //运行图编辑数据
updateData: {}, //运行图更新数据
planSizeCount: 0, //运行图canvas 大小变更标识
planLoadedCount: 0, //运行图数据更新
planUpdateCount: 0, //运行图更新标识
select: {}, //选择的对象
width: 800, //运行图canvas 容器 宽度
height: 600, //运行图canvas 容器 高度
},
getters: {
stations: (state) => {
return state.stations || [];
},
convertPlanData: (state) => () => {
let data = { serviceNumberDataList: [] };
let serviceNumberList = Object.keys(state.editData).sort((a, b) => {
return state.editData[a].oldIndex - state.editData[b].oldIndex;
});
serviceNumberList.forEach(serviceNumber => {
let serviceObj = {
serviceNumber: serviceNumber,
tripNumberDataList: []
};
if (state.editData[serviceNumber].backup) {
serviceObj['backup'] = state.editData[serviceNumber].backup;
}
let trainMap = state.editData[serviceNumber].trainMap;
let tripNumberList = Object.keys(trainMap).sort((a, b) => {
return trainMap[a].oldIndex - trainMap[b].oldIndex;
});
tripNumberList.forEach(tripNumber => {
serviceObj.tripNumberDataList.push(trainMap[tripNumber]);
});
data.serviceNumberDataList.push(serviceObj);
});
return data;
},
},
mutations: {
setWidth: (state, width) => {
state.width = width;
state.planSizeCount += 1;
},
setHeight: (state, height) => {
state.height = height;
state.planSizeCount += 1;
},
setStations: (state, stations) => {
state.stations = stations;
},
setPlanData: (state, data) => {
state.planData = data;
state.editData = {};
if (data && data.serviceNumberDataList && data.serviceNumberDataList.length) {
let serviceList = data.serviceNumberDataList;
serviceList.forEach((service, i) => {
let trainList = service.tripNumberDataList;
state.editData[service.serviceNumber] = { oldIndex: i, serviceNumber: service.serviceNumber, backup: service.backup, trainMap: {} };
trainList.forEach((train, j) => {
state.editData[service.serviceNumber].trainMap[`${train.directionCode}${train.tripNumber}`] = { oldIndex: j, tripNumber: train.tripNumber, directionCode: train.directionCode, reentry: train.reentry, stationTimeList: train.stationTimeList };
});
});
}
state.planLoadedCount++;
},
setSelected: (state, select) => {
state.select = select;
},
addserviceNumber: (state, serviceNumber) => {
let serviceObj = state.planData[serviceNumber];
if (serviceObj) {
let oldIndex = serviceObj.oldIndex;
state.planData[serviceNumber] = { oldIndex, serviceNumber, trainMap: {} };
state.planLoadedCount++;
}
},
updateRunPlanData: (state, data) => {
state.updateData = data;
state.planUpdateCount++;
},
clear: (state) => {
state.stations = [];
state.planData = {};
state.editData = {};
state.select = {};
}
},
actions: {
/** 设置运行图大小*/
resize({ commit }, opt) {
if (opt.width) {
commit('setWidth', opt.width);
}
if (opt.height) {
commit('setHeight', opt.height);
}
},
/** 设置stations数据 */
setStations: ({ commit }, mapModel) => {
commit('setStations', mapModel);
},
/** 设置运行图数据 */
setPlanData: ({ commit }, data) => {
commit('setPlanData', data);
},
/** 增加服务号*/
addserviceNumber: ({ commit }, serviceNumber) => {
commit('addserviceNumber', serviceNumber);
},
/** 选择车次*/
setSelected: ({ commit }, select) => {
commit('setSelected', select);
},
/** 更新数据*/
updateRunPlanData: ({ commit }, data) => {
commit('updateRunPlanData', data);
},
/** 清空数据*/
clear: ({ commit }) => {
commit('clear');
}
}
};
export default runPlan;