编写通用组件

This commit is contained in:
禾几海
2020-07-01 00:05:00 +08:00
parent e3a4862e13
commit 718a7516af
2 changed files with 19 additions and 6 deletions

View File

@@ -1,4 +1,10 @@
<nz-table>
<nz-table nzTableLayout="fixed"
[nzData]="dataList.list"
[nzTotal]="dataList.total"
[(nzPageIndex)]="dataList.pageNum"
[nzPageSize]="dataList.pageSize"
(nzPageIndexChange)="getData()"
nzFrontPagination="false">
<thead>
<tr>
<ng-container *ngFor="let headData of data">

View File

@@ -1,4 +1,4 @@
import {Component, Input, OnInit} from '@angular/core';
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
import {Data} from './data';
import {PageList, RequestObj} from '../../../../class/HttpReqAndResp';
import {HttpService} from '../../../../api/http/http.service';
@@ -8,7 +8,7 @@ import {HttpService} from '../../../../api/http/http.service';
templateUrl: './common-table.component.html',
styleUrls: ['./common-table.component.less']
})
export class CommonTableComponent<T> implements OnInit {
export class CommonTableComponent<T> implements OnInit, OnChanges {
constructor(private httpService: HttpService) {
@@ -20,9 +20,7 @@ export class CommonTableComponent<T> implements OnInit {
dataList: PageList<T> = new PageList<T>();
ngOnInit(): void {
this.httpService.Service<PageList<T>>(this.request).subscribe(resp => {
this.dataList = resp.result;
});
this.getData();
this.data.forEach(dat => {
if (!dat.action) return;
dat.action.forEach(act => {
@@ -33,4 +31,13 @@ export class CommonTableComponent<T> implements OnInit {
})
}
getData = () => {
this.httpService.Service<PageList<T>>(this.request).subscribe(resp => {
this.dataList = resp.result;
});
}
ngOnChanges(changes: SimpleChanges): void {
}
}