动态消息处理转为webWorker处理
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Component, OnInit, ViewChild, Renderer2 } from '@angular/core';
|
||||
import { NavigationEnd, Router } from '@angular/router';
|
||||
import { WebWorkerService } from 'ngx-web-worker';
|
||||
|
||||
import { ToastService } from '../../components/toast/toast.service';
|
||||
import { ToastConfig, ToastType } from '../../components/toast/toast-model';
|
||||
@@ -15,6 +16,7 @@ import { CellColorHandle } from '../../utils/cell-color-handle';
|
||||
import { AlertMessageHandle } from '../../utils/alert-message-handle';
|
||||
|
||||
import dateFormatter from '../../utils/date-formatter';
|
||||
import webWorkerHandle from '../../utils/web-worker-handle';
|
||||
|
||||
import { filter } from 'rxjs/operators';
|
||||
import * as $ from 'jquery';
|
||||
@@ -22,12 +24,14 @@ import * as $ from 'jquery';
|
||||
@Component({
|
||||
selector: 'app-main',
|
||||
templateUrl: './main.component.html',
|
||||
styleUrls: ['./main.component.scss']
|
||||
styleUrls: ['./main.component.scss'],
|
||||
providers: [WebWorkerService]
|
||||
})
|
||||
export class MainComponent implements OnInit {
|
||||
constructor(
|
||||
private router: Router,
|
||||
private renderer2: Renderer2,
|
||||
private webWorkerService: WebWorkerService,
|
||||
private basicDataService: BasicDataService,
|
||||
private operateSpinServiceService: OperateSpinServiceService,
|
||||
private httpCilent: HttpClientService,
|
||||
@@ -141,6 +145,7 @@ export class MainComponent implements OnInit {
|
||||
console.log(message);
|
||||
//是否可以开始处理动态消息
|
||||
if (this.canHandleDynamicMessage) {
|
||||
// this.webWorkerService.terminate(promise);
|
||||
this.dynamicMessageHandle(message);
|
||||
} else {
|
||||
this.dynamicMessageArray.push(message);
|
||||
@@ -418,46 +423,35 @@ export class MainComponent implements OnInit {
|
||||
* 动态消息处理方法
|
||||
* @param message
|
||||
*/
|
||||
startposi: number
|
||||
dynamicMessageHandle(message) {
|
||||
this.startposi = new Date().getTime();
|
||||
let index = this.raw_data.findIndex(element => element['FLID'] === message.FLID);
|
||||
if (index > -1) {
|
||||
this.raw_data[index] = message;
|
||||
} else {
|
||||
this.raw_data.push(message);
|
||||
}
|
||||
console.log(new Date().getTime() - this.startposi + '消息更新替换到原始数据所花时间');
|
||||
|
||||
//查找链接航班并将其组合成一条数据
|
||||
this.startposi = new Date().getTime();
|
||||
let combined_linked_data = this.dataHandle.findLinkFlights(this.raw_data);
|
||||
console.log(new Date().getTime() - this.startposi + '找链接航班所花时间')
|
||||
let combined_data = [];
|
||||
this.combined_data = [];
|
||||
this.startposi = new Date().getTime()
|
||||
combined_linked_data.forEach(element => {
|
||||
let flights_item = this.dataHandle.flightsRenderTransfer(element, this.col_lists);
|
||||
this.combined_data.push(flights_item);
|
||||
});
|
||||
console.log(new Date().getTime() - this.startposi + '转换结束所花时间')
|
||||
this.startposi = new Date().getTime();
|
||||
this.combined_data.forEach(item => {
|
||||
combined_data.push(this.dataHandle.basicDataTransHandle(item, this.airports, this.citys, this.airlines, this.flightStatus, this.flightTypes));
|
||||
})
|
||||
console.log(new Date().getTime() - this.startposi + '基础数据转换结束所花时间');
|
||||
this.combined_data = combined_data;
|
||||
this.startposi = new Date().getTime();
|
||||
this.combined_data.forEach(element => {
|
||||
element['ORDER'] = this.orderHandle.sequence(element);
|
||||
})
|
||||
this.combined_data = this.combined_data.sort(function (a, b) {
|
||||
return (a['ORDER'] - b['ORDER']);
|
||||
})
|
||||
// let combined_linked_data = this.dataHandle.findLinkFlights(this.raw_data);
|
||||
// let combined_data = [];
|
||||
// this.combined_data = [];
|
||||
// combined_linked_data.forEach(element => {
|
||||
// let flights_item = this.dataHandle.flightsRenderTransfer(element, this.col_lists);
|
||||
// this.combined_data.push(flights_item);
|
||||
// });
|
||||
// this.combined_data.forEach(item => {
|
||||
// combined_data.push(this.dataHandle.basicDataTransHandle(item, this.airports, this.citys, this.airlines, this.flightStatus, this.flightTypes));
|
||||
// })
|
||||
// this.combined_data = combined_data;
|
||||
// this.combined_data.forEach(element => {
|
||||
// element['ORDER'] = this.orderHandle.sequence(element);
|
||||
// })
|
||||
// this.combined_data = this.combined_data.sort(function (a, b) {
|
||||
// return (a['ORDER'] - b['ORDER']);
|
||||
// })
|
||||
|
||||
console.log(new Date().getTime() - this.startposi + '排序所花时间');
|
||||
|
||||
this.selectChange('dynamic');
|
||||
// this.selectChange('dynamic');
|
||||
|
||||
if (this.airlinesSelections.findIndex(airline => airline.airlineCodeIata === message['ALCD']) === -1) {
|
||||
let index = this.airlines.findIndex(val => val.airlineCodeIata === message['ALCD']);
|
||||
@@ -469,29 +463,20 @@ export class MainComponent implements OnInit {
|
||||
this.flightTypeSelections.push(this.flightTypes[index]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// let dynamicHandleData = this.dataHandle.dynamicMessageHandle(
|
||||
// message,
|
||||
// this.render_data,
|
||||
// this.col_lists,
|
||||
// this.filterItems,
|
||||
// this.LASTSEARCH,
|
||||
// this.LAST_SEL_COL,
|
||||
// this.airports,
|
||||
// this.citys,
|
||||
// this.airlines,
|
||||
// this.flightStatus,
|
||||
// this.flightTypes
|
||||
// )
|
||||
// this.render_data = dynamicHandleData.render_data;
|
||||
|
||||
// this.render_data.forEach(element => {
|
||||
// element['ORDER'] = this.orderHandle.sequence(element);
|
||||
// })
|
||||
// this.render_data = this.render_data.sort(function (a, b) {
|
||||
// return (a['ORDER'] - b['ORDER']);
|
||||
// })
|
||||
let dynamicData = {
|
||||
raw_data: this.raw_data,
|
||||
col_lists: this.col_lists,
|
||||
airports: this.airports,
|
||||
citys: this.citys,
|
||||
airlines: this.airlines,
|
||||
flightStatus: this.flightStatus,
|
||||
flightTypes: this.flightTypes
|
||||
}
|
||||
const promise = this.webWorkerService.run(webWorkerHandle, dynamicData);
|
||||
promise.then(function (response) {
|
||||
this.combined_data = response;
|
||||
this.selectChange('dynamic');
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -575,7 +560,6 @@ export class MainComponent implements OnInit {
|
||||
* 下拉框选择筛选
|
||||
*/
|
||||
selectChange(type) {
|
||||
this.startposi = new Date().getTime()
|
||||
if (type === 'filter') {
|
||||
this.operateSpinServiceService.showSpin();
|
||||
}
|
||||
@@ -835,11 +819,8 @@ export class MainComponent implements OnInit {
|
||||
})
|
||||
}
|
||||
}
|
||||
console.log(new Date().getTime() - this.startposi + '判断是否满足过滤条件所花时间');
|
||||
this.wait_render_data = filterData;
|
||||
this.startposi = new Date().getTime();
|
||||
this.render_data = this.wait_render_data.slice(this.start, this.end);
|
||||
console.log(new Date().getTime() - this.startposi + '渲染结束所花时间');
|
||||
setTimeout(() => {
|
||||
$(".table-body tbody>tr").eq(0).find('td').each((index, element) => {
|
||||
$(".table-head table thead tr").eq(0).find('th').eq(index).attr('width', $(element).innerWidth() + 'px');
|
||||
|
||||
Reference in New Issue
Block a user