UNPKG

tlk

Version:

查询指定车次的所有站点的余票信息

68 lines (57 loc) 1.42 kB
import table from 'text-table' import Table from 'cli-table-zh' import chalk from 'chalk' import _ from 'lodash' import strlen from './strlen' const setType = [ '商务座', '一等座', '二等座', '高级软卧', '动卧', '软卧', '硬卧', '软座', '硬座', '无座', '其他', ] export default trains => { const table = new Table({ head: ['车次', '上车', '到达', '时间'].concat(setType), // colWidths: [8, 10, 10, 20, 20, 20, 20], // style: { compact: false, mid: 1 }, }) trains.map(t => { const row = print(t) table.push(row) }) // const r = table(tt, { // align: ['l', 'l', 'l', 'l', 'l', 'l'], // hsep: ' '.repeat(4), // stringLength: strlen, // }).replace(/^/gm, ' ') // eslint-disable-next-line console.log(table.toString()) } function print(train) { let row = [ train.TrainNumber, train.DepartStation, train.ArriveStation, `${train.DepartTime} - ${train.ArriveTime} ${ train.TakeDays ? chalk.red('+1') : '' }`, ] const { SeatList } = train const setRow = setType.map(ty => { const ss = _.find(SeatList, s => s.SeatName === ty) if (!ss) return '--' if (!ss.SeatBookable) return '无' const count = ss.SeatInventory >= 99 ? chalk.yellow('有') : chalk.red(ss.SeatInventory) return `${count} (${ss.ShowSeatPrice})` }) row = row.concat(setRow) return row }