加入网站图标预览和友链页链接自动补写

This commit is contained in:
禾几海
2020-08-07 21:29:30 +08:00
parent 953fba5b17
commit 5454a747a7
2 changed files with 15 additions and 1 deletions

View File

@@ -122,7 +122,13 @@
<nz-form-item>
<nz-form-label nzFlex="100px">网站图标</nz-form-label>
<nz-form-control nzFlex="auto" nzErrorTip="链接格式不正确">
<input nz-input formControlName="iconPath">
<nz-input-group [nzSuffix]="icon" nzSize="large">
<input nz-input formControlName="iconPath">
</nz-input-group>
<ng-template #icon>
<img style="width: 25px;height: 25px" *ngIf="applyFormGroup.value.iconPath"
[src]="applyFormGroup.value.iconPath" alt="icon">
</ng-template>
</nz-form-control>
</nz-form-item>
<nz-form-item>

View File

@@ -30,6 +30,7 @@ export class LinkComponent implements OnInit {
loading: boolean = false;
applyFormGroup: FormGroup;
colors: Color[];
private lastUrl: string = '';
ngOnInit() {
@@ -50,6 +51,13 @@ export class LinkComponent implements OnInit {
name: [null, [Validators.required, Validators.maxLength(255)]],
url: [null, [Validators.required, Validators.pattern(/^([\w-]+\.)+[\w-]+(\/[\w-./?%&=]*)?$/)]]
});
this.applyFormGroup.controls.url.valueChanges.subscribe({
next: data => {
const linkUrlData: string = this.applyFormGroup.value.linkUrl || '';
this.applyFormGroup.patchValue({linkUrl: linkUrlData.replace(this.lastUrl, data)});
this.lastUrl = data;
},
})
}
apply() {