From 0ab950615b7e3cc560494fbdbcc39ed1e3fde6cd Mon Sep 17 00:00:00 2001 From: zhouyuejun <505127606@qq.com> Date: Mon, 12 Nov 2018 11:27:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=B0=83=E6=95=B4=20--=20=E5=8D=95=E7=8B=AC=E5=88=B0/?= =?UTF-8?q?=E7=A6=BB=E6=B8=AF=E8=88=AA=E7=8F=AD=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/pages/main/main.component.html | 50 +++-- src/app/pages/main/main.component.ts | 263 ++++++++++++++++--------- src/app/pages/main/main.module.ts | 5 +- src/app/pipes/pipes.module.ts | 9 +- src/app/pipes/screening-flight.pipe.ts | 29 +++ src/app/utils/data-formatter.ts | 9 +- 6 files changed, 250 insertions(+), 115 deletions(-) create mode 100644 src/app/pipes/screening-flight.pipe.ts diff --git a/src/app/pages/main/main.component.html b/src/app/pages/main/main.component.html index 23f853e..6dbe632 100644 --- a/src/app/pages/main/main.component.html +++ b/src/app/pages/main/main.component.html @@ -7,14 +7,14 @@ - +
- + +
@@ -63,32 +73,40 @@
- + +
-
- + +
- + +
- + +
@@ -123,15 +141,15 @@ 序号 重要提示 - {{airline_col.COL_CN}} + {{airline_col.COL_CN}} - - {{i+1}} + {{i+1}} - {{airline_col.COL_CODE|dataFormatter:airline_row}} + {{airline_row['renderFlight'][airline_col.COL_CODE]}} diff --git a/src/app/pages/main/main.component.ts b/src/app/pages/main/main.component.ts index 841fbe0..4cf33a4 100644 --- a/src/app/pages/main/main.component.ts +++ b/src/app/pages/main/main.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { ChangeDetectorRef } from '@angular/core'; import { HttpClientService } from '../../services/http-client.service'; @@ -13,11 +14,25 @@ import arriDept from '../../utils/arri-dept'; styleUrls: ['./main.component.scss'] }) export class MainComponent implements OnInit { - public airline_col_lists: Array; - public airline_row_lists: Array = []; + + constructor( + private httpCilent: HttpClientService, + private changeDetectorRef: ChangeDetectorRef + ) { } + + public raw_data: Array = []; //原始数据,即航班计划 + + public combined_data: Array = []; //组合数据,即链接航班,显示信息等组合好之后的数据 + + public render_data: Array = []; //显示数据,即需要显示的数据 + + + + public col_lists: Array; //列数据 public airline_color: Array = []; public row_state: number; + public TOP_1 = 1000000000000; public TOP_2 = 2000000000000; public TOP_3 = 3000000000000; @@ -32,36 +47,42 @@ export class MainComponent implements OnInit { public TOP_12 = 12000000000000; public TOP_13 = 13000000000000; public TOP_14 = 14000000000000; - public LEVEL_1 = 100000000000000; - public LEVEL_2 = 200000000000000; - public LEVEL_3 = 300000000000000; - public LEVEL_4 = 400000000000000; - public LEVEL_5 = 500000000000000; - public LEVEL_6 = 600000000000000; - public LEVEL_7 = 700000000000000; - public LEVEL_8 = 800000000000000; - public LEVEL_9 = 900000000000000; - public LEVEL_10 = 1000000000000000; - public LEVEL_11 = 1100000000000000; - public LEVEL_12 = 1200000000000000; - public LEVEL_13 = 1300000000000000; - public LEVEL_14 = 1400000000000000; - filterItems = { - SEARCH:'', - ALCD:'', - FLIN:'', - FLTY:'', - + public filterItems = { + SEARCH: '', //手动输入条件 + FLT_POS:'1', //过滤还是定位 + ALCD: '', //航空公司 + FLIN: '', //航线类别 + FLTY: '', //航班类别 + MVIN: '', //到达/出发 + TRML: '', //航站楼 + FHAG: '', //机坪代理 + MHAG: '', //维护代理 + PHAG: '', //旅客代理 + } + + public formatter = { + 'MVIN': { + 'A': '到达', + 'D': '出发', + 'DF': '其他' + }, + 'FLIN': { + 'D': '国内', + 'I': '国际', + 'M': '混合', + 'R': '地区', + 'DF': '其他' + }, + 'SODT': dateFormatter, + 'ESTT': dateFormatter, + 'ACTT': dateFormatter } - constructor( - private httpCilent: HttpClientService - ) { } - selectRow($event, i) { this.row_state = i; + alert(i) } getColor(col_CODE) { @@ -73,14 +94,14 @@ export class MainComponent implements OnInit { } ngOnInit() { - + this.changeDetectorRef.detach(); /* 获取显示列 */ this.httpCilent.get('/assets/mock-data/airline-col_code.json').subscribe( data => { data.sort(function (a, b) { return (a['COL_ORDER'] - b['COL_ORDER']); }) - this.airline_col_lists = data; + this.col_lists = data; } ) /* 获取航班动态信息 */ @@ -88,34 +109,93 @@ export class MainComponent implements OnInit { data => { //解析数据 data.forEach(element => { - let air_message = JSON.parse(element.value); - this.airline_row_lists.push(air_message); + this.raw_data.push(JSON.parse(element.value)); }); + let combined_linked_data = this.raw_data + // this.combined_data = this.raw_data + //查找链接航班并将其组合成一条数据 - for (let i = 0; i < this.airline_row_lists.length; i++) { - if (this.airline_row_lists[i]['MVIN'] === 'D') { - if (this.airline_row_lists[i]['TAID']) { - let index = this.airline_row_lists.findIndex(val => { return val['FLID'] === this.airline_row_lists[i]['TAID'] }); + for (let i = 0; i < combined_linked_data.length; i++) { + if (combined_linked_data[i]['MVIN'] === 'D') { + if (combined_linked_data[i]['TAID']) { + let index = combined_linked_data.findIndex(val => { return val['FLID'] === combined_linked_data[i]['TAID'] }); if (index > -1) { - this.airline_row_lists[i]['isLinked'] = true; - this.airline_row_lists[i]['linkFlight'] = this.airline_row_lists[index]; - this.airline_row_lists.splice(index, 1); + combined_linked_data[i]['isLinked'] = true; + combined_linked_data[i]['linkFlight'] = combined_linked_data[index]; + combined_linked_data.splice(index, 1); i--; } } } } - //排序 - this.airline_row_lists.forEach(element => { - element['order'] = this.sequence(element) - element['ORDER'] = '+' + element['order'] + combined_linked_data.forEach(element => { + let row_flights = {}; + let render_flight = {}; + let render_pre_flight = {}; + let render_rea_flight = {}; + if (element['MVIN'] === 'A' && !element['isLinked']) { + row_flights['preFlight'] = element; + + for (let i = 0; i < this.col_lists.length; i++) { + let key = this.col_lists[i]['COL_CODE'] + render_flight[key] = typeof (this.formatter[key]) === 'function' ? this.formatter[key](row_flights['preFlight'][key],1) : this.formatter[key] ? this.formatter[key][row_flights['preFlight'][key]] : row_flights['preFlight'][key]; + } + row_flights['renderFlight'] = render_flight; + + } else if (element['MVIN'] === 'D' && !element['isLinked']) { + row_flights['reaFlight'] = element; + for (let i = 0; i < this.col_lists.length; i++) { + let key = this.col_lists[i]['COL_CODE'] + render_flight[key] = typeof (this.formatter[key]) === 'function' ? this.formatter[key](row_flights['reaFlight'][key],1) : this.formatter[key] ? this.formatter[key][row_flights['reaFlight'][key]] : row_flights['reaFlight'][key]; + } + row_flights['renderFlight'] = render_flight; + + } else if (element['isLinked']) { + row_flights['preFlight'] = element['linkFlight']; + delete element['linkFlight']; + delete element['isLinked']; + row_flights['reaFlight'] = element; + + for (let i = 0; i < this.col_lists.length; i++) { + let key = this.col_lists[i]['COL_CODE'] + if (this.formatter.hasOwnProperty(key)) { + if (typeof (this.formatter[key]) === 'function') { + render_flight[key] = this.formatter[key](row_flights['preFlight'][key],1) + '/' + this.formatter[key](row_flights['reaFlight'][key],1); + render_pre_flight[key] = this.formatter[key](row_flights['preFlight'][key],1); + render_rea_flight[key] = this.formatter[key](row_flights['reaFlight'][key],1); + } else { + render_flight[key] = this.formatter[key][row_flights['preFlight'][key]] + '/' + this.formatter[key][row_flights['reaFlight'][key]]; + render_pre_flight[key] = this.formatter[key][row_flights['preFlight'][key]]; + render_rea_flight[key] = this.formatter[key][row_flights['reaFlight'][key]]; + } + } else { + render_flight[key] = row_flights['preFlight'][key] + '/' + row_flights['reaFlight'][key]; + render_pre_flight[key] = row_flights['preFlight'][key]; + render_rea_flight[key] = row_flights['reaFlight'][key]; + } + } + row_flights['renderFlight'] = render_flight; + row_flights['renderPreFlight'] = render_pre_flight; + row_flights['renderReaFlight'] = render_rea_flight; + } + this.combined_data.push(row_flights) }) - this.airline_row_lists.sort(function (a, b) { - return (a['order'] - b['order']); + //排序 + this.combined_data.forEach(element => { + element['ORDER'] = this.sequence(element) + // element['ORDER'] = '+' + element['order'] }) + + this.combined_data.sort(function (a, b) { + return (a['ORDER'] - b['ORDER']); + }) + + this.render_data = this.combined_data + + this.changeDetectorRef.detectChanges(); } ) } @@ -159,80 +239,77 @@ export class MainComponent implements OnInit { let dateToCompare = new Date().getTime(); if (!this.isCancled(flight) && !this.isDone(flight) && this.isDelayed(flight)) { if (this.isLinked(flight)) { - if (this.getActualDatetime(flight['linkFlight']) && !this.getActualDatetime(flight)) { - dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['linkFlight']))).getTime(); + if (this.getActualDatetime(flight['preFlight']) && !this.getActualDatetime(flight['reaFlight'])) { + dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['preFlight']))).getTime(); dateTag = this.TOP_1; } else { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['reaFlight']))).getTime(); dateTag = this.TOP_2; } } else { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['reaFlight']))).getTime(); dateTag = this.TOP_3; } return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isBoading(flight)) { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['reaFlight']))).getTime(); dateTag = this.TOP_4; return dateToCompare + dateTag; } - if (!this.isCancled(flight) && !this.isDone(flight) && this.isFlying(flight)) { - if (this.isArriFlight(flight)) { - if (this.getEstimatedDatetime(flight)) { - dateToCompare = new Date(dateFormatter(this.getEstimatedDatetime(flight))).getTime(); - } else { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); - } - } else if (this.isLinked(flight)) { - if (this.getEstimatedDatetime(flight['linkFlight'])) { - dateToCompare = new Date(dateFormatter(this.getEstimatedDatetime(flight['linkFlight']))).getTime(); - } else { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['linkFlight']))).getTime(); - } + if (!this.isCancled(flight) && !this.isDone(flight) && this.isFlying(flight) && !this.getActualDatetime(flight['preFlight'])) { + if (this.getEstimatedDatetime(flight['preFlight'])) { + dateToCompare = new Date(dateFormatter(this.getEstimatedDatetime(flight['preFlight']))).getTime(); + } else { + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['preFlight']))).getTime(); } dateTag = this.TOP_5; return dateToCompare + dateTag; } - if (!this.isCancled(flight) && !this.isDone(flight) && this.isLinked(flight) && this.getActualDatetime(flight['linkFlight']) && !this.getActualDatetime(flight)) { - dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['linkFlight']))).getTime(); + if (!this.isCancled(flight) && !this.isDone(flight) && this.isLinked(flight) && this.getActualDatetime(flight['preFlight']) && !this.getActualDatetime(flight['reaFlight'])) { + dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['preFlight']))).getTime(); dateTag = this.TOP_6; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isDeptFlight(flight) && !this.startBoading(flight)) { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['reaFlight']))).getTime(); dateTag = this.TOP_7; return dateToCompare + dateTag; } if (!this.isCancled(flight) && this.isArriFlight(flight) && this.isDone(flight)) { - dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['preFlight']))).getTime(); dateTag = this.TOP_8; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && this.isOverBoading(flight)) { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['reaFlight']))).getTime(); dateTag = this.TOP_9; return dateToCompare + dateTag; } if (!this.isCancled(flight) && !this.isDone(flight) && !this.isFlying(flight)) { if (this.isLinked(flight)) { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['reaFlight']))).getTime(); dateTag = this.TOP_10; } else if (this.isArriFlight(flight)) { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['preFlight']))).getTime(); dateTag = this.TOP_11; } return dateToCompare + dateTag; } if (!this.isCancled(flight) && this.isDone(flight) && (this.isLinked(flight) || this.isDeptFlight(flight))) { - dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight))).getTime(); + dateToCompare = new Date(dateFormatter(this.getActualDatetime(flight['reaFlight']))).getTime(); dateTag = this.TOP_12; return dateToCompare + dateTag; } if (this.isCancled(flight)) { - dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight))).getTime(); + if (this.isDeptFlight(flight)) { + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['reaFlight']))).getTime(); + } else { + dateToCompare = new Date(dateFormatter(this.getScheduledDatetime(flight['preFlight']))).getTime(); + } + dateTag = this.TOP_13; return dateToCompare + dateTag; } @@ -273,7 +350,7 @@ export class MainComponent implements OnInit { * @return */ public isLinked(flight) { - if (flight.isLinked) { + if (flight['preFlight'] && flight['reaFlight']) { return true } else { return false @@ -286,7 +363,7 @@ export class MainComponent implements OnInit { * @return */ public isDeptFlight(flight) { - if (flight.MVIN === 'D' && !flight.isLinked) { + if (!flight['preFlight'] && flight['reaFlight']) { return true } else { return false @@ -300,7 +377,7 @@ export class MainComponent implements OnInit { * @return */ public isArriFlight(flight) { - if (flight.MVIN === 'A' && !flight.isLinked) { + if (flight['preFlight'] && !flight['reaFlight']) { return true; } else { return false; @@ -313,17 +390,11 @@ export class MainComponent implements OnInit { * @return */ public isFlying(flight) { - if (this.isArriFlight(flight)) { - if (flight['PADT']) { - return true + if (this.isArriFlight(flight) || this.isLinked(flight)) { + if (flight['preFlight']['PADT']) { + return true; } else { - return false - } - } else if (this.isLinked(flight)) { - if (flight['linkFlight']['PADT']) { - return true - } else { - return false + return false; } } else { return false; @@ -337,14 +408,20 @@ export class MainComponent implements OnInit { * @return */ public isCancled(flight) { - if (this.isArriFlight(flight) || this.isDeptFlight(flight)) { - if (flight['CNCL']) { - return true + if (this.isArriFlight(flight)) { + if (flight['preFlight']['CNCL']) { + return true; } else { - return false + return false; + } + } else if (this.isDeptFlight(flight)) { + if (flight['reaFlight']['CNCL']) { + return true; + } else { + return false; } } else { - return false + return false; } } @@ -355,7 +432,7 @@ export class MainComponent implements OnInit { */ public isDelayed(flight) { if (this.isDeptFlight(flight) || this.isLinked(flight)) { - if (flight['DELY']) { + if (flight['reaFlight']['DELY']) { return true } else { return false @@ -372,13 +449,13 @@ export class MainComponent implements OnInit { */ public isDone(flight) { if (this.isLinked(flight) || this.isDeptFlight(flight)) { - if (!this.getActualDatetime(flight)) { + if (!this.getActualDatetime(flight['reaFlight'])) { return false; } else { return true; } } else if (this.isArriFlight(flight)) { - if (!this.getActualDatetime(flight)) { + if (!this.getActualDatetime(flight['preFlight'])) { return false; } else { return true; @@ -395,7 +472,7 @@ export class MainComponent implements OnInit { */ public startBoading(flight) { if (this.isLinked(flight) || this.isDeptFlight(flight)) { - if (!flight['BOTM']) { + if (!flight['reaFlight']['BOTM']) { return false; } else { return true; @@ -413,7 +490,7 @@ export class MainComponent implements OnInit { */ public isBoading(flight) { if (this.isLinked(flight) || this.isDeptFlight(flight)) { - if (flight['BOTM'] && !flight['GCTM']) { + if (flight['reaFlight']['BOTM'] && !flight['reaFlight']['GCTM']) { return true; } else { return false; diff --git a/src/app/pages/main/main.module.ts b/src/app/pages/main/main.module.ts index c1af7d9..2a15960 100644 --- a/src/app/pages/main/main.module.ts +++ b/src/app/pages/main/main.module.ts @@ -1,12 +1,15 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import {PipesModule} from '../../pipes/pipes.module'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { PipesModule } from '../../pipes/pipes.module'; import { MainComponent } from './main.component'; import { MainRoutingModule } from './main-routing.module' @NgModule({ imports: [ CommonModule, + FormsModule, + ReactiveFormsModule, PipesModule, MainRoutingModule ], diff --git a/src/app/pipes/pipes.module.ts b/src/app/pipes/pipes.module.ts index 5dd348b..4c7b251 100644 --- a/src/app/pipes/pipes.module.ts +++ b/src/app/pipes/pipes.module.ts @@ -1,13 +1,16 @@ import { NgModule } from '@angular/core'; -import { DataFormatterPipe } from './data-formatter.pipe' +import { DataFormatterPipe } from './data-formatter.pipe'; +import { ScreeningFlightPipe } from './screening-flight.pipe'; @NgModule({ imports: [], declarations: [ - DataFormatterPipe + DataFormatterPipe, + ScreeningFlightPipe ], exports: [ - DataFormatterPipe + DataFormatterPipe, + ScreeningFlightPipe ] }) diff --git a/src/app/pipes/screening-flight.pipe.ts b/src/app/pipes/screening-flight.pipe.ts new file mode 100644 index 0000000..fde6088 --- /dev/null +++ b/src/app/pipes/screening-flight.pipe.ts @@ -0,0 +1,29 @@ +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name:'screeningFlight' +}) + +export class ScreeningFlightPipe implements PipeTransform{ + transform(items:Array,args:any){ + console.log(args) + var searchCtrl = ( data: any ) => { + var all = false; + if ( typeof data === 'object' ) { + for ( var z in data ) { + if ( all = searchCtrl( data[z] ) ) { + break; + }; + }; + } else { + if ( typeof data === 'number' ) { + all = data === args; + } else { + all = data.toString().match( new RegExp( args, 'i' ) ); + }; + }; + return all; + }; + return items.filter(searchCtrl); + } +} \ No newline at end of file diff --git a/src/app/utils/data-formatter.ts b/src/app/utils/data-formatter.ts index 340a6d1..6d79901 100644 --- a/src/app/utils/data-formatter.ts +++ b/src/app/utils/data-formatter.ts @@ -5,7 +5,7 @@ -export default function (dataString) { +export default function (dataString,type?) { const monthToNumber = { JAN: '01', FEB: '02', @@ -36,5 +36,10 @@ export default function (dataString) { let hour = dataString.substring(7, 9); let min = dataString.substring(9, 11); - return year + '-' + month + '-' + day + ' ' + hour + ':' + min + if(type){ + return hour + ':' + min + }else{ + return year + '-' + month + '-' + day + ' ' + hour + ':' + min + } + } \ No newline at end of file