This commit is contained in:
TaricXin
2022-03-15 17:32:24 +08:00
parent 6ccb5ced18
commit 3539bd2a07
11 changed files with 142 additions and 2 deletions

View File

@ -0,0 +1,13 @@
<button nz-button (click)="refresh()" nzType="primary">Refresh</button>
<g2-pie
#pie
[hasLegend]="true"
title="销售额"
subTitle="销售额"
[total]="total"
[valueFormat]="format"
[data]="salesPieData"
height="294"
repaint="false"
(clickItem)="handleClick($event)"
></g2-pie>

View File

@ -0,0 +1,66 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { G2PieClickItem, G2PieComponent, G2PieData } from '@delon/chart/pie';
import { NzMessageService } from 'ng-zorro-antd/message';
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.less']
})
export class DashboardComponent implements OnInit {
@ViewChild('pie', { static: false }) readonly pie!: G2PieComponent;
salesPieData: G2PieData[] = [];
total = '';
constructor(private msg: NzMessageService) {
this.refresh();
}
ngOnInit(): void {
throw new Error('Method not implemented.');
}
refresh(): void {
const rv = (min: number = 0, max: number = 5000) => Math.floor(Math.random() * (max - min + 1) + min);
this.salesPieData = [
{
x: '家用电器',
y: rv()
},
{
x: '食用酒水',
y: rv()
},
{
x: '个护健康',
y: rv()
},
{
x: '服饰箱包',
y: rv()
},
{
x: '母婴产品',
y: rv()
}
];
if (Math.random() > 0.5) {
this.salesPieData.push({
x: '其他',
y: rv()
});
}
this.total = `&yen ${this.salesPieData.reduce((pre, now) => now.y + pre, 0).toFixed(2)}`;
if (this.pie) {
// 等待组件渲染
setTimeout(() => this.pie.changeData());
}
}
format(val: number): string {
return `&yen ${val.toFixed(2)}`;
}
handleClick(data: G2PieClickItem): void {
this.msg.info(`${data.item.x} - ${data.item.y}`);
}
}

View File

@ -0,0 +1,12 @@
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DashboardComponent } from './components/dashboard/dashboard.component';
const routes: Routes = [{ path: 'dashboard', component: DashboardComponent }];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class RegulatoryDataRoutingModule {}

View File

@ -0,0 +1,14 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { SharedModule, SHARED_G2_MODULES } from '@shared';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { RegulatoryDataRoutingModule } from './regulatory-data-routing.module';
const COMPONENTS: any = [DashboardComponent];
const NOTROUTECOMPONENTS: any = [];
@NgModule({
declarations: [...COMPONENTS, ...NOTROUTECOMPONENTS],
imports: [CommonModule, RegulatoryDataRoutingModule, SharedModule, SHARED_G2_MODULES]
})
export class RegulatoryDataModule {}

View File

@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class RegulatoryDataService {
constructor() { }
}

View File

@ -15,6 +15,7 @@ import { RouterModule, Routes } from '@angular/router';
import { LayoutProComponent } from '@brand';
import { EATokenGuard } from '@core';
import { environment } from '@env/environment';
import { AuthGuard } from '../core/guards/auth.guard';
// dashboard pages
@ -68,6 +69,7 @@ const routes: Routes = [
},
{ path: 'menu-management', loadChildren: () => import('./menu-manager/menu-manager.module').then(m => m.MenuManagerModule) },
{ path: 'partner', loadChildren: () => import('./partner/partner.module').then(m => m.PartnerModule) },
{ path: 'regulatory-data', loadChildren: () => import('./regulatory-data/regulatory-data.module').then(m => m.RegulatoryDataModule) },
{
path: 'download',
loadChildren: () => import('./download/download.module').then(m => m.DownloadModule)
@ -92,4 +94,4 @@ const routes: Routes = [
],
exports: [RouterModule]
})
export class RouteRoutingModule { }
export class RouteRoutingModule {}