沈斌
2018-03-13 5ad15d5e999b91da4afcc358063f80f95eb66ed9
src/app/routes/dashboard/workplace/workplace.component.ts
@@ -1,8 +1,10 @@
import { zip } from 'rxjs/observable/zip';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { getTimeDistance, yuan, fixedZero } from '@delon/abc';
import { getNotice, getActivities } from '../../../../../_mock/api.service';
import { getFakeChartData } from '../../../../../_mock/chart.service';
import { _HttpClient } from '@delon/theme';
import {HttpClient} from '@angular/common/http';
import * as moment from 'moment';
@Component({
    selector: 'app-dashboard-workplace',
@@ -10,89 +12,372 @@
    styleUrls: ['./workplace.component.less']
})
export class DashboardWorkplaceComponent implements OnInit, OnDestroy {
    notice: any[] = [];
    totalDeviceCountList: any[] = [];
    totalDeviceCount = 0;
    avgDeviceCount: string;
    activities: any[] = [];
    radarData: any[] = [];
    loading = true;
    // region: mock data
    links = [
        {
          title: '操作一',
          href: '',
        },
        {
          title: '操作二',
          href: '',
        },
        {
          title: '操作三',
          href: '',
        },
        {
          title: '操作四',
          href: '',
        },
        {
          title: '操作五',
          href: '',
        },
        {
          title: '操作六',
          href: '',
        },
    ];
    members = [
        {
          id: 'members-1',
          title: '科学搬砖组',
          title: '七星官网',
          logo: 'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png',
          link: '',
        },
        {
          id: 'members-2',
          title: '程序员日常',
          title: '七星商城',
          logo: 'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png',
          link: '',
        },
        {
          id: 'members-3',
          title: '设计天团',
          title: '外链三',
          logo: 'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png',
          link: '',
        },
        {
          id: 'members-4',
          title: '中二少女团',
          title: '外链四',
          logo: 'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png',
          link: '',
        },
        {
          id: 'members-5',
          title: '骗你学计算机',
          logo: 'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png',
          link: '',
        },
        }
      ];
    // endregion
    constructor(public msg: NzMessageService) {}
    data: any = {};
    q: any = {
        start: null,
        end: null
    };
    rankingListData: any[] = [
        {title: `PM 2.5`, total: 230},
        {title: `PM 10`, total: 175},
        {title: `二氧化硫`, total: 123},
        {title: `二氧化氮`, total: 92},
        {title: `甲醛`, total: 39},
        {title: `氯气`, total: 24},
        {title: `一氧化碳`, total: 8}
    ];
    constructor(
        private http: _HttpClient,
        public msg: NzMessageService,
        private http2: HttpClient) {
    }
    ngOnInit() {
        setTimeout(() => {
            this.notice = getNotice();
            this.activities = getActivities().map((item: any) => {
                item.template = item.template.split(/@\{([^{}]*)\}/gi).map((key: string) => {
                    if (item[key]) return `<a>${item[key].name}</a>`;
                    return key;
                });
                return item;
        const today = new Date().getTime();
        const fakeDC = [60, 135, 70, 112, 80, 170, 200, 140, 52, 119, 164, 230];
        for (let i = 0; i < 12; i += 1) {
            this.totalDeviceCountList.push({
                x: moment(today).subtract(-1*i, 'months').format(
                    "YYYY-MM"
                ),
                y: fakeDC[i]
            });
            this.radarData = getFakeChartData.radarData;
            this.loading = false;
        }, 500);
            this.totalDeviceCount += fakeDC[i];
        }
        this.avgDeviceCount = (this.totalDeviceCount/12).toFixed(0);
        const alarmData = [];
        const alarmData_1 = [];
        const alarmData_2 = [];
        const alarmData_3 = [];
        for (let i = 0; i < 12; i += 1) {
            alarmData.push({ x: `${i + 1}月`, y: Math.floor(Math.random() * 1000) + 500 });
            alarmData_1.push({ x: `${i + 1}月`, y: Math.floor(Math.random() * 1000) + 100 });
            alarmData_2.push({ x: `${i + 1}月`, y: Math.floor(Math.random() * 1000) + 200 });
            alarmData_3.push({ x: `${i + 1}月`, y: Math.floor(Math.random() * 1000) + 300 });
        }
        const alertData = [];
        const alertData_1 = [];
        const alertData_2 = [];
        const alertData_3 = [];
        for (let i = 0; i < 7; i += 1) {
            alertData.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 500 });
            alertData_1.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 100 });
            alertData_2.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 200 });
            alertData_3.push({ x: this.rankingListData[i].title, y: Math.floor(Math.random() * 1000) + 300 });
        }
        const visitData = [];
        const beginDay = new Date().getTime();
        const fakeY = [7, 5, 4, 2, 4, 7, 5, 6, 5, 9, 6, 3, 1, 5, 3, 6, 5];
        for (let i = 0; i < fakeY.length; i += 1) {
            visitData.push({
                x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format(
                    "YYYY-MM-DD"
                ),
                y: fakeY[i]
            });
        }
        const visitData2 = [];
        const fakeY2 = [1, 6, 4, 8, 3, 7, 2];
        for (let i = 0; i < fakeY2.length; i += 1) {
            visitData2.push({
                x: moment(new Date(beginDay + 1000 * 60 * 60 * 24 * i)).format(
                    "YYYY-MM-DD"
                ),
                y: fakeY2[i]
            });
        }
        const radarOriginData = [
            {
                name: '个人',
                ref: 10,
                koubei: 8,
                output: 4,
                contribute: 5,
                hot: 7
            },
            {
                name: '团队',
                ref: 3,
                koubei: 9,
                output: 6,
                contribute: 3,
                hot: 1
            },
            {
                name: '部门',
                ref: 4,
                koubei: 1,
                output: 6,
                contribute: 5,
                hot: 7
            }
        ];
        const radarData = [];
        const radarTitleMap = {
            ref: '引用',
            koubei: '口碑',
            output: '产量',
            contribute: '贡献',
            hot: '热度'
        };
        radarOriginData.forEach(item => {
            Object.keys(item).forEach(key => {
                if (key !== 'name') {
                    radarData.push({
                        name: item.name,
                        label: radarTitleMap[key],
                        value: item[key]
                    });
                }
            });
        });
        const searchData = [];
        for (let i = 0; i < 50; i += 1) {
            searchData.push({
                index: i + 1,
                keyword: `搜索关键词-${i}`,
                count: Math.floor(Math.random() * 1000),
                range: Math.floor(Math.random() * 100),
                status: Math.floor((Math.random() * 10) % 2)
            });
        }
        var res = {
            alarmData: alarmData,
            alarmData_1: alarmData_1,
            alarmData_2: alarmData_2,
            alarmData_3: alarmData_3,
            alertData: alertData,
            alertData_1: alertData_1,
            alertData_2: alertData_2,
            alertData_3: alertData_3,
            visitData: visitData,
            visitData2: visitData2,
            radarOriginData: radarOriginData,
            radarData: radarData,
            searchData: searchData
        };
        this.data = res;
        this.loading = false;
        this.changeSaleType();
        this.radarData = res.radarData;
        const avatars = [
            'https://gw.alipayobjects.com/zos/rmsportal/WdGqmHpayyMjiEhcKoVE.png', // Alipay
            'https://gw.alipayobjects.com/zos/rmsportal/zOsKZmFRdUtvpqCImOVY.png', // Angular
            'https://gw.alipayobjects.com/zos/rmsportal/dURIMkkrRFpPgTuzkwnB.png', // Ant Design
            'https://gw.alipayobjects.com/zos/rmsportal/sfjbOqnsXXJgNCjCzDBL.png', // Ant Design Pro
            'https://gw.alipayobjects.com/zos/rmsportal/siCrBXXhmvTQGWPNLBow.png', // Bootstrap
            'https://gw.alipayobjects.com/zos/rmsportal/kZzEzemZyKLKFsojXItE.png', // React
            'https://gw.alipayobjects.com/zos/rmsportal/ComBAopevLwENQdKWiIn.png', // Vue
            'https://gw.alipayobjects.com/zos/rmsportal/nxkuOJlFJuAUhzlMTCEe.png'  // Webpack
        ];
        var activities = [
            {
                id: 'trend-1',
                updatedAt: new Date(),
                user: {
                    name: '林东东',
                    avatar: avatars[0],
                },
                group: {
                    name: '高逼格设计天团',
                    link: 'http://github.com/',
                },
                project: {
                    name: '六月迭代',
                    link: 'http://github.com/',
                },
                template: '在 @{group} 新建项目 @{project}',
            },
            {
                id: 'trend-2',
                updatedAt: new Date(),
                user: {
                    name: '付小小',
                    avatar: avatars[1],
                },
                group: {
                    name: '高逼格设计天团',
                    link: 'http://github.com/',
                },
                project: {
                    name: '六月迭代',
                    link: 'http://github.com/',
                },
                template: '在 @{group} 新建项目 @{project}',
            },
            {
                id: 'trend-3',
                updatedAt: new Date(),
                user: {
                    name: '曲丽丽',
                    avatar: avatars[2],
                },
                group: {
                    name: '中二少女团',
                    link: 'http://github.com/',
                },
                project: {
                    name: '六月迭代',
                    link: 'http://github.com/',
                },
                template: '在 @{group} 新建项目 @{project}',
            },
            {
                id: 'trend-4',
                updatedAt: new Date(),
                user: {
                    name: '周星星',
                    avatar: avatars[3],
                },
                project: {
                    name: '5 月日常迭代',
                    link: 'http://github.com/',
                },
                template: '将 @{project} 更新至已发布状态',
            },
            {
                id: 'trend-5',
                updatedAt: new Date(),
                user: {
                    name: '朱偏右',
                    avatar: avatars[4],
                },
                project: {
                    name: '工程效能',
                    link: 'http://github.com/',
                },
                comment: {
                    name: '留言',
                    link: 'http://github.com/',
                },
                template: '在 @{project} 发布了 @{comment}',
            },
            {
                id: 'trend-6',
                updatedAt: new Date(),
                user: {
                    name: '乐哥',
                    avatar: avatars[5],
                },
                group: {
                    name: '程序员日常',
                    link: 'http://github.com/',
                },
                project: {
                    name: '品牌迭代',
                    link: 'http://github.com/',
                },
                template: '在 @{group} 新建项目 @{project}',
            },
            {
                id: 'trend-7',
                updatedAt: new Date(),
                user: {
                    name: '周星星',
                    avatar: avatars[3],
                },
                project: {
                    name: '程序员日常',
                    link: 'http://github.com/',
                },
                template: '将 @{project} 更新至上线状态',
            }
        ];
        this.activities = activities.map((item: any) => {
            item.template = item.template.split(/@\{([^{}]*)\}/gi).map((key: string) => {
                if (item[key]) return `<a>${item[key].name}</a>`;
                return key;
            });
            return item;
        });
    }
    ngOnDestroy(): void {
    }
    sort(sortName, sortValue) {
        this.data.searchData = [
            ...(<any[]>this.data.searchData).sort((a, b) => {
                if (a[ sortName ] > b[ sortName ]) {
                    return (sortValue === 'ascend') ? 1 : -1;
                } else if (a[ sortName ] < b[ sortName ]) {
                    return (sortValue === 'ascend') ? -1 : 1;
                } else {
                    return 0;
                }
            })
        ];
    }
    salesType = '0';
    salesPieData: any;
    salesTotal = 0;
    changeSaleType() {
        if(this.salesType == '0') {
            this.salesPieData = this.data.alertData;
        } else if(this.salesType == '1') {
            this.salesPieData = this.data.alertData_1;
        } else if(this.salesType == '2') {
            this.salesPieData = this.data.alertData_2;
        } else if(this.salesType == '3') {
            this.salesPieData = this.data.alertData_3;
        }
        if (this.salesPieData) this.salesTotal = this.salesPieData.reduce((pre, now) => now.y + pre, 0);
    }
    handlePieValueFormat(value: any) {
        return value + "次";
    }
}