From 7d4045bb727ac6e86939569258cbce1bd2adda58 Mon Sep 17 00:00:00 2001 From: xufenglei <xufenglei> Date: Thu, 29 Mar 2018 14:04:46 +0800 Subject: [PATCH] 报表优化 --- src/app/routes/reports/demo/demo.component.ts | 99 ++++++++++++++++--------------------------------- 1 files changed, 32 insertions(+), 67 deletions(-) diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts index 990a166..431b3a2 100644 --- a/src/app/routes/reports/demo/demo.component.ts +++ b/src/app/routes/reports/demo/demo.component.ts @@ -12,41 +12,37 @@ }) 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 = []; public typeOptions = [ - {value: 'year', label: '���', format: 'yyyy', typeFormat: '%Y-%m', timeLength: 12}, - {value: 'month', label: '���', format: 'yyyy-MM', typeFormat: '%Y-%m-%d', timeLength: 28}, - {value: 'day', label: '���', format: 'yyyy-MM-dd', typeFormat: '%Y-%m-%d %H', timeLength: 24}, - {value: 'hour', label: '���', format: 'yyyy-MM-dd HH', typeFormat: '%Y-%m-%d %H:%i', timeLength: 60} + {value: 'year', label: '���', format: 'YYYY'}, + {value: 'month', label: '���', format: 'YYYY-MM'}, + {value: 'day', label: '���', format: 'YYYY-MM-DD'}, + {value: 'hour', label: '���', format: 'YYYY-MM-DD HH'} ]; public reportOptions = [ {value: 'bar', label: '���������'}, {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); delete queryItem.time; queryItems.push(queryItem); } else { @@ -159,21 +130,15 @@ break; } } - if (validate && query.timeType && query.reportType) { - query.sensors = null; - if (query.sensorKey && query.sensorKey.length > 0) { - const sensors = []; - query.sensorKey.forEach(sensor => { - sensors.push(sensor.sensorKey + '-' + sensor.name + '-' + sensor.unit); - }); - query.sensors = JSON.stringify(sensors); + if (validate && this.timeType && query.reportType) { + if (query.sensorKeys && query.sensorKeys.length > 0) { + query.sensors = JSON.stringify(query.sensorKeys); } query.items = JSON.stringify(queryItems); - query.timeTypes = JSON.stringify(query.timeType); + query.type = this.timeType.value; this.router.navigate(['report'], {queryParams: query}); } else { this.msgSrv.error('���������������������������������������'); } - } } -- Gitblit v1.8.0