公共组件 #18

Merged
xiaohai2271 merged 45 commits from dev into master 2020-07-11 10:41:50 +08:00
3 changed files with 23 additions and 27 deletions
Showing only changes of commit 8bd8986bdd - Show all commits

View File

@@ -9,35 +9,35 @@
[nzScroll]="{x:'1300px'}">
<thead>
<tr>
<ng-container *ngFor="let headData of data">
<th *ngIf="headData.show">
{{headData.fieldName}}
<ng-container *ngFor="let data of headData">
<th *ngIf="data.show">
{{data.title}}
</th>
</ng-container>
</tr>
</thead>
<tbody>
<tr *ngFor="let t of dataList.list;let index = index">
<ng-container *ngFor="let headData of data">
<td *ngIf="headData.show"
<ng-container *ngFor="let data of headData">
<td *ngIf="data.show"
nz-typography
nzEllipsis
[nzEllipsisRows]="headData.isActionColumns?3:1"
[nzTooltipTitle]="headData.isActionColumns ? null : headData.fieldName+' : '+getValue(index,headData.fieldValue)"
[nzEllipsisRows]="data.isActionColumns?3:1"
[nzTooltipTitle]="data.isActionColumns ? null : data.title+' : '+getValue(index,data.fieldValue)"
nzTooltipPlacement="top"
nz-tooltip>
<ng-template [ngIf]="!headData.isActionColumns">
<ng-template [ngIf]="template[headData.fieldValue]">
<ng-template [ngIf]="!data.isActionColumns">
<ng-template [ngIf]="template[data.fieldValue]">
<ng-container
*ngTemplateOutlet="template[headData.fieldValue].temp; context:getContext(headData.fieldValue,index) ">
*ngTemplateOutlet="template[data.fieldValue].temp; context:getContext(data.fieldValue,index) ">
</ng-container>
</ng-template>
<ng-template [ngIf]="!template[headData.fieldValue]">
{{ getValue(index, headData.fieldValue) }}
<ng-template [ngIf]="!template[data.fieldValue]">
{{ getValue(index, data.fieldValue) }}
</ng-template>
</ng-template>
<ng-container *ngIf="headData.isActionColumns">
<a *ngFor="let action of headData.action; let i = index"
<ng-container *ngIf="data.isActionColumns">
<a *ngFor="let action of data.action; let i = index"
(mouseenter)="action.hover(t)"
(mouseout)="null"
[ngStyle]="{'color':action.color,'font-size':action.fontSize}"
@@ -47,7 +47,7 @@
(nzOnConfirm)="action.click(t)"
[title]="action.name">
{{action.name}}
<ng-template [ngIf]="i!=headData.action.length-1">
<ng-template [ngIf]="i!=data.action.length-1">
<nz-divider nzType="vertical"></nz-divider>
</ng-template>
</a>

View File

@@ -17,7 +17,7 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
/**
* 设置readonly data 因为后面有使用eval 为了安全
*/
@Input() readonly data: Data<T>[];
@Input() headData: Data<T>[];
@Input() request: RequestObj;
@Input() cardTitle: string;
@Input() template: {
@@ -33,7 +33,7 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
ngOnInit(): void {
if (!this.template) this.template = {}
this.data.forEach(dat => {
this.headData.forEach(dat => {
if (!dat.action) return;
dat.action.forEach(act => {
if (!act.hover) {
@@ -73,18 +73,14 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
}
getValue(index: number, fieldValue: string) {
let str = `this.dataList.list[${index}].` + fieldValue;
const regexp = /<|>|=|onload|$|{|}|《/
str = str.replace(regexp, '');
let value;
getValue(index: number, fieldValue: string): string {
let value = this.dataList.list[index];
try {
// tslint:disable-next-line:no-eval
value = eval(str);
for (const key of fieldValue.split('.')) value = value[key]
} catch (e) {
value = null
// ignore
}
return (value != null) ? value : '————';
return (value != null) ? value.toString() : '————';
}
getContext = (fieldValue: string, index: number) => {

View File

@@ -1,7 +1,7 @@
import {TemplateRef} from '@angular/core';
export class Data<T> {
fieldName: string;
title: string;
fieldValue: string;
show: boolean = true;
primaryKey?: boolean = false;