2019-11-29 12:51:58 +08:00
|
|
|
|
import { createMartPoint, createSeriesModel, createMarkLineModels, hexColor, prefixTime, convertSheetToList } from '@/utils/runPlan';
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
/** 边缘高度*/
|
|
|
|
|
EdgeHeight: 3,
|
|
|
|
|
|
|
|
|
|
/** 间隔高度*/
|
|
|
|
|
CoordMultiple: 3,
|
|
|
|
|
|
|
|
|
|
/** 偏移时间*/
|
|
|
|
|
TranslationTime: 60 * 60 * 2,
|
|
|
|
|
|
|
|
|
|
/** excel解析配置*/
|
|
|
|
|
ExcelConfig: {
|
|
|
|
|
beginRow: 1,
|
|
|
|
|
beginCol: 0,
|
|
|
|
|
// fieldNum: 10,
|
|
|
|
|
columns: {
|
|
|
|
|
'默认上行折返轨': { key: 'upTrack', formatter: (val) => { return val; } },
|
|
|
|
|
'默认下行折返轨': { key: 'downTrack', formatter: (val) => { return val; } }
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 解析exal数据转换为Json后台数据*/
|
|
|
|
|
importData(Sheet, JsonData) {
|
|
|
|
|
const dataList = convertSheetToList(Sheet, true);
|
|
|
|
|
const needList = Object.keys(this.ExcelConfig.columns);
|
|
|
|
|
const tripObj = { upTrack: '', downTrack: '' };
|
|
|
|
|
if (dataList && dataList.length && dataList[1] && dataList[0]) {
|
|
|
|
|
const tIndex = dataList.findIndex(it => { return it[0]; });
|
|
|
|
|
if (dataList[0][0] == needList[0] && dataList[1][0] == needList[1]) {
|
|
|
|
|
for (var colIndex = this.ExcelConfig.beginCol; colIndex < dataList.length; colIndex += 1) {
|
|
|
|
|
var isContinue = true;
|
|
|
|
|
|
|
|
|
|
for (var rowIndex = this.ExcelConfig.beginRow; isContinue; rowIndex += 1) {
|
|
|
|
|
isContinue = false;
|
|
|
|
|
|
|
|
|
|
var title = dataList[colIndex][0];
|
|
|
|
|
var value = dataList[colIndex][rowIndex];
|
|
|
|
|
|
|
|
|
|
if (title && value) {
|
|
|
|
|
// 数据列解析
|
|
|
|
|
isContinue = true;
|
|
|
|
|
var titleStr = `${title}`.replace(/\s*/g, '');
|
|
|
|
|
var valueStr = `${value}`.replace(/\s*/g, '');
|
|
|
|
|
|
|
|
|
|
// 取需要的字段
|
|
|
|
|
if (needList.findIndex(elem => { return elem == titleStr; }) >= 0) {
|
|
|
|
|
tripObj[this.ExcelConfig.columns[titleStr].key] = this.ExcelConfig.columns[titleStr].formatter(valueStr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/** 解析二维数组为json对象*/
|
|
|
|
|
const reg0 = /^[↑|↓|¡|ü|ý|]+(.*)/; // ↑|↓
|
|
|
|
|
const reg1 = /^([▼|▲|¡ø|¨]+)\s*(\d+:\d+:\d+)/; // ▲ 06:10:00
|
|
|
|
|
const reg2 = /^(\d+:\d+:\d+)\s*([▼|▲|¡ø|¨]+)/; // 06:10:00 ▲
|
|
|
|
|
const reg3 = /^(\d+:\d+:\d+)\s*(\d+:\d+:\d+|)/; // 06:10:00 06:12:00
|
|
|
|
|
const reg4 = /[▼|▲|¡|ø|¨|]+/; // ▲
|
|
|
|
|
|
|
|
|
|
dataList.forEach((elem, i) => {
|
|
|
|
|
var begin = -1;
|
|
|
|
|
/** 跳过名称所在的行*/
|
|
|
|
|
if (i != tIndex && elem && elem.length > 0) {
|
|
|
|
|
elem.forEach((item, j) => {
|
|
|
|
|
/** 过滤空值*/
|
|
|
|
|
if (item) {
|
|
|
|
|
var value = `${item}`.trim();
|
|
|
|
|
var title = `${dataList[tIndex][j]}`.replace(/\s*/g, '');
|
|
|
|
|
/** 匹配到开始位置或者结束位置*/
|
|
|
|
|
if (reg0.test(value)) {
|
|
|
|
|
if (begin == -1) {
|
|
|
|
|
begin = value; // 设置初始索引
|
|
|
|
|
JsonData.push({
|
|
|
|
|
code: reg0.exec(value)[1],
|
|
|
|
|
arrivalList: []
|
|
|
|
|
});
|
|
|
|
|
} else if (begin === value) {
|
|
|
|
|
begin = -1; // 清空初始索引
|
|
|
|
|
}
|
|
|
|
|
} else if (begin !== -1) {
|
|
|
|
|
/** 匹配到中间位置*/
|
|
|
|
|
var begTime, endTime;
|
|
|
|
|
var runFlag = JsonData[JsonData.length - 1].code[2];
|
|
|
|
|
var stationName = title.replace(/\s/, '');
|
|
|
|
|
var need = false;
|
|
|
|
|
var flag = false;
|
|
|
|
|
if (reg1.test(value)) {
|
|
|
|
|
/** 含有特殊字符的时间格式*/
|
|
|
|
|
[, begTime, endTime] = reg1.exec(value);
|
|
|
|
|
|
|
|
|
|
begTime = reg4.test(begTime) ? '' : begTime;
|
|
|
|
|
endTime = reg4.test(endTime) ? '' : endTime;
|
|
|
|
|
|
|
|
|
|
/** 下行方向时间互换*/
|
|
|
|
|
if (runFlag === '2') {
|
|
|
|
|
[begTime, endTime] = [endTime, begTime];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 设置标志*/
|
|
|
|
|
[need, flag] = [true, true];
|
|
|
|
|
} else if (reg2.test(value)) {
|
|
|
|
|
/** 含有特殊字符的时间格式*/
|
|
|
|
|
[, begTime, endTime] = reg2.exec(value);
|
|
|
|
|
|
|
|
|
|
begTime = reg4.test(begTime) ? '' : begTime;
|
|
|
|
|
endTime = reg4.test(endTime) ? '' : endTime;
|
|
|
|
|
|
|
|
|
|
/** 下行方向时间互换*/
|
|
|
|
|
if (runFlag === '2') {
|
|
|
|
|
[begTime, endTime] = [endTime, begTime];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 设置标志*/
|
|
|
|
|
[need, flag] = [true, true];
|
|
|
|
|
} else if (reg3.test(value)) {
|
|
|
|
|
/** 正常时间格式*/
|
|
|
|
|
[, begTime, endTime] = reg3.exec(value);
|
|
|
|
|
|
|
|
|
|
/** 如果只存在一个数据时,则开始和结束设置一样*/
|
|
|
|
|
endTime = endTime || begTime;
|
|
|
|
|
|
|
|
|
|
/** 下行方向时间互换*/
|
|
|
|
|
if (runFlag === '2') {
|
|
|
|
|
[begTime, endTime] = [endTime, begTime];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 设置标志*/
|
|
|
|
|
[need, flag] = [true, false];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 添加json数据*/
|
|
|
|
|
if (need) { // 储存非空 数据
|
|
|
|
|
var stationObj = {
|
|
|
|
|
stationName: stationName
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (begTime) { stationObj['arriveTime'] = prefixTime(begTime); }
|
|
|
|
|
if (endTime) { stationObj['departureTime'] = prefixTime(endTime); }
|
|
|
|
|
if (flag) { stationObj['flag'] = flag; } // 是否转换轨
|
|
|
|
|
JsonData[JsonData.length - 1].arrivalList.push(stationObj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
JsonData.forEach(item => {
|
|
|
|
|
item['upTrack'] = tripObj.upTrack;
|
|
|
|
|
item['downTrack'] = tripObj.downTrack;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return JsonData;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 将后台数据解析成图表*/
|
|
|
|
|
convertDataToModels(data, stations, kmRangeCoordMap, lineStyle) {
|
|
|
|
|
var models = [];
|
|
|
|
|
|
|
|
|
|
if (data && data.serviceNumberDataList && data.serviceNumberDataList.length) {
|
|
|
|
|
/** 按服务遍历数据*/
|
|
|
|
|
data.serviceNumberDataList.forEach((service) => {
|
|
|
|
|
/** 按车次遍历数据*/
|
|
|
|
|
var isBackup = true;
|
|
|
|
|
var opt = { name: '', markPointData: [], data: [] };
|
|
|
|
|
if (service.tripNumberDataList && service.tripNumberDataList.length) {
|
|
|
|
|
service.tripNumberDataList.forEach((train, j) => {
|
|
|
|
|
var pointdata = {};
|
|
|
|
|
var idx = 0;
|
|
|
|
|
var lastPoint = null;
|
|
|
|
|
var nextPoint = null;
|
|
|
|
|
|
|
|
|
|
/** 创建标记点名称和坐标*/
|
2020-08-31 13:25:26 +08:00
|
|
|
|
// pointdata.name = `${service.serviceNumber}${train.directionCode}${train.tripNumber}`;
|
|
|
|
|
pointdata.name = `${service.serviceNumber}${train.tripNumber}`;
|
2019-11-29 12:51:58 +08:00
|
|
|
|
pointdata.color = '#000' || lineStyle.color;
|
|
|
|
|
pointdata.directionCode = train.directionCode;
|
|
|
|
|
pointdata.coord = [train.stationTimeList[0].secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, train.stationTimeList[0], train.directionCode, false)];
|
|
|
|
|
|
|
|
|
|
/** 给服务对象添加服务名称和标记点*/
|
|
|
|
|
opt.name = '' + service.serviceNumber;
|
|
|
|
|
opt.markPointData.push(createMartPoint(pointdata));
|
|
|
|
|
|
|
|
|
|
/** 计算非折返点车次点坐标集合*/
|
|
|
|
|
train.stationTimeList.forEach((elem, index) => {
|
|
|
|
|
idx = index;
|
|
|
|
|
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];
|
|
|
|
|
nextPoint = service.tripNumberDataList[j + 1].stationTimeList[0];
|
|
|
|
|
const aa = `${train.directionCode}${train.tripNumber}`;
|
|
|
|
|
opt.data.push([lastPoint.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, lastPoint, train.directionCode, true), lastPoint.stationCode, aa, '折返轨']);
|
|
|
|
|
opt.data.push([nextPoint.secondTime, this.getCoordYByElem(stations, kmRangeCoordMap, lastPoint, train.directionCode, true), lastPoint.stationCode, aa, '折返轨']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 如果是备用车,按车次添加线*/
|
|
|
|
|
if (train.backup) {
|
|
|
|
|
/** 创建一条完成的服务数据*/
|
|
|
|
|
opt.name += j;
|
|
|
|
|
// var model = createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
|
|
|
|
var model = createSeriesModel(opt, Object.assign({ color: '#000' }, lineStyle));
|
|
|
|
|
if (model) {
|
|
|
|
|
models.push(model);
|
|
|
|
|
opt = { name: '', markPointData: [], data: [] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isBackup = train.backup;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 不是备用车,按服务添加线
|
|
|
|
|
if (!isBackup) {
|
|
|
|
|
/** 创建一条完成的服务数据*/
|
|
|
|
|
// var model = createSeriesModel(opt, Object.assign({ color: hexColor.toCreate() }, lineStyle));
|
|
|
|
|
var model = createSeriesModel(opt, Object.assign({ color: '#000' }, 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) {
|
2020-08-28 11:30:55 +08:00
|
|
|
|
const result = serie.markPoint.data.some(ele => ele.name == `(${elem.groupNumber})${elem.serviceNumber}${elem.tripNumber}`);
|
|
|
|
|
if (!result) {
|
|
|
|
|
serie.markPoint.data.push(createMartPoint({
|
|
|
|
|
directionCode: elem.directionCode,
|
|
|
|
|
coord: [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeCoordMap, elem)],
|
2020-08-31 13:25:26 +08:00
|
|
|
|
name: `(${elem.groupNumber})${elem.serviceNumber}${elem.tripNumber}`,
|
2020-08-28 11:30:55 +08:00
|
|
|
|
color: lineStyle.color || '#000'
|
|
|
|
|
}));
|
|
|
|
|
}
|
2019-11-29 12:51:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 计算折返点*/
|
|
|
|
|
var nextPoint = [parseInt(elem.secondTime), this.getCoordYByElem(stations, kmRangeCoordMap, elem), elem.directionCode];
|
|
|
|
|
if (serie.data.length > 0) {
|
|
|
|
|
var lastPoint = serie.data[serie.data.length - 1];
|
|
|
|
|
if (lastPoint[2] !== nextPoint[2]) {
|
|
|
|
|
serie.data.push([lastPoint[0], this.getYvalueByDirectionCode(lastPoint[1], lastPoint[2]), lastPoint[2]]);
|
|
|
|
|
serie.data.push([nextPoint[0], this.getYvalueByDirectionCode(nextPoint[1], lastPoint[2]), lastPoint[2]]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 添加车组号数据到对应的服务图数据中*/
|
|
|
|
|
serie.data.push(nextPoint);
|
|
|
|
|
|
|
|
|
|
/** 保证原始数据排序*/
|
|
|
|
|
serie.data.sort((a, b) => {
|
|
|
|
|
return parseInt(a[0]) - parseInt(b[0]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return series;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 将后台数据转换为试图序列模型*/
|
|
|
|
|
convertStationsToMap(stations) {
|
|
|
|
|
var map = {};
|
|
|
|
|
if (stations && stations.length) {
|
|
|
|
|
stations.forEach((elem, index) => {
|
|
|
|
|
map[`${elem.kmRange}`] = this.EdgeHeight + index * this.CoordMultiple;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
},
|
|
|
|
|
/** 初始化Y轴*/
|
|
|
|
|
initializeYaxis(stations) {
|
|
|
|
|
return createMarkLineModels(stations, (elem, index) => {
|
|
|
|
|
return this.EdgeHeight + index * this.CoordMultiple;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 计算y轴最小值*/
|
|
|
|
|
computedYaxisMinValue() {
|
|
|
|
|
return 0;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 计算y轴最大值*/
|
|
|
|
|
computedYaxisMaxValue(stations) {
|
|
|
|
|
return this.EdgeHeight * 2 + (stations.length - 1) * this.CoordMultiple;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 格式化y轴数据*/
|
|
|
|
|
computedFormatYAxis(stations, params) {
|
2020-01-07 14:49:51 +08:00
|
|
|
|
var yText = '0m';
|
2019-11-29 12:51:58 +08:00
|
|
|
|
var index = Math.floor((parseInt(params.value) - this.EdgeHeight) / this.CoordMultiple);
|
|
|
|
|
if (index >= 0 && index < stations.length) {
|
2020-01-07 14:49:51 +08:00
|
|
|
|
yText = Math.floor(stations[index].kmRange) + 'm';
|
2019-11-29 12:51:58 +08:00
|
|
|
|
}
|
|
|
|
|
return yText;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 根据方向计算y折返偏移量*/
|
|
|
|
|
getYvalueByDirectionCode(defaultVlue, directionCode) {
|
|
|
|
|
if (directionCode === '1') {
|
|
|
|
|
defaultVlue -= this.EdgeHeight / 2;
|
|
|
|
|
} else if (directionCode === '2') {
|
|
|
|
|
defaultVlue += this.EdgeHeight / 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultVlue;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/** 根据elem计算y值*/
|
|
|
|
|
getCoordYByElem(stations, kmRangeCoordMap, elem, directionCode, isSpecial) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return defaultVlue;
|
|
|
|
|
}
|
|
|
|
|
};
|