公共组件 #18

Merged
xiaohai2271 merged 45 commits from dev into master 2020-07-11 10:41:50 +08:00
Showing only changes of commit 5524b8a80b - Show all commits

View File

@@ -15,13 +15,14 @@ import {NzModalRef, NzModalService} from 'ng-zorro-antd';
selector: 'editable-tag', selector: 'editable-tag',
template: ` template: `
<nz-tag *ngIf="!inputVisible" title="双击进入编辑" [nzColor]="color" nzNoAnimation <nz-tag *ngIf="!inputVisible" title="双击进入编辑" [nzColor]="color" nzNoAnimation
(click)="showInput(true)" (click)="showInput(this.doubleClick)"
[style.border-style]="showBorder ? 'solid': 'none'"> [style.border-style]="showBorder ? 'solid': 'none'">
{{text}} {{text}}
<ng-content></ng-content>
</nz-tag> </nz-tag>
<input #inputElement <input #inputElement
nz-input nz-input
nzSize="small" [nzSize]="size"
*ngIf="inputVisible" *ngIf="inputVisible"
type="text" type="text"
[(ngModel)]="inputValue" [(ngModel)]="inputValue"
@@ -55,6 +56,9 @@ export class EditableTagComponent implements OnInit, OnChanges {
@Input() text: string; @Input() text: string;
@Input() key: any; @Input() key: any;
@Input() showConfirmModal: boolean; @Input() showConfirmModal: boolean;
@Input() doubleClick: boolean;
@Input() autoClear: boolean;
@Input() size: 'small' | 'default' | 'large';
@Output() modalOK = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>(); @Output() modalOK = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>();
@Output() modalCancel = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>(); @Output() modalCancel = new EventEmitter<{ value: string, originalValue: string, changed: boolean }>();
@@ -71,6 +75,9 @@ export class EditableTagComponent implements OnInit, OnChanges {
if (this.showBorder == null) { if (this.showBorder == null) {
this.showBorder = true; this.showBorder = true;
} }
if (this.doubleClick == null) {
this.doubleClick = true;
}
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
@@ -82,7 +89,7 @@ export class EditableTagComponent implements OnInit, OnChanges {
showInput(doubleClick: boolean): void { showInput(doubleClick: boolean): void {
this.inputValue = this.text; this.inputValue = this.text;
if (doubleClick) { if (this.doubleClick && doubleClick) {
if (!this.doubleClickInfo.date) { if (!this.doubleClickInfo.date) {
this.doubleClickInfo.date = new Date().getTime(); this.doubleClickInfo.date = new Date().getTime();
return return
@@ -118,7 +125,7 @@ export class EditableTagComponent implements OnInit, OnChanges {
this.text = this.inputValue; this.text = this.inputValue;
this.inputValue = ''; this.inputValue = '';
this.inputVisible = false; this.inputVisible = false;
if (this.showConfirmModal && value.changed) { if (this.showConfirmModal && value.changed && this.text != null) {
this.confirmModal = this.modal.confirm({ this.confirmModal = this.modal.confirm({
nzTitle: '数据变更', nzTitle: '数据变更',
nzContent: '是否提交修改,点击确定提交修改,点击取消则恢复原数据', nzContent: '是否提交修改,点击确定提交修改,点击取消则恢复原数据',
@@ -126,6 +133,9 @@ export class EditableTagComponent implements OnInit, OnChanges {
nzOnCancel: () => this.modalCancel.emit(value) nzOnCancel: () => this.modalCancel.emit(value)
}); });
} }
if (this.autoClear) {
this.text = null
}
} }
} }