From ba15aacf079d1a3fd13e4594f5a94cf25dacb036 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Mon, 26 Mar 2018 14:25:26 +0800 Subject: [PATCH] 报表 优化 --- src/app/routes/reports/demo/demo.component.ts | 82 +++++++++++++---------------------------- 1 files changed, 26 insertions(+), 56 deletions(-) diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts index 990a166..c64baca 100644 --- a/src/app/routes/reports/demo/demo.component.ts +++ b/src/app/routes/reports/demo/demo.component.ts @@ -12,16 +12,6 @@ }) export class DemoComponent implements OnInit { - constructor( - public http: HttpClient, - public dateSrv: DateService, - public router: Router, - public msgSrv: NzMessageService - ) { - this.query.timeType = this.typeOptions[1]; - this.time.format = this.query.timeType.format.toUpperCase(); - this.query.reportType = this.reportOptions[1].value; - } [x: string]: any; public query: any = {}; public sensorOptions = []; @@ -36,17 +26,23 @@ {value: 'line', label: '���������'} ]; public monitorPointOptions = []; - public time: any = {}; public items = [{ id: 0, monitorPoint: null, - monitorPointName: '', - monitorPointAddress: '', - mac: '', - deviceName: '', + device: null, time: null, deviceOptions: [] }]; + + constructor( + public http: HttpClient, + public dateSrv: DateService, + public router: Router, + public msgSrv: NzMessageService + ) { + this.timeType = this.typeOptions[1]; + this.query.reportType = this.reportOptions[1].value; + } ngOnInit() { this.http.get(environment.SERVER_BASH_URL + 'sensor/all').subscribe((res: any) => { @@ -58,23 +54,12 @@ }); } - typeChange(searchText) { - this.typeOptions.forEach(types => { - if (types === searchText) { - this.time.format = types.format.toUpperCase(); - } - }); - } - addItem() { const id = (this.items.length > 0) ? this.items[this.items.length - 1].id + 1 : 0; const index = this.items.push({ id: id, monitorPoint: null, - monitorPointName: '', - monitorPointAddress: '', - mac: '', - deviceName: '', + device: null, time: null, deviceOptions: [] }); @@ -97,38 +82,15 @@ monitorPointChange(value, i) { this.items[i].deviceOptions = []; + this.items[i].device = null; if (value) { - this.monitorPointOptions.forEach(monitorPoint => { - if (monitorPoint.id === value) { - this.items[i].monitorPointName = monitorPoint.name; - this.items[i].monitorPointAddress = monitorPoint.address; - } - }); - this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: value}}).subscribe((res: any) => { + this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: value.id}}).subscribe((res: any) => { if (res.code === 0) { this.msgSrv.error(res.message); } else { this.items[i].deviceOptions = res.data; - this.items[i].mac = null; } }); - } else { - this.items[i].monitorPoint = null; - this.items[i].mac = null; - this.items[i].monitorPointName = ''; - this.items[i].monitorPointAddress = ''; - } - } - - deviceChange(value, i) { - if (value) { - this.items[i].deviceOptions.forEach(device => { - if (device.mac === value) { - this.items[i].deviceName = device.name; - } - }); - } else { - this.items[i].deviceName = ''; } } @@ -144,14 +106,23 @@ let item = this.items[i]; let queryItem: any = {}; if (item.monitorPoint && item.time) { - queryItem.formatTime = this.dateSrv.date_format(item.time, this.time.format); for (var key in item) { if (item[key]) { queryItem[key] = item[key]; } } + queryItem.monitorPointId = queryItem.monitorPoint.id; + queryItem.monitorPointName = queryItem.monitorPoint.name; + queryItem.monitorPointAddress = queryItem.monitorPoint.address; + delete queryItem.monitorPoint; + if (queryItem.device) { + queryItem.mac = queryItem.device.mac; + queryItem.deviceName = queryItem.device.name; + delete queryItem.device; + } queryItem.deviceCount = queryItem.deviceOptions.length; delete queryItem.deviceOptions; + queryItem.formatTime = this.dateSrv.date_format(queryItem.time, this.timeType.format.toUpperCase()); delete queryItem.time; queryItems.push(queryItem); } else { @@ -159,7 +130,7 @@ break; } } - if (validate && query.timeType && query.reportType) { + if (validate && this.timeType && query.reportType) { query.sensors = null; if (query.sensorKey && query.sensorKey.length > 0) { const sensors = []; @@ -169,11 +140,10 @@ query.sensors = JSON.stringify(sensors); } query.items = JSON.stringify(queryItems); - query.timeTypes = JSON.stringify(query.timeType); + query.timeType = JSON.stringify(this.timeType); this.router.navigate(['report'], {queryParams: query}); } else { this.msgSrv.error('���������������������������������������'); } - } } -- Gitblit v1.8.0