From 43f2601b8a5706a029f333204f7f52f153d61dfe Mon Sep 17 00:00:00 2001
From: fengxiang <110431245@qq.com>
Date: Thu, 08 Mar 2018 09:22:20 +0800
Subject: [PATCH] Merge branch 'develop' of http://blit.7drlb.com:8888/r/screen-frontend into develop

---
 src/app/routes/report/report.component.html     |    6 
 src/app/routes/report/report.component.ts       |  122 ++++++++---------
 src/app/routes/reports/demo/demo.component.ts   |  149 +++++++--------------
 src/app/routes/routes-routing.module.ts         |    3 
 src/assets/app-data.json                        |   27 ---
 src/app/routes/reports/demo/demo.component.html |   72 +++------
 6 files changed, 141 insertions(+), 238 deletions(-)

diff --git a/src/app/routes/report/report.component.html b/src/app/routes/report/report.component.html
index 8890aed..c779396 100644
--- a/src/app/routes/report/report.component.html
+++ b/src/app/routes/report/report.component.html
@@ -1,3 +1,5 @@
-<!-- <input type='button' value='������' class='notprint' onclick='javascript:window.print();' /> -->
 
-<div id ="mydiv" style="height: 300px; width: 100%"></div>
+<div *ngFor="let i of sensorArr">
+	<div id ="mydiv{{i}}" style="height: 486px; width: 1000px"></div>
+</div>
+
diff --git a/src/app/routes/report/report.component.ts b/src/app/routes/report/report.component.ts
index c74c6b9..f898999 100644
--- a/src/app/routes/report/report.component.ts
+++ b/src/app/routes/report/report.component.ts
@@ -4,6 +4,7 @@
 import {HttpClient} from '@angular/common/http';
 import {ActivatedRoute} from '@angular/router';
 import * as echarts from 'echarts';
+import * as $ from 'jquery';
 
 @Component({
   selector: 'app-report',
@@ -11,22 +12,23 @@
   styles: []
 })
 export class ReportComponent implements OnInit {
-
-  public data: any;
-
-  public isShow = true;
+  [x: string]: any;
 
   constructor(
-    injector: Injector,
+    public injector: Injector,
     public http: HttpClient,
     public activeRoute: ActivatedRoute,
     public msgSrv: NzMessageService
-  ) { }
+  ) {
+    for (let index = 0; index < 30; index++) {
+      this.sensorArr.push(index);
+    }
+  }
 
   public echartOption = {
     title: {
       text: '',
-      subtext: '12������',
+      // subtext: '12������',
       left: 'center'
     },
     tooltip: {
@@ -34,10 +36,13 @@
     },
     legend: {
       data: [],
-      left: 'left'
+      orient: 'vertical',
+      right: 40,
+      top: 5,
+      bottom: 20
     },
     toolbox: {
-      show: true,
+      show: false,
       feature: {
         dataZoom: {
           yAxisIndex: 'none'
@@ -60,79 +65,66 @@
 
     },
     series: [
-      {
-        smooth: false,
-        type: 'line',
-        data: [],
-        name: ''
-      },
-      {
-        smooth: true,
-        type: 'line',
-        data: [],
-        name: '',
-        itemStyle: {
-          normal: {
-            barBorderRadius: [10, 10, 10, 10]
-          }
-        }
-      }
+      //      {
+      //        smooth: true,
+      //        type: 'line',
+      //        data: [],
+      //        name: '',
+      //        itemStyle: {
+      //          normal: {
+      //            barBorderRadius: [10, 10, 10, 10]
+      //          }
+      //        }
+      //      }
     ]
   };
 
+  sensorArr: any = [];
+  
   ngOnInit() {
     this.activeRoute.queryParams.subscribe(params => {
+      const items = JSON.parse(params.items);
       const query = params;
       this.http.get(environment.SERVER_BASH_URL + 'report/compare', {params: query}).subscribe((res: any) => {
         if (res.code === 0) {
           this.msgSrv.error(res.message);
         } else {
           const option = this.echartOption;
-          const data = res.data;
-          if (data['time']) {
-            option.xAxis.data = data['time'];
-            option.title.text = query.sensorName + query.label + '������������';
-            option.series[0].data = [];
-            option.legend.data[0] = '';
-            option.series[0].name = '';
-            option.series[1].data = [];
-            option.legend.data[1] = '';
-            option.series[1].name = '';
-            if (data.dataA) {
-              const legendNamea = (query.deviceaName ? query.deviceaName : query.monitorPointaName) + query.time + query.label;
-              option.series[0].data = data.dataA;
-              option.legend.data[0] = legendNamea;
-              option.series[0].name = legendNamea;
+          const datas = res.data.datas;
+          const times = res.data.times
+          const sensors = res.data.sensors
+          option.xAxis.data = times;
+          option.xAxis.name = query.xAxisName;
+          for (let index = 0; index < sensors.length; index++) {
+            let sensorKey = sensors[index];
+            let split = sensorKey.split('-');
+            option.title.text = split[1] + query.label + '������������';
+            option.yAxis.name = split[2] && split[2] != 'null' ? split[2] : '';
+            option.series = [];
+            option.legend.data = [];
+
+            for (let i = 0; i < items.length; i++) {
+              const legendName = items[i].formatTime + query.label + (items[i].mac ? items[i].deviceName : items[i].monitorPointName);
+              option.legend.data[i] = legendName;
+              const seriesData = datas[i]['data' + i][0][sensorKey];
+              option.series.push({
+                data: seriesData,
+                smooth: true,
+                type: 'line',
+                name: legendName
+              });
             }
-            if (data.dataB) {
-              const legendNameb = (query.devicebName ? query.devicebName : params.monitorPointbName) + query.timeb + query.label;
-              option.series[1].data = data['dataB'];
-              option.legend.data[1] = legendNameb;
-              option.series[1].name = legendNameb;
-            }
-            option.yAxis.name = query.sensorUnit;
-            option.xAxis.name = query.xAxisName;
-            const myChart = echarts.init(document.getElementById('mydiv'));
+            const myChart = echarts.init(document.getElementById('mydiv' + index));
             myChart.setOption(option, true);
             window.onresize = myChart.resize;
           }
-          this.isShow = true;
+          this.sensorArr.forEach(i => {
+            if (i >= sensors.length) {
+              $('#mydiv' + i).remove();
+            }
+          });
         }
-
       });
     });
-
-  }
-
-  doPrint() {
-    this.isShow = false;
-    window.print();
-  }
-  printBtnBoolean = true;
-  printComplete() {
-    this.printBtnBoolean = true;
-  }
-  beforePrint() {
-    this.printBtnBoolean = false;
   }
 }
diff --git a/src/app/routes/reports/demo/demo.component.html b/src/app/routes/reports/demo/demo.component.html
index 2062384..ed8b01c 100644
--- a/src/app/routes/reports/demo/demo.component.html
+++ b/src/app/routes/reports/demo/demo.component.html
@@ -5,10 +5,10 @@
 			<div nz-col [nzSpan]="6" class="mb-md">
 				<div nz-form-item class="d-flex">
 					<div nz-form-label>
-						<label nz-form-item-required>���&nbsp;���</label>
+						<label>&nbsp;&nbsp;&nbsp;���&nbsp;&nbsp;&nbsp;&nbsp;���</label>
 					</div>
 					<div nz-form-control class="flex-1">
-						<nz-select [(ngModel)]="query.sensorKey" name="sensorKey" [nzSize]="'large'" [nzPlaceHolder]="'���������'" (ngModelChange)="sensorChange($event)" nzAllowClear>
+						<nz-select [(ngModel)]="query.sensorKey" name="sensorKey" [nzSize]="'large'" [nzPlaceHolder]="'���������'" nzAllowClear>
 							<nz-option *ngFor="let option of sensorOptions" [nzLabel]="option.name" [nzValue]="option.sensorKey" ></nz-option>
             			</nz-select>
 					</div>
@@ -20,23 +20,31 @@
 						<label nz-form-item-required>������</label>
 					</div>
 					<div nz-form-control class="flex-1">
-						<nz-select [(ngModel)]="query.type" name="isDelete" [nzSize]="'large'" [nzPlaceHolder]="'���������'" (ngModelChange)="typeChange($event)">
+						<nz-select [(ngModel)]="query.type" name="type" [nzSize]="'large'" [nzPlaceHolder]="'���������'" (ngModelChange)="typeChange($event)">
 							<nz-option *ngFor="let option of typeOptions" [nzLabel]="option.label" [nzValue]="option.value" ></nz-option>
             			</nz-select>
 					</div>
 				</div>
 			</div>
+			<div nz-col [nzSpan]="6" class="mb-md" *ngIf="items.length!=5">
+				<button nz-button type="button" [nzType]="'primary'" [nzSize]="'large'" (click)="addItem()">
+					<!-- <i class="anticon anticon-plus"></i> -->
+					<i class="anticon anticon-plus-circle-o"></i>
+					<span>������������������</span>
+				</button>
+			</div>
+			
 		</div>
 
-		<div nz-row [nzGutter]="24">
+		<div nz-row [nzGutter]="24" *ngFor="let item of items;let i = index">
 			<div nz-col [nzSpan]="6" class="mb-md">
 				<div nz-form-item class="d-flex">
 					<div nz-form-label>
-						<label >���������</label>
+						<label nz-form-item-required>���������</label>
 					</div>
 					<div nz-form-control class="flex-1">
-						<nz-select [(ngModel)]="query.monitorPoint" name="monitorPoint" nzAllowClear [nzPlaceHolder]="'���������'" [nzFilter]="false" [nzSize]="'large'"  
-							(nzSearchChange)="searchChange($event)" [nzNotFoundContent]="'������������'" (ngModelChange)="monitorPointChange($event)" nzShowSearch> 
+						<nz-select [(ngModel)]="item.monitorPoint" name="monitorPoint{{item.id}}" nzAllowClear [nzPlaceHolder]="'���������'" [nzFilter]="false" [nzSize]="'large'"  
+							(nzSearchChange)="searchChange($event,i)" [nzNotFoundContent]="'������������'" (ngModelChange)="monitorPointChange($event,i)" nzShowSearch> 
 							<nz-option *ngFor="let option of monitorPointOptions"  [nzLabel]="option['name']" [nzValue]="option['id']"> </nz-option> 
 						</nz-select>
 					</div>
@@ -48,7 +56,7 @@
 						<label>&nbsp;&nbsp;������</label>
 					</div>
 					<div nz-form-control class="flex-1">
-						<nz-select [(ngModel)]="query.mac" name="mac" [nzSize]="'large'" nzAllowClear [nzPlaceHolder]="'���������'" (ngModelChange)="deviceChange($event)">
+						<nz-select [(ngModel)]="item.mac" name="mac{{item.id}}" [nzSize]="'large'" nzAllowClear [nzPlaceHolder]="'���������'" (ngModelChange)="deviceChange($event,i)">
 							<nz-option *ngFor="let option of deviceOptions" [nzLabel]="option.name" [nzValue]="option.mac" ></nz-option>
             			</nz-select>
 					</div>
@@ -57,53 +65,21 @@
 			<div nz-col [nzSpan]="6" class="mb-md">
 				<div nz-form-item class="d-flex">
 					<div nz-form-label>
-						<label >������</label>
+						<label nz-form-item-required>������</label>
 					</div>
 					<div nz-form-control class="flex-1">
-						<nz-datepicker style="width: 100%;" [(ngModel)]="query.time" name="time" [nzPlaceHolder]="'���������'" [nzFormat]="time.format" [nzMode]="time.mode" [nzSize]="'large'" nzShowTime></nz-datepicker>
+						<nz-datepicker style="width: 100%;" value="" [(ngModel)]="item.time" name="time{{item.id}}" id="{{item.time}}" [nzPlaceHolder]="'���������'" [nzFormat]="time.format" [nzMode]="time.mode" [nzSize]="'large'" nzShowTime></nz-datepicker>
 					</div>
 				</div>
+			</div>
+			<div nz-col [nzSpan]="6" class="mb-md" *ngIf="items.length!=1">
+				<button nz-button type="button" [nzType]="'danger'" [nzSize]="'large'" (click)="items.splice(i, 1)" nzGhost>
+					<i class="anticon anticon-minus-circle-o dynamic-delete-button"></i>
+					<span>������������������</span>
+				</button>
 			</div>
 		</div>
 
-		<div nz-row [nzGutter]="24">
-			<div nz-col [nzSpan]="6" class="mb-md">
-				<div nz-form-item class="d-flex">
-					<div nz-form-label>
-						<label >���������</label>
-					</div>
-					<div nz-form-control class="flex-1">
-						<nz-select [(ngModel)]="query.monitorPointb" name="monitorPointb" nzAllowClear [nzPlaceHolder]="'���������'" [nzFilter]="false" [nzSize]="'large'"  
-							(nzSearchChange)="searchChangeb($event)" [nzNotFoundContent]="'������������'" (ngModelChange)="monitorPointbChange($event)" nzShowSearch> 
-							<nz-option *ngFor="let option of monitorPointbOptions"  [nzLabel]="option['name']" [nzValue]="option['id']"> </nz-option> 
-						</nz-select>
-					</div>
-				</div>
-			</div>
-			<div nz-col [nzSpan]="6" class="mb-md">
-				<div nz-form-item class="d-flex">
-					<div nz-form-label>
-						<label>&nbsp;&nbsp;������</label>
-					</div>
-					<div nz-form-control class="flex-1">
-						<nz-select [(ngModel)]="query.macb" name="macb" [nzSize]="'large'" nzAllowClear [nzPlaceHolder]="'���������'" (ngModelChange)="devicebChange($event)">
-							<nz-option *ngFor="let option of devicebOptions" [nzLabel]="option.name" [nzValue]="option.mac" ></nz-option>
-							
-            			</nz-select>
-					</div>
-				</div>
-			</div>
-			<div nz-col [nzSpan]="6" class="mb-md">
-				<div nz-form-item class="d-flex">
-					<div nz-form-label>
-						<label >������</label>
-					</div>
-					<div nz-form-control class="flex-1">
-						<nz-datepicker style="width: 100%;" [(ngModel)]="query.timeb" name="timeb" [nzPlaceHolder]="'���������'" [nzFormat]="time.format" [nzMode]="time.mode" [nzSize]="'large'" nzShowTime></nz-datepicker>
-					</div>
-				</div>
-			</div>
-		</div>
 		<div nz-row [nzGutter]="24">
 			<div nz-col [nzSpan]="6" class="mb-md">
 				<button nz-button type="submit" [nzType]="'primary'" [nzSize]="'large'">������</button>
diff --git a/src/app/routes/reports/demo/demo.component.ts b/src/app/routes/reports/demo/demo.component.ts
index f1e2c10..0e3fa7e 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',
@@ -20,26 +19,29 @@
     format: 'YYYY',
     mode: 'month'
   };
+  items = [{
+    id: 0,
+    monitorPoint: null,
+    mac: '',
+    time: null,
+    formatTime: null,
+    monitorPointName: '',
+    deviceName: ''
+  }];
 
   public sensorOptions = [];
-
   public monitorPointOptions = [];
   public deviceOptions = [];
-  public monitorPointbOptions = [];
-  public devicebOptions = [];
 
   constructor(
     public http: HttpClient,
     public dateSrv: DateService,
     public router: Router,
     public msgSrv: NzMessageService
-  ) {}
-
-
+  ) {
+  }
 
   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 +51,21 @@
     });
   }
 
-  searchChange(searchText) {
+  addItem() {
+    const id = (this.items.length > 0) ? this.items[this.items.length - 1].id + 1 : 0;
+    const index = this.items.push({
+      id,
+      monitorPoint: null,
+      mac: '',
+      time: null,
+      formatTime: null,
+      monitorPointName: '',
+      deviceName: ''
+    });
+  }
+
+
+  searchChange(searchText, i) {
     if (searchText) {
       const query = encodeURI(searchText);
       if (query) {
@@ -64,13 +80,12 @@
     }
   }
 
-  monitorPointChange(value) {
-    this.query.mac = null;
+  monitorPointChange(value, i) {
     this.deviceOptions = [];
     if (value) {
       this.monitorPointOptions.forEach(monitorPoint => {
         if (monitorPoint.id === value) {
-          this.monitorPointa = monitorPoint;
+          this.items[i].monitorPointName = monitorPoint.name;
         }
       });
       this.http.get(environment.SERVER_BASH_URL + 'device/monitorPointId', {params: {monitorPointId: value}}).subscribe((res: any) => {
@@ -81,74 +96,29 @@
         }
       });
     } else {
-      this.monitorPointa = null;
+      this.items[i].monitorPoint = null;
+      this.items[i].mac = '';
+      this.items[i].monitorPointName = '';
     }
   }
 
-  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;
+  deviceChange(value, i) {
     if (value) {
       this.deviceOptions.forEach(device => {
         if (device.mac === value) {
-          this.devicea = device;
+          this.items[i].deviceName = device.name;
         }
       });
     } 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].deviceName = '';
     }
   }
 
   public 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'}
+    {value: 'year', label: '���', mode: 'month', xAxisName: '���', format: 'yyyy', typeFormat: '%Y-%m', timeLength: 12},
+    {value: 'month', label: '���', mode: 'month', xAxisName: '���', format: 'yyyy-MM', typeFormat: '%Y-%m-%d', timeLength: 28},
+    {value: 'day', label: '���', mode: 'day', xAxisName: '���', format: 'yyyy-MM-dd', typeFormat: '%Y-%m-%d %H', timeLength: 24},
+    {value: 'hour', label: '���', mode: 'day', xAxisName: '���', format: 'yyyy-MM-dd HH', typeFormat: '%Y-%m-%d %H:%i', timeLength: 60}
   ];
 
 
@@ -164,45 +134,28 @@
 
   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;
+    for (let i = 0; i < this.items.length; i++) {
+      let item = this.items[i];
+      if (item.monitorPoint && item.time) {
+        item.formatTime = this.dateSrv.date_format(item.time, this.time.format);
+      } else {
+        validate = false;
+        break;
       }
-      if (query.timeb) {
-        query.timeb = this.dateSrv.date_format(query.timeb, this.time.format);
-      }
+    }
+    if (validate && query.type) {
       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;
-      }
+      query.timeLength = this.timeType.timeLength;
+      query.items = JSON.stringify(this.items);
       this.router.navigate(['report'], {queryParams: query});
-
     } else {
-      this.msgSrv.error('������������������');
+      this.msgSrv.error('���������������������������������������');
     }
 
-  }
-
-  sensorChange(value) {
-    this.sensorOptions.forEach(sensor => {
-      if (sensor.sensorKey === value) {
-        this.sensor = sensor;
-      }
-    });
   }
 
 }
diff --git a/src/app/routes/routes-routing.module.ts b/src/app/routes/routes-routing.module.ts
index 44cc309..367fd3a 100644
--- a/src/app/routes/routes-routing.module.ts
+++ b/src/app/routes/routes-routing.module.ts
@@ -43,7 +43,8 @@
     },    // passport
     {
       path: 'report',
-      component: ReportComponent
+      component: ReportComponent,
+      data:{title:'������������'}
     },
     { path: '**', redirectTo: 'passport/login' }
 ];
diff --git a/src/assets/app-data.json b/src/assets/app-data.json
index 420b56d..76b2b22 100644
--- a/src/assets/app-data.json
+++ b/src/assets/app-data.json
@@ -13,31 +13,10 @@
             "translate": "main_navigation",
             "group": true,
             "children": [{
-                "text": "���������",
-                "link": "/dashboard",
+                "text": "���������",
+                "link": "/dashboard/workplace",
                 "icon": "icon-speedometer",
-                "children": [{
-                    "text": "���������V1",
-                    "link": "/dashboard/v1",
-                    "translate": "dashboard_v1"
-                }, {
-                    "text": "���������",
-                    "link": "/dashboard/analysis"
-                }, {
-                    "text": "Monitor",
-                    "link": "/dashboard/monitor",
-                    "translate": "dashboard_monitor"
-                }, {
-                    "text": "Workplace",
-                    "link": "/dashboard/workplace",
-                    "translate": "dashboard_workplace"
-                }]
-            }, {
-                "text": "������������",
-                "translate": "shortcut",
-                "icon": "icon-rocket",
-                "shortcut_root": true,
-                "children": []
+                "translate": "dashboard_workplace"
             }]
         }, {
             "text": "������������",

--
Gitblit v1.8.0