|  |  |  | 
|---|
|  |  |  | import {NzMessageService, NzModalService} from 'ng-zorro-antd'; | 
|---|
|  |  |  | import {Component, OnInit, Inject} from '@angular/core'; | 
|---|
|  |  |  | import {HttpClient} from '@angular/common/http'; | 
|---|
|  |  |  | import { ITokenService, DA_SERVICE_TOKEN } from '@delon/auth'; | 
|---|
|  |  |  | import {ITokenService, DA_SERVICE_TOKEN} from '@delon/auth'; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Component({ | 
|---|
|  |  |  | selector: 'app-excel', | 
|---|
|  |  |  | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | export class ExcelComponent implements OnInit { | 
|---|
|  |  |  | [x: string]: any; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | query: any = { | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | time: any = { | 
|---|
|  |  |  | format: 'YYYY', | 
|---|
|  |  |  | mode: 'month' | 
|---|
|  |  |  | }; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public query: any = {}; | 
|---|
|  |  |  | public sensorOptions = []; | 
|---|
|  |  |  | public monitorPointOptions = []; | 
|---|
|  |  |  | public deviceOptions = []; | 
|---|
|  |  |  | public typeOptions = [ | 
|---|
|  |  |  | {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'} | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | constructor( | 
|---|
|  |  |  | public http: HttpClient, | 
|---|
|  |  |  | public dateSrv: DateService, | 
|---|
|  |  |  | public msgSrv: NzMessageService, | 
|---|
|  |  |  | @Inject(DA_SERVICE_TOKEN)public tokenService: ITokenService | 
|---|
|  |  |  | ) {} | 
|---|
|  |  |  | @Inject(DA_SERVICE_TOKEN) public tokenService: ITokenService | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | this.timeType = this.typeOptions[1]; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ngOnInit() { | 
|---|
|  |  |  | this.query.time = null; | 
|---|
|  |  |  | 
|---|
|  |  |  | this.msgSrv.error(res.message); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.sensorOptions = res.data; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | sensorChange(value) { | 
|---|
|  |  |  | this.sensorOptions.forEach(sensor => { | 
|---|
|  |  |  | if (sensor.sensorKey === value) { | 
|---|
|  |  |  | this.sensor = sensor; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | this.deviceOptions = res.data; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.monitorPointa = null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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'} | 
|---|
|  |  |  | ]; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | typeChange(searchText) { | 
|---|
|  |  |  | this.typeOptions.forEach(types => { | 
|---|
|  |  |  | if (types.value === searchText) { | 
|---|
|  |  |  | this.timeType = types; | 
|---|
|  |  |  | this.time.format = types.format.toUpperCase(); | 
|---|
|  |  |  | this.time.mode = types.mode; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | reportQuery() { | 
|---|
|  |  |  | const query = this.query; | 
|---|
|  |  |  | if (query.type && query.monitorPointId && query.time) { | 
|---|
|  |  |  | if (query.time) { | 
|---|
|  |  |  | query.time = this.dateSrv.date_format(query.time, this.time.format); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (this.timeType && query.monitorPointId && 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.time.format); | 
|---|
|  |  |  | query.timeb = this.dateSrv.date_format(query.timeb, this.timeType.format); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (query.sensorKey) { | 
|---|
|  |  |  | query.sensorName = this.sensor.name; | 
|---|
|  |  |  | if (query.sensorKey && query.sensorKey.length > 0) { | 
|---|
|  |  |  | query.sensors = JSON.stringify(query.sensorKey); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | query.format = this.timeType.format; | 
|---|
|  |  |  | query.typeFormat = this.timeType.typeFormat; | 
|---|
|  |  |  | query.type = this.timeType.value; | 
|---|
|  |  |  | let url = environment.SERVER_BASH_URL + 'report/excel?'; | 
|---|
|  |  |  | for (const a in query) { | 
|---|
|  |  |  | if (query[a]) { | 
|---|
|  |  |  | url += encodeURI(a) + '=' + encodeURI(query[a]) + '&'; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | window.location.href = url + '_token=' + this.tokenService.get().token; | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | this.msgSrv.error('请完善搜索项'); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|