File

src/app/apm/behavior/behavior.component.ts

Implements

OnInit

Metadata

selector apm-behavior
styleUrls ./behavior.component.scss
templateUrl ./behavior.component.html

Index

Properties
Methods

Constructor

constructor(service: BehaviorService, router: Router)
Parameters :
Name Type Optional
service BehaviorService No
router Router No

Methods

ngOnInit
ngOnInit()
Returns : void
onDetailClicked
onDetailClicked(row)
Parameters :
Name Optional
row No
Returns : void

Properties

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>

./behavior.component.scss

.table-container {
  position: relative;
  overflow: auto;
}

table {
  width: 100%;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""