121 lines
5.7 KiB
JavaScript
121 lines
5.7 KiB
JavaScript
|
import { convertSheetToList, prefixTime } from '../parser/util';
|
||
|
|
||
|
export default {
|
||
|
/** 运行图解析方式*/
|
||
|
type: 'Ratio',
|
||
|
|
||
|
/** 边缘高度*/
|
||
|
height: 600,
|
||
|
|
||
|
/** 间隔高度*/
|
||
|
multiple: 1,
|
||
|
|
||
|
/** 偏移时间*/
|
||
|
translation: 60 * 60 * 2,
|
||
|
|
||
|
/** excel解析配置*/
|
||
|
excelConfig: {
|
||
|
beginRow: 1,
|
||
|
beginCol: 0,
|
||
|
fieldNum: 10,
|
||
|
sepField: '行车间隔',
|
||
|
trainId: 'TrainID',
|
||
|
columns: ['折返线', 'TrainID', '行车间隔']
|
||
|
},
|
||
|
|
||
|
/** 解析excel数据转换为Json后台数据*/
|
||
|
importData(Sheet, JsonData) {
|
||
|
var dataList = convertSheetToList(Sheet, true);
|
||
|
if (dataList && dataList.length) {
|
||
|
if (dataList && dataList.length && dataList[1] && dataList[0]) {
|
||
|
// const tIndex = dataList.findIndex(it => { return it[0]; }); // 设置不用过滤行数
|
||
|
const tIndex = 9; // 设置不用过滤行数
|
||
|
|
||
|
/** 解析二维数组为json对象*/
|
||
|
const reg3 = /^(\d+:\d+:\d+|)/; // 06:12:00
|
||
|
dataList.forEach((elem, i) => {
|
||
|
var begin = -1;
|
||
|
/** 跳过名称所在的行*/
|
||
|
if (i != tIndex && elem && elem.length > 0) {
|
||
|
let flag = false;
|
||
|
let count = 0;
|
||
|
let param = { begTime: '', endTime: '' };
|
||
|
if (i > tIndex) { elem.reverse(); }
|
||
|
elem.forEach((item, j) => {
|
||
|
/** 过滤空值*/
|
||
|
if (item) {
|
||
|
let title = '';
|
||
|
var value = `${item}`.trim();
|
||
|
if (i > tIndex) { // 上行线
|
||
|
title = `${dataList[tIndex][dataList[tIndex].length - j - 1]}`.replace(/\s*/g, '');
|
||
|
if (title == 'undefined') {
|
||
|
title = `${dataList[tIndex][dataList[tIndex].length - j - 2]}`.replace(/\s*/g, '');
|
||
|
}
|
||
|
} else { // 下行线
|
||
|
title = `${dataList[tIndex][j]}`.replace(/\s*/g, '');
|
||
|
if (title == 'undefined') {
|
||
|
title = `${dataList[tIndex][j - 1]}`.replace(/\s*/g, '');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** 匹配到开始位置或者结束位置*/
|
||
|
if (title == this.excelConfig.trainId) {
|
||
|
if (begin == -1) {
|
||
|
flag = true;
|
||
|
begin = value; // 设置初始索引
|
||
|
JsonData.push({
|
||
|
code: value,
|
||
|
destinationCode: '',
|
||
|
arrivalList: []
|
||
|
});
|
||
|
} else if (flag) {
|
||
|
begin = -1; // 清空初始索引
|
||
|
JsonData[JsonData.length - 1].destinationCode = value;
|
||
|
flag = false;
|
||
|
}
|
||
|
} else if (begin !== -1) {
|
||
|
/** 匹配到中间位置*/
|
||
|
var stationName = title.replace(/\s/, '');
|
||
|
if (this.excelConfig.columns.indexOf(stationName) == -1 && reg3.test(value)) {
|
||
|
let need = false;
|
||
|
if (value.split(':')[0] == '24') { // 24:XX:XX 类似这种数据 变24为00
|
||
|
const arr = value.split(':');
|
||
|
arr[0] = '00';
|
||
|
value = arr.join(':');
|
||
|
}
|
||
|
if (count == 1) {
|
||
|
count = 0;
|
||
|
param.endTime = value;
|
||
|
}
|
||
|
if (count == 0) {
|
||
|
count = 1;
|
||
|
param.begTime = param.begTime || value;
|
||
|
}
|
||
|
|
||
|
if (param.begTime && param.endTime) {
|
||
|
need = true;
|
||
|
}
|
||
|
|
||
|
/** 添加json数据*/
|
||
|
if (need) { // 储存非空 数据
|
||
|
var stationObj = {
|
||
|
stationName: stationName
|
||
|
};
|
||
|
stationObj['arriveTime'] = prefixTime(param.begTime);
|
||
|
stationObj['departureTime'] = prefixTime(param.endTime);
|
||
|
JsonData[JsonData.length - 1].arrivalList.push(stationObj);
|
||
|
param = { begTime: '', endTime: '' };
|
||
|
count = 0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
return JsonData;
|
||
|
}
|
||
|
};
|