From 6a6d3bbb3748c12c2dc94beec05d21d82d0faba1 Mon Sep 17 00:00:00 2001 From: fengxiang <110431245@qq.com> Date: Tue, 13 Mar 2018 14:43:01 +0800 Subject: [PATCH] 数据报表 --- src/app/routes/dashboard/workplace/workplace.component.ts | 501 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 481 insertions(+), 20 deletions(-) diff --git a/src/app/routes/dashboard/workplace/workplace.component.ts b/src/app/routes/dashboard/workplace/workplace.component.ts index 30e2c8b..7698053 100644 --- a/src/app/routes/dashboard/workplace/workplace.component.ts +++ b/src/app/routes/dashboard/workplace/workplace.component.ts @@ -3,6 +3,8 @@ import { NzMessageService } from 'ng-zorro-antd'; import { getTimeDistance, yuan, fixedZero } from '@delon/abc'; import { _HttpClient } from '@delon/theme'; +import {HttpClient} from '@angular/common/http'; +import * as moment from 'moment'; @Component({ selector: 'app-dashboard-workplace', @@ -10,6 +12,11 @@ styleUrls: ['./workplace.component.less'] }) export class DashboardWorkplaceComponent implements OnInit, OnDestroy { + + totalDeviceCountList: any[] = []; + totalDeviceCount = 0; + avgDeviceCount: string; + notice: any[] = []; activities: any[] = []; radarData: any[] = []; @@ -76,27 +83,481 @@ ]; // endregion - constructor(private http: _HttpClient, public msg: NzMessageService) {} - - ngOnInit() { - // zip( - // this.http.get('/chart'), - // this.http.get('/api/notice'), - // this.http.get('/api/activities') - // ).subscribe(([ chart, notice, activities ]) => { - // this.radarData = chart['radarData']; - // this.notice = <any []>notice; - // this.activities = (<any []>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; - // }); - // this.loading = false; - // }); + ngOnDestroy(): void { } - ngOnDestroy(): void { + + data: any = { + salesData: [], + offlineData: [] + }; + + q: any = { + start: null, + end: null + }; + rankingListData: any[] = Array(7).fill({}).map((item, i) => { + return { + title: `��������� ${i} ������`, + total: 323234 + }; + }); + + constructor(private http: _HttpClient, public msg: NzMessageService, + private http2: HttpClient) {} + + ngOnInit() { + + 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.totalDeviceCount += fakeDC[i]; + } + this.avgDeviceCount = (this.totalDeviceCount/12).toFixed(0); + + + 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 salesData = []; + for (let i = 0; i < 12; i += 1) { + salesData.push({ + x: `${i + 1}���`, + y: Math.floor(Math.random() * 1000) + 200 + }); + } + + const salesTypeData = [ + { + x: "������������", + y: 4544 + }, + { + x: "������������", + y: 3321 + }, + { + x: "������������", + y: 3113 + }, + { + x: "������������", + y: 2341 + }, + { + x: "������������", + y: 1231 + }, + { + x: "������", + y: 1231 + } + ]; + + const salesTypeDataOnline = [ + { + x: "������������", + y: 244 + }, + { + x: "������������", + y: 321 + }, + { + x: "������������", + y: 311 + }, + { + x: "������������", + y: 41 + }, + { + x: "������������", + y: 121 + }, + { + x: '������', + y: 111 + } + ]; + + const salesTypeDataOffline = [ + { + x: '������������', + y: 99 + }, + { + x: '������������', + y: 188 + }, + { + x: '������������', + y: 344 + }, + { + x: '������������', + y: 255 + }, + { + x: '������', + y: 65 + } + ]; + + const offlineData = []; + for (let i = 0; i < 10; i += 1) { + offlineData.push({ + name: `������${i}`, + cvr: Math.ceil(Math.random() * 9) / 10 + }); + } + const offlineChartData = []; + for (let i = 0; i < 20; i += 1) { + offlineChartData.push({ + x: new Date().getTime() + 1000 * 60 * 30 * i, + y1: Math.floor(Math.random() * 100) + 10, + y2: Math.floor(Math.random() * 100) + 10 + }); + } + + 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 = { + visitData: visitData, + salesData: salesData, + visitData2: visitData2, + salesTypeData: salesTypeData, + salesTypeDataOnline: salesTypeDataOnline, + salesTypeDataOffline: salesTypeDataOffline, + offlineData: offlineData, + offlineChartData: offlineChartData, + radarOriginData: radarOriginData, + radarData: radarData, + searchData: searchData + }; + + res.offlineData.forEach((item: any) => { + item.chart = Object.assign([], res.offlineChartData); + }); + this.data = res; + this.loading = false; + this.changeSaleType(); + + this.radarData = res.radarData; + + const titles = [ + 'Alipay', + 'Angular', + 'Ant Design', + 'Ant Design Pro', + 'Bootstrap', + 'React', + 'Vue', + 'Webpack' + ]; + + 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 notice = [ + { + id: 'xxx1', + title: titles[0], + logo: avatars[0], + description: '������������������������������ ���������������������������������������', + updatedAt: new Date(), + member: '���������������', + href: '', + memberLink: '', + }, + { + id: 'xxx2', + title: titles[1], + logo: avatars[1], + description: '���������������������������������������������������������������������������', + updatedAt: new Date('2017-07-24'), + member: '���������������������', + href: '', + memberLink: '', + }, + { + id: 'xxx3', + title: titles[2], + logo: avatars[2], + description: '������������������������������������������������������������������', + updatedAt: new Date(), + member: '���������������', + href: '', + memberLink: '', + }, + { + id: 'xxx4', + title: titles[3], + logo: avatars[3], + description: '���������������������������������������������������������������������', + updatedAt: new Date('2017-07-23'), + member: '���������������', + href: '', + memberLink: '', + }, + { + id: 'xxx5', + title: titles[4], + logo: avatars[4], + description: '������������', + updatedAt: new Date('2017-07-23'), + member: '���������������������', + href: '', + memberLink: '', + }, + { + id: 'xxx6', + title: titles[5], + logo: avatars[5], + description: '������������������������������������������������������', + updatedAt: new Date('2017-07-23'), + member: '���������������������', + href: '', + memberLink: '', + }, + ]; + this.notice = notice; + + 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}', + }, + ]; + 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; + }); + + + + } + + setDate(type: any) { + const rank = getTimeDistance(type); + this.q.start = rank[0]; + this.q.end = rank[1]; + } + + 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 = 'all'; + salesPieData: any; + salesTotal = 0; + changeSaleType() { + this.salesPieData = this.salesType === 'all' ? this.data.salesTypeData : ( + this.salesType === 'online' ? this.data.salesTypeDataOnline : this.data.salesTypeDataOffline + ); + if (this.salesPieData) this.salesTotal = this.salesPieData.reduce((pre, now) => now.y + pre, 0); + } + + handlePieValueFormat(value: any) { + return yuan(value); + } + + _activeTab = 0; + _tabChange(value: any) { + console.log('tab', this._activeTab, value); } } -- Gitblit v1.8.0