src/app/routes/report/report.component.ts | ●●●●● patch | view | raw | blame | history | |
src/app/routes/reports/demo/demo.component.html | ●●●●● patch | view | raw | blame | history | |
src/app/routes/reports/demo/demo.component.ts | ●●●●● patch | view | raw | blame | history | |
src/app/routes/reports/excel/excel.component.html | ●●●●● patch | view | raw | blame | history | |
src/app/routes/reports/excel/excel.component.ts | ●●●●● patch | view | raw | blame | history |
src/app/routes/report/report.component.ts
@@ -105,7 +105,7 @@ } for (let i = 0; i < items.length; i++) { this.title = items[i].formatTime; const legendName = items[i].formatTime + label + (items[i].mac ? items[i].deviceName : items[i].monitorPointName); const legendName = items[i].formatTime + label + (items[i].mac ? '设备:'+items[i].deviceName : (items[i].monitorPointid?'监测点:'+items[i].monitorPointName:items[i].areaName)); option.legend.data[i] = legendName; option.series.push({ name: legendName, src/app/routes/reports/demo/demo.component.html
@@ -8,13 +8,21 @@ <label> 项 目</label> </div> <div nz-form-control class="flex-1"> <nz-select [nzMode]="'multiple'" [(ngModel)]="query.sensorKeys" name="sensorKeys" [nzSize]="'large'" [nzPlaceHolder]="'请选择'"> <!-- <nz-select [nzMode]="'multiple'" [(ngModel)]="query.sensorKeys" name="sensorKeys" [nzSize]="'large'" [nzPlaceHolder]="'请选择'"> <nz-option *ngFor="let option of sensorOptions" [nzLabel]="option.name" [nzValue]="option.sensorKey + '-' + option.name + '-' + option.unit"></nz-option> </nz-select> <!-- <input nz-input /> <div> <ul id="sensorTree" class="ztree"></ul> </div> --> </nz-select> --> <nz-popover [nzPlacement]="'bottomLeft'" [nzTrigger]="'hover'"> <nz-input [nzType]="'input'" nz-popover [ngModel]="sensorNames" name="sensorKeys" [nzReadonly]="true" [nzPlaceHolder]="'请选择 项目'"> <ng-template #suffix> <i class="anticon anticon-down ant-cascader-picker-arrow "></i> </ng-template> </nz-input> <ng-template #nzTemplate> <div [ngStyle]="{'width': '240px', 'height': '240px', 'overflow-y' :'auto'}"> <nz-tree [nzNodes]="sensorOptions" (nzActivate)="onTreeClickSelect($event)" (nzDeactivate)="onTreeClickSelect($event)" [nzCheckable]="true" (nzCheck)="onSensorSelect($event)"></nz-tree> </div> </ng-template> </nz-popover> </div> </div> </div> @@ -59,8 +67,7 @@ <label nz-form-item-required>省市区</label> </div> <div nz-form-control class="flex-1"> <nz-cascader [class.class123]="true" (nzLoad)="areaLazyLoad($event,i)" [nzPlaceHolder]="'选择 省/市/区'" (nzSelectionChange)="setAreasData($event,i)" [nzAllowClear]="false" [nzChangeOnSelect]="true" [ngModel]="item._areas" name="areasData{{item.id}}"> <nz-cascader (nzLoad)="areaLazyLoad($event,i)" [nzPlaceHolder]="'请选择 省/市/区'" [nzAllowClear]="false" [nzChangeOnSelect]="true" (nzSelect)="regionChange($event,i)"> </nz-cascader> </div> </div> @@ -72,8 +79,8 @@ <label>监测点</label> </div> <div nz-form-control class="flex-1"> <nz-select [(ngModel)]="item.monitorPoint" name="monitorPoint{{item.id}}" nzAllowClear [nzPlaceHolder]="'选择 监测点'" [nzSize]="'large'" [nzNotFoundContent]="'无法找到'" (ngModelChange)="monitorPointChange($event,i)" nzShowSearch> <nz-select [(ngModel)]="item.monitorPoint" name="monitorPoint{{item.id}}" [nzPlaceHolder]="'请选择 监测点'" [nzSize]="'large'" [nzNotFoundContent]="'无法找到'" (ngModelChange)="monitorPointChange($event,i)" nzShowSearch nzAllowClear> <nz-option *ngFor="let option of item.monitorPointOptions" [nzLabel]="option['name']" [nzValue]="option"> </nz-option> </nz-select> </div> src/app/routes/reports/demo/demo.component.ts
@@ -4,10 +4,9 @@ import {Component, OnInit} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {CascaderOption} from 'ng-zorro-antd/src/cascader/nz-cascader.component'; import {Organization} from '@business/entity/data'; import {ResultCode} from '@business/enum/types.enum'; import {ResultBean} from '@business/entity/grid'; import {AreacodeService} from '@business/services/http/areacode.service'; import {NzTreeComponent} from 'ng-tree-antd'; import {Subject} from 'rxjs/Subject'; @Component({ selector: 'app-demo', @@ -30,15 +29,21 @@ {value: 'line', label: '折线图'} ]; public items = [{ public items: any[] = [{ id: 0, monitorPoint: null, device: null, time: null, monitorPointOptions: [], deviceOptions: [], _areas: [] deviceOptions: [] }]; private treeClickStream: Subject<any> = new Subject<any>(); private _sensors: {[key: string]: string} = {}; private _sensorNames: string; get sensorNames(): string { return this._sensorNames; } constructor( public http: HttpClient, @@ -55,9 +60,52 @@ if (res.code === 0) { this.msgSrv.error(res.message); } else { this.sensorOptions = res.data; this.sensorOptions.push({id: -1, name: '全部', isExpanded: true, children: res.data}); } }); } public onTreeClickSelect(event): void { this.treeClickStream.next(event); } public onSensorSelect(event): void { const data = event.node.data; if (data.id === -1 && data.halfChecked === false) { if (!!data.checked) { this.sensorOptions[0].children.forEach( sensor => { this._sensors[sensor.id] = sensor.sensorKey + '-' + sensor.name + '-' + sensor.unit; } ); } else { this._sensors = {}; } } else { if (!!data.checked) { this._sensors[data.id] = data.sensorKey + '-' + data.name + '-' + data.unit; } else { delete this._sensors[data.id]; } } this.reloadSensorNames(); } private reloadSensorNames(): void { // 异步提升展现速度 setTimeout(() => { this._sensorNames = ''; const sensorNameList = Object.keys(this._sensors).map( id => { const sensor = this.sensorOptions[0].children.find(item => { return Number(id) === Number(item.id); }); return sensor.name; } ); this._sensorNames = sensorNameList.join(', '); }, 1); } addItem() { @@ -68,8 +116,7 @@ device: null, time: null, monitorPointOptions: [], deviceOptions: [], _areas: [] deviceOptions: [] }); } @@ -98,33 +145,34 @@ } } public setAreasData(areas: {label: string, value: string}[], i) { let isChanged = false; const _areas = this.items[i]._areas isChanged = areas.some((item, index: number) => { // this._areas[index] 为null 改变 监控点选项 return _areas.length < areas.length || !_areas[index] || _areas[index].value !== item.value; }); if (isChanged) { this.items[i]._areas = areas; this.items[i].monitorPoint = null; this.regionChange(i); } } regionChange(i) { public regionChange(event: {option: CascaderOption, index: number}, i) { let name = ''; let areaName = ''; switch (this.items[i]._areas.length) { const option = event.option; this.items[i].monitorPoint = null; this.items[i].areaCode = null; this.items[i].device = null; switch (event.index) { case 0: name = 'provinceCode'; this.items[i].provinceCode = option.value; this.items[i].cityCode = null; areaName = option.label; break; case 1: areaName = 'provinceCode'; break; name = 'cityCode'; this.items[i].cityCode = option.value; areaName = option.parent.label + '/' + option.label; break; case 2: areaName = 'cityCode'; break; case 3: areaName = 'areaCode'; break; name = 'areaCode'; this.items[i].areaCode = option.value; areaName = option.parent.parent.label + '/' + option.parent.label + '/' + option.label; break; } this.http.get(environment.SERVER_BASH_URL + 'monitor-point/list/region', {params: {name: areaName, value: this.items[i]._areas.slice(-1).pop().value}}).subscribe((res: any) => { this.items[i].areaName = areaName; this.http.get(environment.SERVER_BASH_URL + 'monitor-point/list/region', {params: {name: name, value: option.value}}).subscribe((res: any) => { if (res.code === 0) { this.msgSrv.error(res.message); } else { @@ -156,6 +204,7 @@ let validate = true; const queryItems = []; for (let i = 0; i < this.items.length; i++) { let areaName = ''; let item = this.items[i]; let queryItem: any = {}; if ((!!item.time) && (item.monitorPointOptions.length > 0)) { @@ -164,19 +213,6 @@ queryItem[key] = item[key]; } } for (let i = 0; i < queryItem._areas.length; i++) { let region = queryItem._areas[i]; if (i == 0) { queryItem.provinceCode = region.value; } if (i == 1) { queryItem.cityCode = region.value; } if (i == 2) { queryItem.areaCode = region.value; } } delete queryItem._areas; if (queryItem.monitorPoint) { queryItem.monitorPointId = queryItem.monitorPoint.id; queryItem.monitorPointName = queryItem.monitorPoint.name; @@ -189,7 +225,9 @@ queryItem.deviceName = queryItem.device.name; delete queryItem.device; } queryItem.deviceCount = queryItem.deviceOptions.length; if (queryItem.deviceOptions && queryItem.deviceOptions.length > 0) { queryItem.deviceCount = queryItem.deviceOptions.length; } delete queryItem.deviceOptions; queryItem.formatTime = this.dateSrv.date_format(queryItem.time, this.timeType.format); delete queryItem.time; @@ -200,8 +238,14 @@ } } if (validate && this.timeType && query.reportType) { if (query.sensorKeys && query.sensorKeys.length > 0) { query.sensors = JSON.stringify(query.sensorKeys); if (this._sensors) { const sensors = []; for (var key in this._sensors) { sensors.push(this._sensors[key]); } if (sensors.length > 0) { query.sensors = JSON.stringify(sensors); } } query.items = JSON.stringify(queryItems); query.type = this.timeType.value; src/app/routes/reports/excel/excel.component.html
@@ -5,23 +5,43 @@ <div nz-col [nzSpan]="6" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> <label> 项目</label> <label>项目</label> </div> <div nz-form-control class="flex-1"> <nz-select [(ngModel)]="query.sensorKeys" name="sensorKeys" [nzSize]="'large'" [nzPlaceHolder]="'请选择'" [nzMode]="'multiple'"> <nz-option *ngFor="let option of sensorOptions" [nzLabel]="option.name" [nzValue]="option.sensorKey + '-' + option.name + '-' + option.unit" ></nz-option> </nz-select> <nz-popover [nzPlacement]="'bottomLeft'" [nzTrigger]="'hover'"> <nz-input [nzType]="'input'" nz-popover [ngModel]="sensorNames" name="sensorKeys" [nzReadonly]="true" [nzPlaceHolder]="'请选择 项目'"> <ng-template #suffix> <i class="anticon anticon-down ant-cascader-picker-arrow "></i> </ng-template> </nz-input> <ng-template #nzTemplate> <div [ngStyle]="{'width': '240px', 'height': '240px', 'overflow-y' :'auto'}"> <nz-tree [nzNodes]="sensorOptions" (nzActivate)="onTreeClickSelect($event)" (nzDeactivate)="onTreeClickSelect($event)" [nzCheckable]="true" (nzCheck)="onSensorSelect($event)"></nz-tree> </div> </ng-template> </nz-popover> </div> </div> </div> <div nz-col [nzSpan]="6" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> <label nz-form-item-required>监测点</label> <label nz-form-item-required>省市区</label> </div> <div nz-form-control class="flex-1"> <nz-select [(ngModel)]="query.monitorPointId" name="monitorPoint" nzAllowClear [nzPlaceHolder]="'请输入'" [nzFilter]="false" [nzSize]="'large'" (nzSearchChange)="searchChange($event)" [nzNotFoundContent]="'无法找到'" (ngModelChange)="monitorPointChange($event)" nzShowSearch> <nz-cascader (nzLoad)="areaLazyLoad($event)" [nzPlaceHolder]="'请选择 省/市/区'" [nzAllowClear]="false" [nzChangeOnSelect]="true" (nzSelect)="regionChange($event)"> </nz-cascader> </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-select [(ngModel)]="query.monitorPointId" name="monitorPoint" [nzPlaceHolder]="'请选择 监测点'" [nzSize]="'large'" [nzNotFoundContent]="'无法找到'" (ngModelChange)="monitorPointChange($event)" nzShowSearch nzAllowClear> <nz-option *ngFor="let option of monitorPointOptions" [nzLabel]="option['name']" [nzValue]="option['id']"> </nz-option> </nz-select> </div> @@ -33,7 +53,7 @@ <label>设备</label> </div> <div nz-form-control class="flex-1"> <nz-select [(ngModel)]="query.mac" name="mac" [nzSize]="'large'" nzAllowClear [nzPlaceHolder]="'请选择'" > <nz-select [(ngModel)]="query.mac" name="mac" [nzSize]="'large'" [nzPlaceHolder]="'请选择 设备'" [nzNotFoundContent]="'无法找到'" nzShowSearch nzAllowClear> <nz-option *ngFor="let option of deviceOptions" [nzLabel]="option.name" [nzValue]="option.mac" ></nz-option> </nz-select> </div> @@ -45,7 +65,7 @@ <div nz-col [nzSpan]="6" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> <label nz-form-item-required>类型</label> <label>类型</label> </div> <div nz-form-control class="flex-1"> <nz-select [(ngModel)]="timeType" name="timeType" [nzSize]="'large'" [nzPlaceHolder]="'请选择'"> @@ -60,7 +80,7 @@ <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]="'请选择'" [nzSize]="'large'" [nzFormat]="timeType.format" <nz-datepicker style="width: 100%;" [(ngModel)]="query.time" name="time" [nzPlaceHolder]="'请选择 时间'" [nzSize]="'large'" [nzFormat]="timeType.format" [nzMode]="timeType.value=='hour'||timeType.value=='day'?'day':'month'" [nzShowTime]="timeType.value=='hour'?true:false"></nz-datepicker> </div> </div> @@ -68,10 +88,10 @@ <div nz-col [nzSpan]="6" class="mb-md"> <div nz-form-item class="d-flex"> <div nz-form-label> <label > 到</label> <label >时间至</label> </div> <div nz-form-control class="flex-1"> <nz-datepicker style="width: 100%;" [(ngModel)]="query.timeb" name="timeb" [nzPlaceHolder]="'请选择'" [nzSize]="'large'" [nzFormat]="timeType.format" <nz-datepicker style="width: 100%;" [(ngModel)]="query.timeb" name="timeb" [nzPlaceHolder]="'请选择 时间'" [nzSize]="'large'" [nzFormat]="timeType.format" [nzMode]="timeType.value=='hour'||timeType.value=='day'?'day':'month'" [nzShowTime]="timeType.value=='hour'?true:false"></nz-datepicker> </div> </div> src/app/routes/reports/excel/excel.component.ts
@@ -4,6 +4,10 @@ import {Component, OnInit, Inject} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {ITokenService, DA_SERVICE_TOKEN} from '@delon/auth'; import {CascaderOption} from 'ng-zorro-antd/src/cascader/nz-cascader.component'; import {AreacodeService} from '@business/services/http/areacode.service'; import {NzTreeComponent} from 'ng-tree-antd'; import {Subject} from 'rxjs/Subject'; @Component({ selector: 'app-excel', @@ -23,10 +27,18 @@ {value: 'hour', label: '时', format: 'YYYY-MM-DD HH'} ]; private treeClickStream: Subject<any> = new Subject<any>(); private _sensors: {[key: string]: string} = {}; private _sensorNames: string; get sensorNames(): string { return this._sensorNames; } constructor( public http: HttpClient, public dateSrv: DateService, public msgSrv: NzMessageService, private areacodeService: AreacodeService, @Inject(DA_SERVICE_TOKEN) public tokenService: ITokenService ) { this.timeType = this.typeOptions[1]; @@ -39,24 +51,106 @@ if (res.code === 0) { this.msgSrv.error(res.message); } else { this.sensorOptions = res.data; this.sensorOptions.push({id: -1, name: '全部', isExpanded: true, children: res.data}); } }); } searchChange(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.monitorPointOptions = res.data; public onTreeClickSelect(event): void { this.treeClickStream.next(event); } public onSensorSelect(event): void { const data = event.node.data; if (data.id === -1 && data.halfChecked === false) { if (!!data.checked) { this.sensorOptions[0].children.forEach( sensor => { this._sensors[sensor.id] = sensor.sensorKey + '-' + sensor.name + '-' + sensor.unit; } }); ); } else { this._sensors = {}; } } else { if (!!data.checked) { this._sensors[data.id] = data.sensorKey + '-' + data.name + '-' + data.unit; } else { delete this._sensors[data.id]; } } this.reloadSensorNames(); } private reloadSensorNames(): void { // 异步提升展现速度 setTimeout(() => { this._sensorNames = ''; const sensorNameList = Object.keys(this._sensors).map( id => { const sensor = this.sensorOptions[0].children.find(item => { return Number(id) === Number(item.id); }); return sensor.name; } ); this._sensorNames = sensorNameList.join(', '); }, 1); } public areaLazyLoad(event: {option: CascaderOption, index: number, resolve: (children: CascaderOption[]) => void, reject: () => void}) { const index = event['index']; const option = event.option; switch (index) { case -1: this.areacodeService.getProvinces().subscribe( (res: {label: string, value: string}[]) => { event.resolve(res); } ); break; case 0: this.areacodeService.getCities(option.value).subscribe( (res: {label: string, value: string}[]) => { event.resolve(res); } ); break; case 1: this.areacodeService.getAreas(option.value).subscribe( (res: {label: string, value: string}[]) => { event.resolve(res); } ); break; } } public regionChange(event: {option: CascaderOption, index: number}) { let name = ''; const option = event.option; this.query.areaCode = null; this.query.monitorPointId = null; this.query.mac = null; switch (event.index) { case 0: name = 'provinceCode'; this.query.provinceCode = option.value; this.query.cityCode = null; break; case 1: name = 'cityCode'; this.query.cityCode = option.value; break; case 2: name = 'areaCode'; this.query.areaCode = option.value; break; } this.http.get(environment.SERVER_BASH_URL + 'monitor-point/list/region', {params: {name: name, value: option.value}}).subscribe((res: any) => { if (res.code === 0) { this.msgSrv.error(res.message); } else { this.monitorPointOptions = res.data; } }); } monitorPointChange(value) { @@ -75,15 +169,22 @@ reportQuery() { const query = this.query; if (this.timeType && query.monitorPointId && query.time) { if (this.monitorPointOptions.length > 0 && query.time) { query.time = this.dateSrv.date_format(query.time, this.timeType.format); if (query.timeb) { query.timeb = this.dateSrv.date_format(query.timeb, this.timeType.format); } if (query.sensorKeys && query.sensorKeys.length > 0) { query.sensors = JSON.stringify(query.sensorKeys); } query.type = this.timeType.value; if (this._sensors) { const sensors = []; for (var key in this._sensors) { sensors.push(this._sensors[key]); } if (sensors.length > 0) { query.sensors = JSON.stringify(sensors); } } let url = environment.SERVER_BASH_URL + 'report/excel?'; for (const a in query) { if (query[a]) { @@ -92,7 +193,7 @@ } window.location.href = url + '_token=' + this.tokenService.get().token; } else { this.msgSrv.error('请完善搜索项'); this.msgSrv.error('开始时间为空或者所选区域没有监控点数据!'); } } }