diff --git a/src/pages/TrainPage.vue b/src/pages/TrainPage.vue index 318e0c4..e3bd14c 100644 --- a/src/pages/TrainPage.vue +++ b/src/pages/TrainPage.vue @@ -7,204 +7,18 @@ - + - 列车索引 - - - {{ trainInfo.id }} - - - - - 是否上行 + {{ item.label }} {{ - trainInfo.up ? '是' : '否' + item.formatFn + ? item.formatFn(trainInfo[item.key]) + : trainInfo[item.key] }} - - - 车头所在link的索引 - - - {{ trainInfo.headLinkId }} - - - - - 车头所在link内的偏移量 - - - {{ - trainInfo.headLinkOffset - }} - - - - - 车尾所在link的索引 - - - {{ trainInfo.tailLinkId }} - - - - - 车尾所在link内的偏移量 - - - {{ - trainInfo.tailLinkOffset - }} - - - - - 生命信号 - - - {{ trainInfo.heartbeat }} - - - - - 列车所在位置坡度值 - - - {{ trainInfo.slope }} - - - - - 列车所在位置坡度走势 - - - {{ - trainInfo.upslope ? '上坡' : '下坡' - }} - - - - - 列车当前运行方向 - - - {{ - trainInfo.runningUp ? '上行' : '下行' - }} - - - - - 实际运行阻力 - - - {{ trainInfo.runningResistanceSum }}KN - - - - - 空气阻力 - - - {{ trainInfo.airResistance }}KN - - - - - 坡道阻力 - - - {{ trainInfo.rampResistance }}KN - - - - - 曲线阻力 - - - {{ trainInfo.curveResistance }}KN - - - - - 列车运行速度 - - - {{ trainInfo.speed }}km/h - - - - - 头车速传1速度值 - - - {{ trainInfo.headSensorSpeed1 }}km/h - - - - - 头车速传2速度值 - - - {{ trainInfo.headSensorSpeed2 }}km/h - - - - - 尾车速传1速度值 - - - {{ trainInfo.tailSensorSpeed1 }}km/h - - - - - 尾车速传2速度值 - - - {{ trainInfo.tailSensorSpeed2 }}km/h - - - - - 头车雷达速度值 - - - {{ trainInfo.headRadarSpeed }}km/h - - - - - 尾车雷达速度值 - - - {{ trainInfo.tailRadarSpeed }}km/h - - @@ -215,9 +29,55 @@ import { ITrainState, Train } from 'src/graphics/train/Train'; import { useLineStore } from 'src/stores/line-store'; import { ref, watch } from 'vue'; - +interface keyType { + label: string; + key: keyof ITrainState; + formatFn?(v: ITrainState[keyof ITrainState]): string; +} const lineStore = useLineStore(); const trainInfo = ref(); +const list: keyType[] = [ + { label: '列车索引', key: 'id' }, + { label: '是否上行', key: 'up', formatFn: upFormat }, + { label: '车头所在link的索引', key: 'headLinkId' }, + { label: '车头所在link内的偏移量', key: 'headLinkOffset' }, + { label: '车尾所在link的索引', key: 'tailLinkId' }, + { label: '车尾所在link内的偏移量', key: 'tailLinkOffset' }, + { label: '生命信号', key: 'heartbeat' }, + { label: '列车所在位置坡度值', key: 'slope' }, + { label: '列车所在位置坡度走势', key: 'upslope', formatFn: upslopeFormat }, + { label: '列车当前运行方向', key: 'runningUp', formatFn: runningUpFormat }, + { + label: '实际运行阻力', + key: 'runningResistanceSum', + formatFn: resistanceFormat, + }, + { label: '空气阻力', key: 'airResistance', formatFn: resistanceFormat }, + { label: '坡道阻力', key: 'rampResistance', formatFn: resistanceFormat }, + { label: '曲线阻力', key: 'curveResistance', formatFn: resistanceFormat }, + { label: '列车运行速度', key: 'speed', formatFn: speedFormat }, + { label: '头车速传1速度值', key: 'headSensorSpeed1', formatFn: speedFormat }, + { label: '头车速传2速度值', key: 'headSensorSpeed2', formatFn: speedFormat }, + { label: '尾车速传1速度值', key: 'tailSensorSpeed1', formatFn: speedFormat }, + { label: '尾车速传2速度值', key: 'tailSensorSpeed2', formatFn: speedFormat }, + { label: '头车雷达速度值', key: 'headRadarSpeed', formatFn: speedFormat }, + { label: '尾车雷达速度值', key: 'tailRadarSpeed', formatFn: speedFormat }, +]; +function upFormat(v: boolean) { + return v ? '是' : '否'; +} +function upslopeFormat(v: boolean) { + return v ? '上坡' : '下坡'; +} +function runningUpFormat(v: boolean) { + return v ? '上行' : '下行'; +} +function resistanceFormat(v: number) { + return `${v}KN`; +} +function speedFormat(v: number) { + return `${v}km/h`; +} watch( () => lineStore.selectedGraphics, (val) => {