2020-03-23 14:27:57 +08:00
|
|
|
|
import { createMartPoint, createSeriesModel, createMarkLineModels, hexColor, convertSheetToList, prefixTime } from '@/utils/runPlan';
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
/** 边缘高度*/
|
|
|
|
|
EdgeHeight: 600,
|
|
|
|
|
|
|
|
|
|
/** 间隔高度*/
|
|
|
|
|
CoordMultiple: 1,
|
|
|
|
|
|
|
|
|
|
/** 偏移时间*/
|
|
|
|
|
TranslationTime: 60 * 60 * 2,
|
|
|
|
|
|
|
|
|
|
/** excel解析配置*/
|
|
|
|
|
ExcelConfig: {
|
|
|
|
|
beginRow: 1,
|
|
|
|
|
beginCol: 0,
|
|
|
|
|
fieldNum: 10,
|
|
|
|
|
sepField: '行车间隔',
|
2020-04-03 17:40:18 +08:00
|
|
|
|
trainId: 'TRAINID',
|
2020-03-23 14:27:57 +08:00
|
|
|
|
columns: ['折返线', 'TrainID', '行车间隔']
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 解析exal数据转换为Json后台数据*/
|
|
|
|
|
importData(Sheet, JsonData) {
|
|
|
|
|
var dataList = convertSheetToList(Sheet, true);
|
|
|
|
|
if (dataList && dataList.length) {
|
|
|
|
|
if (dataList && dataList.length && dataList[1] && dataList[0]) {
|
|
|
|
|
/** 解析二维数组为json对象*/
|
|
|
|
|
const reg3 = /^(\d+:\d+:\d+|)/; // 06:12:00
|
2020-04-03 17:40:18 +08:00
|
|
|
|
const reg = /^[0-9]{5}/;
|
|
|
|
|
const positionList = []; // trainId所在行
|
|
|
|
|
let columnNum; // trainId所在列
|
2020-03-23 14:27:57 +08:00
|
|
|
|
dataList.forEach((elem, i) => {
|
2020-04-03 17:40:18 +08:00
|
|
|
|
if (elem.includes(this.ExcelConfig.trainId)) {
|
|
|
|
|
columnNum = i;
|
2020-03-23 14:27:57 +08:00
|
|
|
|
elem.forEach((item, j) => {
|
2020-04-03 17:40:18 +08:00
|
|
|
|
if (item === this.ExcelConfig.trainId) {
|
|
|
|
|
positionList.push(j);
|
2020-03-23 14:27:57 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-04-03 17:40:18 +08:00
|
|
|
|
for (let i = 0; i < dataList.length; i++) {
|
|
|
|
|
positionList.forEach((item, index)=> {
|
|
|
|
|
if ((index + 1) % 2 !== 0 ) {
|
|
|
|
|
const trainIdDown = dataList[i][item];
|
|
|
|
|
const trainIdUp = dataList[i][positionList[index + 1]];
|
|
|
|
|
if (reg.test(trainIdDown)) {
|
|
|
|
|
const arrivalList = [];
|
|
|
|
|
for (let j = 1; item + j < positionList[index + 1]; j = j + 2) {
|
|
|
|
|
arrivalList.push({
|
|
|
|
|
stationName: dataList[columnNum][item + j],
|
|
|
|
|
arriveTime: reg3.test(dataList[i][item + j]) ? dataList[i][item + j] : '',
|
|
|
|
|
departureTime: reg3.test(dataList[i][item + j + 1]) ? dataList[i][item + j + 1] : ''
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
JsonData.push({
|
|
|
|
|
code: trainIdDown,
|
|
|
|
|
destinationCode: '1',
|
|
|
|
|
arrivalList: arrivalList
|
|
|
|
|
});
|
|
|
|
|
} else if (reg.test(trainIdUp)) {
|
|
|
|
|
const arrivalList = [];
|
|
|
|
|
for (let j = 1; positionList[index + 1] - j > item; j = j + 2) {
|
|
|
|
|
arrivalList.push({
|
|
|
|
|
stationName: dataList[columnNum][item + j],
|
|
|
|
|
arriveTime: reg3.test(dataList[i][item + j]) ? dataList[i][item + j] : '',
|
|
|
|
|
departureTime: reg3.test(dataList[i][item + j + 1]) ? dataList[i][item + j + 1] : ''
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
JsonData.push({
|
|
|
|
|
code: trainIdUp,
|
|
|
|
|
destinationCode: '2',
|
|
|
|
|
arrivalList: arrivalList
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-23 14:27:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return JsonData;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 将后台数据解析成图表*/
|
|
|
|
|
convertDataToModels(data, stations, kmRangeCoordMap, lineStyle) {
|
|
|
|
|
var models = [];
|
|
|
|
|
if (data && data.serviceNumberDataList && data.serviceNumberDataList.length) {
|
|
|
|
|
/** 按服务遍历数据*/
|
|
|
|
|
data.serviceNumberDataList.forEach((service) => {
|
|
|
|
|
/** 按车次遍历数据*/
|
|
|
|
|
var opt = { name: '', markPointData: [], data: [] };
|
|
|
|
|
if (service.tripNumberDataList && service.tripNumberDataList.length) {
|
|
|
|
|
service.tripNumberDataList.forEach((train, j) => {
|
|
|
|
|
var pointdata = {};
|
|
|
|
|
var idx = 0;
|
|
|
|
|
var num = 0;
|
|
|
|
|
var lastPoint = null;
|
|
|
|
|
var nextPoint = null;
|
|
|
|
|
|
|
|
|
|
/** 如果车次号为空,不显示名称*/
|
|
|
|
|
if (train.tripNumber) {
|
|
|
|
|
/** 创建标记点名称和坐标*/
|
|
|
|
|
pointdata.name = `${service.serviceNumber}${train.directionCode}${train.tripNumber}`;
|
|
|
|
|
pointdata.color = '#000' || lineStyle.color;
|
|
|
|
|
pointdata.directionCode = train.directionCode;
|
|
|
|
|
pointdata.coord = [train.stationTimeList[1].secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, train.stationTimeList[1], train.directionCode, false)];
|
|
|
|
|
|
|
|
|
|
/** 给服务对象添加服务名称和标记点*/
|
|
|
|
|
opt.markPointData.push(createMartPoint(pointdata));
|
|
|
|
|
/** 创建服务号名称*/
|
|
|
|
|
opt.name = `${service.serviceNumber}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 计算非折返点车次点坐标集合*/
|
|
|
|
|
train.stationTimeList.forEach((elem, index) => {
|
|
|
|
|
idx = index;
|
|
|
|
|
if (index == 0 && train.stationTimeList[index].stationCode != train.stationTimeList[index + 1].stationCode ||
|
|
|
|
|
index == train.stationTimeList.length - 2 && train.stationTimeList[index].secondTime != train.stationTimeList[index + 1].secondTime ||
|
|
|
|
|
index > 0 && index < train.stationTimeList.length - 1) {
|
|
|
|
|
const aa = `${train.directionCode}${train.tripNumber}`;
|
|
|
|
|
opt.data.push([elem.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, elem, elem.directionCode, false), elem.stationCode, aa]);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/** 计算折返点车次坐标点集合*/
|
|
|
|
|
if (!train.backup && train.reentry && service.tripNumberDataList[j + 1] && service.tripNumberDataList[j + 1].stationTimeList) {
|
|
|
|
|
lastPoint = train.stationTimeList[idx - 1];
|
|
|
|
|
nextPoint = service.tripNumberDataList[j + 1].stationTimeList[1];
|
|
|
|
|
num = this.computedReentryNumber(train.tripNumber);
|
|
|
|
|
opt.data.push([lastPoint.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, lastPoint, train.directionCode, true, num), lastPoint.stationCode]);
|
|
|
|
|
opt.data.push([nextPoint.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, nextPoint, train.directionCode, true, num), nextPoint.stationCode]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 如果是备用车,按车次添加线*/
|
|
|
|
|
if (train.backup) {
|
|
|
|
|
/** 创建一条完成的服务数据*/
|
|
|
|
|
opt.name += j;
|
|
|
|
|
var model = createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
|
|
|
|
if (model) {
|
|
|
|
|
models.push(model);
|
|
|
|
|
opt = { name: '', markPointData: [], data: [] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 不是备用车,按服务添加线
|
|
|
|
|
if (!service.backup) {
|
|
|
|
|
/** 创建一条完成的服务数据*/
|
|
|
|
|
var model = createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
|
|
|
|
if (model) {
|
|
|
|
|
models.push(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return models;
|
|
|
|
|
} else {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 更新数据并解析成图表*/
|
|
|
|
|
updateDataToModels(data, stations, kmRangeCoordMap, runPlanData, series, lineStyle) {
|
|
|
|
|
if (data && data.length) {
|
|
|
|
|
data.forEach(elem => {
|
|
|
|
|
/** 判断此条记录的服务号是否存在*/
|
|
|
|
|
if (!runPlanData[elem.serviceNumber]) {
|
|
|
|
|
/** 创建一个新服务号标记*/
|
|
|
|
|
runPlanData[elem.serviceNumber] = {};
|
|
|
|
|
/** 不存在此服务号,则需要创建一条新的line*/
|
|
|
|
|
series.push(createSeriesModel({
|
|
|
|
|
zlevel: 1,
|
|
|
|
|
name: `run${elem.serviceNumber}`,
|
|
|
|
|
data: [],
|
|
|
|
|
markPointData: []
|
|
|
|
|
}, Object.assign({ color: hexColor.toCreate() }, lineStyle)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 添加数据*/
|
|
|
|
|
series.forEach(serie => {
|
|
|
|
|
/** 找到服务号所在图数据的位置*/
|
|
|
|
|
if (serie.name == `run${elem.serviceNumber}`) {
|
|
|
|
|
/** 添加车组号记录标记*/
|
|
|
|
|
if (!runPlanData[elem.serviceNumber][elem.tripNumber]) {
|
|
|
|
|
runPlanData[elem.serviceNumber][elem.tripNumber] = [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
runPlanData[elem.serviceNumber][elem.tripNumber].push(elem);
|
|
|
|
|
runPlanData[elem.serviceNumber][elem.tripNumber].sort((a, b) => {
|
|
|
|
|
return parseInt(a.secondTime) - parseInt(b.secondTime);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/** 如果此记录车组号的数据为第一条时,则打上标签*/
|
|
|
|
|
if (runPlanData[elem.serviceNumber][elem.tripNumber].length <= 1) {
|
|
|
|
|
serie.markPoint.data.push(createMartPoint({
|
|
|
|
|
directionCode: elem.directionCode,
|
|
|
|
|
coord: [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeCoordMap, elem, false)],
|
|
|
|
|
name: `(${elem.groupNumber})${elem.serviceNumber}${elem.directionCode}${elem.tripNumber}`,
|
|
|
|
|
color: lineStyle.color || '#000'
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 计算折返点*/
|
|
|
|
|
var nextPoint = [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeCoordMap, elem, false), elem.directionCode];
|
|
|
|
|
if (serie.data.length > 0) {
|
|
|
|
|
var lastPoint = serie.data[serie.data.length - 1];
|
|
|
|
|
if (lastPoint[2] !== nextPoint[2]) {
|
|
|
|
|
var num = this.computedReentryNumber(elem.tripNumber);
|
|
|
|
|
serie.data.push([lastPoint[0], this.getYvalueByDirectionCode(lastPoint[1], lastPoint[2], num), lastPoint[2]]);
|
|
|
|
|
serie.data.push([nextPoint[0], this.getYvalueByDirectionCode(nextPoint[1], lastPoint[2], num), lastPoint[2]]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 添加车组号数据到对应的服务图数据中*/
|
|
|
|
|
serie.data.push(nextPoint);
|
|
|
|
|
|
|
|
|
|
/** 保证原始数据排序*/
|
|
|
|
|
serie.data.sort((a, b) => {
|
|
|
|
|
return parseInt(a[0]) - parseInt(b[0]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return series;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 初始化Y轴*/
|
|
|
|
|
initializeYaxis(stations) {
|
|
|
|
|
return createMarkLineModels(stations, (elem) => {
|
|
|
|
|
return this.EdgeHeight + elem.kmRange * this.CoordMultiple;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 将后台数据转换为试图序列模型*/
|
|
|
|
|
convertStationsToMap(stations) {
|
|
|
|
|
var map = {};
|
|
|
|
|
if (stations && stations.length) {
|
|
|
|
|
stations.forEach((elem) => {
|
|
|
|
|
map[`${elem.kmRange}`] = this.EdgeHeight + elem.kmRange * this.CoordMultiple;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 计算y轴最小值*/
|
|
|
|
|
computedYaxisMinValue(stations) {
|
|
|
|
|
return stations[0].kmRange * this.CoordMultiple;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 计算y轴最大值*/
|
|
|
|
|
computedYaxisMaxValue(stations) {
|
|
|
|
|
return stations[stations.length - 1].kmRange * this.CoordMultiple + this.EdgeHeight * 2;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 格式化y轴数据*/
|
|
|
|
|
computedFormatYAxis(stations, params) {
|
|
|
|
|
var yText = '0m';
|
|
|
|
|
|
|
|
|
|
stations.forEach(elem => {
|
|
|
|
|
if (elem.kmRange < parseInt(params.value) / this.CoordMultiple - this.EdgeHeight) {
|
|
|
|
|
yText = Math.floor(elem.kmRange) + 'm';
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return yText;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 根据是否和上一个车次是否相交,计算下一个车次的折返的高度*/
|
|
|
|
|
computedReentryNumber(code) {
|
|
|
|
|
return parseInt(code || 1) % 2 ? 1 : 2;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 根据方向计算y折返偏移量*/
|
|
|
|
|
getYvalueByDirectionCode(defaultVlue, directionCode, num) {
|
|
|
|
|
if (directionCode === '1') {
|
|
|
|
|
defaultVlue -= this.EdgeHeight / 2 * num;
|
|
|
|
|
} else if (directionCode === '2') {
|
|
|
|
|
defaultVlue += this.EdgeHeight / 2 * num;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultVlue;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 根据elem计算y值*/
|
|
|
|
|
getCoordYByElem(stations, kmRangeCoordMap, elem, directionCode, isSpecial, num) {
|
|
|
|
|
var defaultVlue = 0;
|
|
|
|
|
var station = stations.find(it => { return it.code == elem.stationCode; });
|
|
|
|
|
if (station) {
|
|
|
|
|
defaultVlue = kmRangeCoordMap[`${station.kmRange}`];
|
|
|
|
|
if (isSpecial) {
|
|
|
|
|
defaultVlue = this.getYvalueByDirectionCode(defaultVlue, directionCode, num);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultVlue;
|
|
|
|
|
}
|
|
|
|
|
};
|