编写通用组件

This commit is contained in:
禾几海
2020-06-30 18:12:23 +08:00
parent b60688cfd7
commit c271b1a8cf
5 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<nz-table>
<thead>
<tr>
<td *ngFor="let headData of data">
{{headData.fieldName}}
</td>
</tr>
</thead>
<tbody>
<tr>
<td *ngFor="let headData of data">
<ng-template [ngIf]="!headData.isActionColumns">
{{headData.fieldName}}
</ng-template>
<ng-template *ngIf="headData.isActionColumns">
<a *ngFor="let action of headData.action" (mouseenter)="action.hover(headData)" (mouseout)="null"
(click)="action.click(headData)" [ngStyle]="{'color':action.color,'font-size':action.fontSize}">
{{action.name}}
</a>
</ng-template>
</td>
</tr>
</tbody>
</nz-table>

View File

@@ -0,0 +1,19 @@
import {Component, Input, OnInit} from '@angular/core';
import {Data} from './data';
@Component({
selector: 'app-common-table',
templateUrl: './common-table.component.html',
styleUrls: ['./common-table.component.less']
})
export class CommonTableComponent<T> implements OnInit {
constructor() {
}
@Input() data: Data<T>[]
ngOnInit(): void {
}
}

View File

@@ -0,0 +1,17 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {CommonTableComponent} from './common-table.component';
import {NzTableModule} from "ng-zorro-antd";
@NgModule({
declarations: [
CommonTableComponent
],
imports: [
CommonModule,
NzTableModule
]
})
export class CommonTableModule {
}

View File

@@ -0,0 +1,15 @@
export class Data<T> {
fieldName: string;
fieldValue: string;
show: boolean;
bindData?: T;
isActionColumns: boolean;
action: {
name: string,
color: string,
order: number,
fontSize: string,
click: (data: T) => void,
hover: (data: T) => void;
}[]
}