Merge branch 'test' of https://git.code.tencent.com/lian-cbtc/jl-client into test
This commit is contained in:
commit
ada7d199c8
@ -15,85 +15,204 @@ export default {
|
||||
beginRow: 1,
|
||||
beginCol: 0,
|
||||
fieldNum: 6,
|
||||
sepField: '车次号',
|
||||
columns: {
|
||||
'停车站名称': { key: 'stationName', formatter: (val) => { return val; } },
|
||||
'到达时间': { key: 'arriveTime', formatter: (val) => { return val; } },
|
||||
'出发时间': { key: 'departureTime', formatter: (val) => { return val; } }
|
||||
}
|
||||
trainId: '车次号',
|
||||
ignoreColumns: ['备注', '车次号', '运行方向']
|
||||
// sepField: '下行线 / 往金海路方向',
|
||||
// columns: {
|
||||
// '停车站名称': { key: 'stationName', formatter: (val) => { return val; } },
|
||||
// '到达时间': { key: 'arriveTime', formatter: (val) => { return val; } },
|
||||
// '出发时间': { key: 'departureTime', formatter: (val) => { return val; } }
|
||||
// }
|
||||
},
|
||||
|
||||
/** 解析exal数据转换为Json后台数据*/
|
||||
importData(Sheet, JsonData) {
|
||||
const dataList = convertSheetToList(Sheet, true);
|
||||
const needList = Object.keys(this.ExcelConfig.columns);
|
||||
|
||||
// const needList = Object.keys(this.ExcelConfig.columns);
|
||||
if (dataList && dataList.length) {
|
||||
for (let colIndex = this.ExcelConfig.beginCol; colIndex < dataList.length; colIndex += this.ExcelConfig.fieldNum + 1) {
|
||||
let isContinue = true;
|
||||
let tripObj = { code: '', directionCode: '', arrivalList: [] };
|
||||
for (let rowIndex = this.ExcelConfig.beginRow; isContinue; rowIndex += 1) {
|
||||
isContinue = false;
|
||||
|
||||
const stationObj = {};
|
||||
for (let index = 0; index < this.ExcelConfig.fieldNum; index += 1) {
|
||||
if (dataList[colIndex + index]) {
|
||||
const title = dataList[colIndex + index][0];
|
||||
const value = dataList[colIndex + index][rowIndex];
|
||||
|
||||
if (title && value) {
|
||||
// 数据列解析
|
||||
isContinue = true;
|
||||
const titleStr = `${title}`.trim();
|
||||
let valueStr = `${value}`.trim();
|
||||
|
||||
if (titleStr == this.ExcelConfig.sepField) {
|
||||
valueStr = `${dataList[colIndex + index - 1][rowIndex]}${valueStr}`;
|
||||
if (tripObj.code) {
|
||||
const length = tripObj.arrivalList.length;
|
||||
if (length == 1) {
|
||||
tripObj.arrivalList[0]['flag'] = true;
|
||||
if (dataList[1] && dataList[0]) {
|
||||
const tIndexStart = 5; // 设置不用过滤开始行数
|
||||
const tIndexEnd = 7; // 设置不用过滤结束行数
|
||||
/** 解析二维数组为json对象*/
|
||||
const reg3 = /^(\d+:\d+:\d+|)/; // 06:12:00
|
||||
dataList.forEach((elem, i) => {
|
||||
var begin = -1;
|
||||
/** 跳过名称所在的行*/
|
||||
if ((i < tIndexStart || i > tIndexEnd) && elem && elem.length > 0) {
|
||||
let count = 0;
|
||||
let param = { begTime: '', endTime: '' };
|
||||
let stationName = '';
|
||||
if (i > tIndexEnd) { elem.reverse(); }
|
||||
// debugger;
|
||||
elem.forEach((item, j) => {
|
||||
/** 过滤空值*/
|
||||
if (item) {
|
||||
let title = '';
|
||||
let nextTitle = '';
|
||||
var value = `${item}`.trim();
|
||||
if (i > tIndexEnd) { // 上行线
|
||||
title = `${dataList[tIndexStart][dataList[tIndexStart].length - j - 1]}`.replace(/\s*/g, '');
|
||||
if (title == '到点' || title == '发点') {
|
||||
title = `${dataList[tIndexEnd][dataList[tIndexEnd].length - j - 1]}`.replace(/\s*/g, '');
|
||||
}
|
||||
if (valueStr != tripObj.code) {
|
||||
JsonData.push(tripObj);
|
||||
const strVal = `${value}`.trim();
|
||||
tripObj = { code: valueStr, directionCode: strVal[0], arrivalList: [] };
|
||||
nextTitle = dataList[tIndexEnd - 1][dataList[tIndexEnd - 1].length - j - 1];
|
||||
if (title == 'undefined') {
|
||||
title = `${dataList[tIndexStart][dataList[tIndexStart].length - j - 2]}`.replace(/\s*/g, '');
|
||||
if (title == '到点' || title == '发点') {
|
||||
title = `${dataList[tIndexEnd][dataList[tIndexEnd].length - j - 2]}`.replace(/\s*/g, '');
|
||||
}
|
||||
nextTitle = dataList[tIndexEnd - 1][dataList[tIndexEnd - 1].length - j - 2];
|
||||
}
|
||||
} else if (i < tIndexStart) { // 下行线
|
||||
title = `${dataList[tIndexStart][j]}`.replace(/\s*/g, '');
|
||||
nextTitle = dataList[tIndexStart + 1][j];
|
||||
if (title == 'undefined') {
|
||||
title = `${dataList[tIndexStart][j - 1]}`.replace(/\s*/g, '');
|
||||
nextTitle = dataList[tIndexStart + 1][j - 1];
|
||||
}
|
||||
}
|
||||
/** 匹配到开始位置*/
|
||||
if (title == this.ExcelConfig.trainId) {
|
||||
if (!value.includes('Y') && value != '金备') {
|
||||
begin = value; // 设置初始索引
|
||||
JsonData.push({
|
||||
code: value,
|
||||
destinationCode: '',
|
||||
arrivalList: []
|
||||
});
|
||||
} else {
|
||||
const strVal = `${value}`.trim();
|
||||
tripObj.code = valueStr;
|
||||
tripObj.directionCode = strVal[0];
|
||||
begin = -1; // 设置初始索引
|
||||
}
|
||||
} else if (begin !== -1) {
|
||||
if (this.ExcelConfig.ignoreColumns.indexOf(title) == -1 ) {
|
||||
let need = false;
|
||||
if (nextTitle) { stationName = nextTitle; }
|
||||
if (value == '…') {
|
||||
param.endTime = '…';
|
||||
} else if (value == '▼' || value == '▲') {
|
||||
value = '不填';
|
||||
if (count == 0) {
|
||||
param.endTime = value;
|
||||
count = 1;
|
||||
} else {
|
||||
param.begTime = value;
|
||||
count = 0;
|
||||
}
|
||||
} else if (reg3.test(value)) {
|
||||
if (title == '到点') {
|
||||
param.endTime = value;
|
||||
} else if (title == '发点') {
|
||||
param.begTime = value;
|
||||
} else {
|
||||
if (count == 0) {
|
||||
param.endTime = value;
|
||||
count = 1;
|
||||
} else {
|
||||
param.begTime = value;
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (title != '发点' && title != '到点') {
|
||||
stationName = title;
|
||||
}
|
||||
if (param.begTime && param.endTime) {
|
||||
if (param.endTime == '…') {
|
||||
param.endTime = param.begTime;
|
||||
}
|
||||
if (param.endTime == '不填') {
|
||||
param.endTime = '';
|
||||
} if (param.begTime == '不填') {
|
||||
param.begTime = '';
|
||||
}
|
||||
need = true;
|
||||
}
|
||||
if (need) { // 储存非空 数据
|
||||
var stationObj = {
|
||||
stationName: stationName
|
||||
};
|
||||
stationObj['arriveTime'] = prefixTime(param.endTime);
|
||||
stationObj['departureTime'] = prefixTime(param.begTime);
|
||||
JsonData[JsonData.length - 1].arrivalList.push(stationObj);
|
||||
param = { begTime: '', endTime: '' };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
debugger;
|
||||
console.log(JsonData);
|
||||
}
|
||||
// for (let colIndex = this.ExcelConfig.beginCol; colIndex < dataList.length; colIndex += this.ExcelConfig.fieldNum + 1) {
|
||||
// let isContinue = true;
|
||||
// const tripObj = { code: '', directionCode: '', arrivalList: [] };
|
||||
// for (let rowIndex = this.ExcelConfig.beginRow; isContinue; rowIndex += 1) {
|
||||
// isContinue = false;
|
||||
|
||||
// 取需要的字段
|
||||
if (needList.findIndex(elem => { return elem == titleStr; }) >= 0) {
|
||||
stationObj[this.ExcelConfig.columns[titleStr].key] = this.ExcelConfig.columns[titleStr].formatter(valueStr);
|
||||
if (this.ExcelConfig.columns[titleStr].key == 'arriveTime' || this.ExcelConfig.columns[titleStr].key == 'departureTime') {
|
||||
stationObj[this.ExcelConfig.columns[titleStr].key] = this.ExcelConfig.columns[titleStr].formatter(prefixTime(valueStr));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// const stationObj = {};
|
||||
// for (let index = 0; index < this.ExcelConfig.fieldNum; index += 1) {
|
||||
|
||||
// 添加字段值
|
||||
if (Object.keys(stationObj).length) {
|
||||
if (stationObj.arriveTime) {
|
||||
tripObj.arrivalList.push(stationObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
// // for (let index = 0; index < this.ExcelConfig.fieldNum; index += 1) {
|
||||
// // if (dataList[colIndex + index]) {
|
||||
// // const title = dataList[colIndex + index][0];
|
||||
// // const value = dataList[colIndex + index][rowIndex];
|
||||
|
||||
// 添加最后那条没有车次的记录
|
||||
if (tripObj.code) {
|
||||
const length = tripObj.arrivalList.length;
|
||||
if (length) {
|
||||
tripObj.arrivalList[length - 1]['flag'] = true;
|
||||
}
|
||||
JsonData.push(tripObj);
|
||||
}
|
||||
}
|
||||
// // // 数据列解析
|
||||
// // debugger;
|
||||
// // isContinue = true;
|
||||
// // const titleStr = `${title}`.trim();
|
||||
// // let valueStr = `${value}`.trim();
|
||||
|
||||
// // if (titleStr == this.ExcelConfig.sepField) {
|
||||
// // valueStr = `${dataList[colIndex + index - 1][rowIndex]}${valueStr}`;
|
||||
// // if (tripObj.code) {
|
||||
// // const length = tripObj.arrivalList.length;
|
||||
// // if (length == 1) {
|
||||
// // tripObj.arrivalList[0]['flag'] = true;
|
||||
// // }
|
||||
// // if (valueStr != tripObj.code) {
|
||||
// // JsonData.push(tripObj);
|
||||
// // const strVal = `${value}`.trim();
|
||||
// // tripObj = { code: valueStr, directionCode: strVal[0], arrivalList: [] };
|
||||
// // }
|
||||
// // } else {
|
||||
// // const strVal = `${value}`.trim();
|
||||
// // tripObj.code = valueStr;
|
||||
// // tripObj.directionCode = strVal[0];
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // // 取需要的字段
|
||||
// // if (needList.findIndex(elem => { return elem == titleStr; }) >= 0) {
|
||||
// // stationObj[this.ExcelConfig.columns[titleStr].key] = this.ExcelConfig.columns[titleStr].formatter(valueStr);
|
||||
// // if (this.ExcelConfig.columns[titleStr].key == 'arriveTime' || this.ExcelConfig.columns[titleStr].key == 'departureTime') {
|
||||
// // stationObj[this.ExcelConfig.columns[titleStr].key] = this.ExcelConfig.columns[titleStr].formatter(prefixTime(valueStr));
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
|
||||
// // 添加字段值
|
||||
// if (Object.keys(stationObj).length) {
|
||||
// if (stationObj.arriveTime) {
|
||||
// tripObj.arrivalList.push(stationObj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 添加最后那条没有车次的记录
|
||||
// if (tripObj.code) {
|
||||
// const length = tripObj.arrivalList.length;
|
||||
// if (length) {
|
||||
// tripObj.arrivalList[length - 1]['flag'] = true;
|
||||
// }
|
||||
// JsonData.push(tripObj);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return JsonData;
|
||||
|
@ -14,7 +14,7 @@
|
||||
ref="tree"
|
||||
:data="treeList"
|
||||
node-key="key"
|
||||
:props="{children: 'children',label: 'name'}"
|
||||
:props="{children:'children',label:'name'}"
|
||||
highlight-current
|
||||
:span="22"
|
||||
:filter-node-method="filterNode"
|
||||
|
Loading…
Reference in New Issue
Block a user