fengxiang
2018-08-03 4c99ab95e0449348d938ec0ceb949bceafb0cfda
src/app/routes/operation/device-data/device-data.component.ts
@@ -1,6 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { _HttpClient } from '@delon/theme';
import * as moment from "moment";
import { DeviceControllerService } from '../device-controller/device-controller.service';
@Component({
@@ -13,20 +14,92 @@
        advancedOperation2: [],
        advancedOperation3: []
    };
    public selectedIndex = 0;
    public get deviceData() {
        return this.deviceControllerService.data;
    }
    public get deviceStatusName() {
        if(!!this.deviceControllerService
        &&this.deviceControllerService.data
        &&this.deviceControllerService.data.state) {
            switch (this.deviceControllerService.data.state) {
                case "0":
                    return '正常';
                case "1":
                    return '轻度';
                case "2":
                    return '中度';
                case "3":
                    return '严重';
                default:
                    return '离线';
            }
        }else {
         return '离线';
        }
    }
    constructor(
        public msg: NzMessageService, 
        private http: _HttpClient,
        private deviceControllerService:DeviceControllerService,
    ) {}
    ) {
    }
    /**
     * 返回设备列表页面
     * toDeviceStatus
     */
    public toDeviceStatus() {
        this.deviceControllerService.incumbent = 'status';
    }
    /**
     * getTableList
     */
    public historys = [
        {"CO": "1.1", "O3": "10.0", "AQI": "170.0", "NO2": "76.0", "SO2": "13.0", "PM10": "187.0", "city": "杭州市", "PM2_5": "129.0", "level": "4", "quality": "中度污染", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "细颗粒物(PM2.5)"},
        {"CO": "1.3", "O3": "3.0", "AQI": "169.0", "NO2": "77.0", "SO2": "18.0", "PM10": "185.0", "city": "杭州市", "PM2_5": "128.0", "level": "4", "quality": "中度污染", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "细颗粒物(PM2.5)"},
        {"CO": "1.5", "O3": "3.0", "AQI": "156.0", "NO2": "79.0", "SO2": "19.0", "PM10": "178.0", "city": "杭州市", "PM2_5": "119.0", "level": "4", "quality": "中度污染", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "细颗粒物(PM2.5)"},
        {"CO": "1.1", "O3": "6.0", "AQI": "100.0", "NO2": "64.0", "SO2": "11.0", "PM10": "112.0", "city": "杭州市", "PM2_5": "75.0", "level": "2", "quality": "良", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "细颗粒物(PM2.5)"},
        {"CO": "1.2", "O3": "4.0", "AQI": "77.0", "NO2": "72.0", "SO2": "14.0", "PM10": "97.0", "city": "杭州市", "PM2_5": "56.0", "level": "2", "quality": "良", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "细颗粒物(PM2.5)"},
        {"CO": "0.7", "O3": "31.0", "AQI": "70.0", "NO2": "41.0", "SO2": "10.0", "PM10": "77.0", "city": "杭州市", "PM2_5": "51.0", "level": "2", "quality": "良", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "细颗粒物(PM2.5)"},
        {"CO": "0.8", "O3": "10.0", "AQI": "50.0", "NO2": "62.0", "SO2": "10.0", "PM10": "44.0", "city": "杭州市", "PM2_5": "35.0", "level": "1", "quality": "优", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "—"},
        {"CO": "0.7", "O3": "31.0", "AQI": "70.0", "NO2": "41.0", "SO2": "10.0", "PM10": "77.0", "city": "杭州市", "PM2_5": "51.0", "level": "2", "quality": "良", "latitude": "30.2111727272727", "city_code": "330100", "longitude": "120.081909090909", "pollutions": "细颗粒物(PM2.5)"},
        {"CO": "1.5", "O3": "70.0", "AQI": "185.0", "NO2": "46.0", "SO2": "12.0", "PM10": "167.0", "city": "杭州市", "PM2_5": "139.0", "level": "", "quality": "中度污染", "station": "和睦小学", "latitude": "30.3119", "city_code": "330100", "longitude": "120.12", "pollutions": "细颗粒物(PM2.5)", "station_code": "1230A"},
        {"CO": "1.6", "O3": "24.0", "AQI": "202.0", "NO2": "82.0", "SO2": "10.0", "PM10": "186.0", "city": "杭州市", "PM2_5": "152.0", "level": "", "quality": "重度污染", "station": "和睦小学", "latitude": "30.3119", "city_code": "330100", "longitude": "120.12", "pollutions": "细颗粒物(PM2.5)", "station_code": "1230A"}
    ];
    public getTableList(type) {
        let index = 1;
        return this.historys.map(
            item => {
                const date = moment().subtract(index,'days').format('YYYY-MM-DD');
                let content = '';
                switch (type) {
                    case 'history':
                        content = `
                         CO:${item.CO} ug/m3,
                         O3:${item.O3} mg/m3,
                         NO2:${item.NO2} mg/m3,
                         SO2:${item.SO2} mg/m3,
                         PM10:${item.PM10} mg/m3,
                         PM2_5:${item.PM2_5} mg/m3
                        `;
                        break;
                    case 'alarm':
                    content = `${item.quality}`;
                    break;
                    case 'violation':
                    content = `${item.pollutions}`;
                    break;
                    default:
                        break;
                }
                index++;
                return {
                    date:date,
                    content:content
                }
            }
        );
    }
    ngOnInit() {
        this.http.get('/profile/advanced').subscribe((res: any) => this.data = res);
    }