import { convertSheetToList } from '../parser/util'; export default { /** 运行图解析方式*/ type: 'Ratio', /** 边缘高度*/ edge: 600, /** 间隔高度*/ multiple: 1, /** 偏移时间*/ translation: 60 * 60 * 2, /** excel解析配置*/ excelConfig: { beginRow: 1, beginCol: 0, fieldNum: 8, sepField: '车次', columns: { '车站名称': { key: 'stationName', formatter: (val) => { return val; } }, '到点': { key: 'arriveTime', formatter: (val) => { return val; } }, '发点': { key: 'departureTime', formatter: (val) => { return val; } } } }, /** 解析excel数据转换为Json后台数据*/ importData(Sheet, JsonData) { var dataList = convertSheetToList(Sheet, false); var needList = Object.keys(this.excelConfig.columns); if (dataList && dataList.length) { for (var rowIndex = this.excelConfig.beginRow; rowIndex < dataList.length; rowIndex += 1) { for (var colIndex = this.excelConfig.beginCol; colIndex < dataList[this.excelConfig.beginCol].length; colIndex += this.excelConfig.fieldNum + 1) { var tripNew, tripObj; var stationObj = {}; tripNew = tripObj = { code: '', arrivalList: [] }; for (var index = 0; index < this.excelConfig.fieldNum; index += 1) { var title = dataList[0][colIndex + index]; var value = dataList[rowIndex][colIndex + index]; if (title && value) { var titleStr = `${title}`.trim(); var valueStr = `${value}`.trim(); if (titleStr.includes(this.excelConfig.sepField)) { tripObj.code = valueStr; JsonData.forEach(elem => { if (elem.code == valueStr) { tripObj = elem; return; } }); } // 取需要的字段 if (needList.findIndex(elem => { return elem == titleStr; }) >= 0) { stationObj[this.excelConfig.columns[titleStr].key] = this.excelConfig.columns[titleStr].formatter(valueStr); } } } tripObj.arrivalList.push(stationObj); if (tripObj.code && tripObj == tripNew) { JsonData.push(tripObj); } } } } return JsonData; } };