File
Implements
Metadata
| selector |
apm-behavior |
| styleUrls |
./behavior.component.scss |
| templateUrl |
./behavior.component.html |
Methods
|
onDetailClicked
|
onDetailClicked(row)
|
|
|
|
|
|
dataSource
|
Default value : new MatTableDataSource([])
|
|
|
|
devicesDataSource
|
Type : []
|
Default value : []
|
|
|
|
displayedColumns
|
Type : string[]
|
Default value : ['ip', 'browser', 'system', 'star']
|
|
|
|
eventDataSource
|
Type : []
|
Default value : []
|
|
|
|
isLoadingResults
|
Default value : true
|
|
|
|
isRateLimitReached
|
Default value : false
|
|
|
|
paginator
|
Type : MatPaginator
|
Decorators :
@ViewChild(MatPaginator, {static: true})
|
|
|
|
resultsLength
|
Type : number
|
Default value : 0
|
|
|
|
search
|
Type : SearchComponent
|
Decorators :
@ViewChild(SearchComponent, {static: true})
|
|
|
|
selection
|
Default value : new SelectionModel(true, [])
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
import { Router } from '@angular/router';
import { MatPaginator, MatTableDataSource } from '@angular/material';
import { SelectionModel } from '@angular/cdk/collections';
import { merge, of as observableOf } from 'rxjs';
import { catchError, map, startWith, switchMap } from 'rxjs/operators';
import { SearchComponent } from '../../component';
import { BehaviorService } from './behavior.service';
@Component({
selector: 'apm-behavior',
templateUrl: './behavior.component.html',
styleUrls: ['./behavior.component.scss']
})
export class BehaviorComponent implements OnInit {
displayedColumns: string[] = ['ip', 'browser', 'system', 'star'];
dataSource = new MatTableDataSource([]);
selection = new SelectionModel(true, []);
resultsLength = 0;
isLoadingResults = true;
isRateLimitReached = false;
devicesDataSource = [];
eventDataSource = [];
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(SearchComponent, { static: true }) search: SearchComponent;
constructor(private service: BehaviorService, private router: Router) { }
ngOnInit() {
this.search.onSearch.subscribe(() => (this.paginator.pageIndex = 0));
merge(this.search.onSearch, this.paginator.page)
.pipe(
startWith({}),
switchMap(search => {
return this.service.getList(this.paginator.pageIndex, search);
}),
map(data => {
this.isLoadingResults = false;
this.isRateLimitReached = false;
this.resultsLength = data.data.totalNum;
return data.data.datalist;
}),
catchError(() => {
this.isLoadingResults = false;
this.isRateLimitReached = true;
return observableOf([]);
})
)
.subscribe(data => (this.dataSource = data));
}
onDetailClicked(row) {
this.router.navigateByUrl(`${this.router.url}/${row.markuser}`);
}
}
<stbui-search
placeholder="输入资源名称"
class="mat-elevation-z4 m-b-16"
></stbui-search>
<div class="mat-elevation-z4">
<div class="table-container">
<table class="table-hover" mat-table [dataSource]="dataSource">
<ng-container matColumnDef="ip">
<th mat-header-cell *matHeaderCellDef>访问者IP</th>
<td mat-cell *matCellDef="let element">{{ element.ip }}</td>
</ng-container>
<ng-container matColumnDef="browser">
<th mat-header-cell *matHeaderCellDef>浏览器</th>
<td mat-cell *matCellDef="let element">{{ element.browser }}</td>
</ng-container>
<ng-container matColumnDef="system">
<th mat-header-cell *matHeaderCellDef>操作系统</th>
<td mat-cell *matCellDef="let element">{{ element.system }}</td>
</ng-container>
<ng-container matColumnDef="star" stickyEnd>
<th mat-header-cell *matHeaderCellDef>操作</th>
<td
mat-cell
*matCellDef="let element"
(click)="onDetailClicked(element); $event.stopPropagation()"
>
详情
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr
mat-row
*matRowDef="let row; columns: displayedColumns"
(click)="onRowClicked(row, $event)"
></tr>
</table>
</div>
<mat-paginator [length]="resultsLength" [pageSize]="10"></mat-paginator>
</div>
.table-container {
position: relative;
overflow: auto;
}
table {
width: 100%;
}
Legend
Html element with directive