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 | 225 ++++++++++++++++++++-----------------------------------
1 files changed, 83 insertions(+), 142 deletions(-)
diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts
index 16537be..c64baca 100644
--- a/src/app/routes/reports/demo/demo.component.ts
+++ b/src/app/routes/reports/demo/demo.component.ts
@@ -5,7 +5,6 @@
import {HttpClient} from '@angular/common/http';
import {Router} from '@angular/router';
-
@Component({
selector: 'app-demo',
templateUrl: './demo.component.html',
@@ -14,32 +13,38 @@
export class DemoComponent implements OnInit {
[x: string]: any;
- query: any = {
- };
- time: any = {
- format: 'YYYY',
- mode: 'month'
- };
-
+ 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}
+ ];
+ public reportOptions = [
+ {value: 'bar', label: '���������'},
+ {value: 'line', label: '���������'}
+ ];
public monitorPointOptions = [];
- public deviceOptions = [];
- public monitorPointbOptions = [];
- public devicebOptions = [];
+ public items = [{
+ id: 0,
+ monitorPoint: null,
+ 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.query.time = null;
- this.query.timeb = null;
this.http.get(environment.SERVER_BASH_URL + 'sensor/all').subscribe((res: any) => {
if (res.code === 0) {
this.msgSrv.error(res.message);
@@ -49,7 +54,18 @@
});
}
- searchChange(searchText) {
+ 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,
+ device: null,
+ time: null,
+ deviceOptions: []
+ });
+ }
+
+ searchChange(searchText, i) {
if (searchText) {
const query = encodeURI(searchText);
if (query) {
@@ -64,145 +80,70 @@
}
}
- monitorPointChange(value) {
- this.query.mac = null;
- this.deviceOptions = [];
+ monitorPointChange(value, i) {
+ this.items[i].deviceOptions = [];
+ this.items[i].device = null;
if (value) {
- this.monitorPointOptions.forEach(monitorPoint => {
- if (monitorPoint.id === value) {
- this.monitorPointa = monitorPoint;
- }
- });
- 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.deviceOptions = res.data;
- }
- });
- } else {
- this.monitorPointa = null;
- }
- }
-
- searchChangeb(searchText) {
- if (searchText) {
- const query = encodeURI(searchText);
- if (query) {
- this.http.get(environment.SERVER_BASH_URL + '/monitor-point/list/' + query).subscribe((res: any) => {
- if (res.code === 0) {
- this.msgSrv.error(res.message);
- } else {
- this.monitorPointbOptions = res.data;
- }
- });
- }
- }
- }
-
- devicebChange(value) {
- if (value) {
- this.devicebOptions.forEach(device => {
- if (device.mac === value) {
- this.deviceb = device;
- }
- });
- } else {
- this.deviceb = null;
- }
- }
-
- deviceChange(value) {
- this.devicea = null;
- if (value) {
- this.deviceOptions.forEach(device => {
- if (device.mac === value) {
- this.devicea = device;
- }
- });
- } else {
- this.devicea = null;
- }
- }
-
- monitorPointbChange(searchText) {
- this.query.macb = null;
- this.devicebOptions = [];
- if (searchText) {
- this.monitorPointbOptions.forEach(monitorPoint => {
- if (monitorPoint.id === searchText) {
- this.monitorPointb = monitorPoint;
- }
- });
- this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: searchText}}).subscribe((res: any) => {
- if (res.code === 0) {
- this.msgSrv.error(res.message);
- } else {
- this.devicebOptions = res.data;
+ this.items[i].deviceOptions = res.data;
}
});
}
}
- private typeOptions = [
- {value: 'year', label: '���', mode: 'month', xAxisName: '���', format: 'yyyy', typeFormat: '%Y-%m'},
- {value: 'month', label: '���', mode: 'month', xAxisName: '���', format: 'yyyy-MM', typeFormat: '%Y-%m-%d'},
- {value: 'day', label: '���', mode: 'day', xAxisName: '���', format: 'yyyy-MM-dd', typeFormat: '%Y-%m-%d %H'},
- {value: 'hour', label: '���', mode: 'day', xAxisName: '���', format: 'yyyy-MM-dd HH', typeFormat: '%Y-%m-%d %H:%i'}
- ];
-
-
- typeChange(searchText) {
- this.typeOptions.forEach(types => {
- if (types.value === searchText) {
- this.timeType = types;
- this.time.format = types.format.toUpperCase();
- this.time.mode = types.mode;
- }
- });
+ _disabledDate(current: Date): boolean {
+ return current && current.getTime() > Date.now();
}
reportQuery() {
const query = this.query;
- if (query.sensorKey && query.type && ((query.monitorPoint && query.time) || (query.monitorPointb && query.timeb))) {
- if (query.time) {
- query.time = this.dateSrv.date_format(query.time, this.time.format);
+ let validate = true;
+ const queryItems = [];
+ for (let i = 0; i < this.items.length; i++) {
+ let item = this.items[i];
+ let queryItem: any = {};
+ if (item.monitorPoint && item.time) {
+ 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 {
+ validate = false;
+ break;
}
- if (query.timeb) {
- query.timeb = this.dateSrv.date_format(query.timeb, this.time.format);
- }
- query.format = this.timeType.format;
- query.typeFormat = this.timeType.typeFormat;
- query.xAxisName = this.timeType.xAxisName;
- query.label = this.timeType.label;
- query.sensorName = this.sensor.name;
- query.sensorUnit = this.sensor.unit;
- if (this.devicea) {
- query.deviceaName = this.devicea.name;
- }
- if (this.deviceb) {
- query.devicebName = this.deviceb.name;
- }
- if (this.monitorPointa) {
- query.monitorPointaName = this.monitorPointa.name;
- }
- if (this.monitorPointb) {
- query.monitorPointbName = this.monitorPointb.name;
- }
- this.router.navigate(['report'], {queryParams: query});
-
- } else {
- this.msgSrv.error('������������������');
}
-
- }
-
- sensorChange(value) {
- this.sensorOptions.forEach(sensor => {
- if (sensor.sensorKey === value) {
- this.sensor = sensor;
+ if (validate && this.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);
}
- });
+ query.items = JSON.stringify(queryItems);
+ query.timeType = JSON.stringify(this.timeType);
+ this.router.navigate(['report'], {queryParams: query});
+ } else {
+ this.msgSrv.error('���������������������������������������');
+ }
}
-
}
--
Gitblit v1.8.0