feature(commonTable): dynamic detection of data changes

This commit is contained in:
禾几海
2020-08-28 14:53:11 +08:00
parent e95cd8fe23
commit 6da84e259e

View File

@@ -15,9 +15,6 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
} }
/**
* 设置readonly data 因为后面有使用eval 为了安全
*/
@Input() private headData: Data<T>[]; @Input() private headData: Data<T>[];
@Input() request: RequestObj; @Input() request: RequestObj;
@Input() cardTitle: string | null; @Input() cardTitle: string | null;
@@ -115,9 +112,10 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
return context; return context;
} }
showFieldSetting() { showFieldSetting = () => this.settingModalVisible = true;
this.settingModalVisible = true;
} cancel = () => this.settingModalVisible = false;
calculateVisibleFieldLength = () => this.filedData.filter(value => value.show).length;
ok() { ok() {
this.calculateVisibleFieldLength(); this.calculateVisibleFieldLength();
@@ -142,10 +140,6 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
this.calculateVisibleFieldLength(); this.calculateVisibleFieldLength();
} }
cancel = () => this.settingModalVisible = false;
calculateVisibleFieldLength = () => this.filedData.filter(value => value.show).length;
cloneData = (source: Data<T>[] | string): Data<T>[] => { cloneData = (source: Data<T>[] | string): Data<T>[] => {
let dist: Data<T>[]; let dist: Data<T>[];
if (typeof source === 'string') { if (typeof source === 'string') {
@@ -160,7 +154,17 @@ export class CommonTableComponent<T> implements OnInit, OnChanges {
return dist; return dist;
} }
click() { /**
* 字段编辑项被点击
*/
click = () => {
this.changed = false;
for (let i = 0; i < this.filedData.length; i++) {
const d1 = this.filedData[i];
const d2 = this.headData[i];
if (d1.fieldValue !== d2.fieldValue || d1.show !== d2.show) {
this.changed = true; this.changed = true;
} }
} }
}
}