公共组件 #18
@@ -45,6 +45,10 @@ const routes: Routes = [
|
|||||||
loadChildren: () => import('./admin-visitor/admin-visitor.module').then(mod => mod.AdminVisitorModule),
|
loadChildren: () => import('./admin-visitor/admin-visitor.module').then(mod => mod.AdminVisitorModule),
|
||||||
// canActivate: [AuthGuard]
|
// canActivate: [AuthGuard]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'test',
|
||||||
|
loadChildren: () => import('./test-common-table/test-common-table.module').then(Mod => Mod.TestCommonTableModule)
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '**',
|
path: '**',
|
||||||
loadChildren: () => import('./admin-dashboard/admin-dashboard.module').then(mod => mod.AdminDashboardModule),
|
loadChildren: () => import('./admin-dashboard/admin-dashboard.module').then(mod => mod.AdminDashboardModule),
|
||||||
|
|||||||
@@ -1,24 +1,33 @@
|
|||||||
<nz-table>
|
<nz-table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td *ngFor="let headData of data">
|
<ng-container *ngFor="let headData of data">
|
||||||
|
<th *ngIf="headData.show">
|
||||||
{{headData.fieldName}}
|
{{headData.fieldName}}
|
||||||
</td>
|
</th>
|
||||||
|
</ng-container>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr *ngFor="let t of dataList.list">
|
||||||
<td *ngFor="let headData of data">
|
<ng-container *ngFor="let headData of data">
|
||||||
|
<td *ngIf="headData.show">
|
||||||
<ng-template [ngIf]="!headData.isActionColumns">
|
<ng-template [ngIf]="!headData.isActionColumns">
|
||||||
{{headData.fieldName}}
|
{{t[headData.fieldValue]}}
|
||||||
</ng-template>
|
</ng-template>
|
||||||
<ng-template *ngIf="headData.isActionColumns">
|
<ng-container *ngIf="headData.isActionColumns">
|
||||||
<a *ngFor="let action of headData.action" (mouseenter)="action.hover(headData)" (mouseout)="null"
|
<a *ngFor="let action of headData.action; let i = index" (mouseenter)="action.hover(t)"
|
||||||
(click)="action.click(headData)" [ngStyle]="{'color':action.color,'font-size':action.fontSize}">
|
(mouseout)="null" (click)="action.click(t)"
|
||||||
|
[ngStyle]="{'color':action.color,'font-size':action.fontSize}">
|
||||||
{{action.name}}
|
{{action.name}}
|
||||||
</a>
|
<ng-template [ngIf]="i!=headData.action.length-1">
|
||||||
|
<nz-divider nzType="vertical"></nz-divider>
|
||||||
</ng-template>
|
</ng-template>
|
||||||
|
</a>
|
||||||
|
</ng-container>
|
||||||
</td>
|
</td>
|
||||||
|
</ng-container>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import {Component, Input, OnInit} from '@angular/core';
|
import {Component, Input, OnInit} from '@angular/core';
|
||||||
import {Data} from './data';
|
import {Data} from './data';
|
||||||
|
import {PageList, RequestObj} from '../../../../class/HttpReqAndResp';
|
||||||
|
import {HttpService} from '../../../../api/http/http.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-common-table',
|
selector: 'app-common-table',
|
||||||
@@ -8,12 +10,27 @@ import {Data} from './data';
|
|||||||
})
|
})
|
||||||
export class CommonTableComponent<T> implements OnInit {
|
export class CommonTableComponent<T> implements OnInit {
|
||||||
|
|
||||||
constructor() {
|
constructor(private httpService: HttpService) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Input() data: Data<T>[]
|
@Input() data: Data<T>[]
|
||||||
|
@Input() request: RequestObj
|
||||||
|
|
||||||
|
dataList: PageList<T> = new PageList<T>();
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.httpService.Service<PageList<T>>(this.request).subscribe(resp => {
|
||||||
|
this.dataList = resp.result;
|
||||||
|
});
|
||||||
|
this.data.forEach(dat => {
|
||||||
|
if (!dat.action) return;
|
||||||
|
dat.action.forEach(act => {
|
||||||
|
if (!act.hover) {
|
||||||
|
act.hover = () => null;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
import {CommonModule} from '@angular/common';
|
import {CommonModule} from '@angular/common';
|
||||||
import {CommonTableComponent} from './common-table.component';
|
import {CommonTableComponent} from './common-table.component';
|
||||||
import {NzTableModule} from "ng-zorro-antd";
|
import {NzDividerModule, NzTableModule} from 'ng-zorro-antd';
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
CommonTableComponent
|
CommonTableComponent
|
||||||
],
|
],
|
||||||
|
exports: [
|
||||||
|
CommonTableComponent
|
||||||
|
],
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
NzTableModule
|
NzTableModule,
|
||||||
|
NzDividerModule
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class CommonTableModule {
|
export class CommonTableModule {
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
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;
|
|
||||||
}[]
|
|
||||||
}
|
|
||||||
15
src/app/view/admin/components/common-table/data.ts
Normal file
15
src/app/view/admin/components/common-table/data.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
export class Data<T> {
|
||||||
|
fieldName: string;
|
||||||
|
fieldValue: string;
|
||||||
|
show: boolean = true;
|
||||||
|
primaryKey?: boolean = false;
|
||||||
|
isActionColumns?: boolean = false;
|
||||||
|
action?: {
|
||||||
|
name: string,
|
||||||
|
color?: string,
|
||||||
|
order?: number,
|
||||||
|
fontSize?: string,
|
||||||
|
click: (data: T) => void,
|
||||||
|
hover?: (data: T) => void | null;
|
||||||
|
}[] = []
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user