import { provideValueAccessor } from 'rh-base/core'; import { RhControlValueAccessorComponent } from 'rh-base/shared'; import { Component, ChangeDetectorRef, Input, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core'; import { NzSizeLDSType } from 'ng-zorro-antd/core/types'; @Component({ selector: 'rh-qrcode-display-input', templateUrl: './qrcode-display-input.component.html', styleUrls: ['./qrcode-display-input.component.less'], providers: [provideValueAccessor(RhQrcodeDisplayInputComponent)] }) export class RhQrcodeDisplayInputComponent extends RhControlValueAccessorComponent { @Input() rhSize!: NzSizeLDSType; @Input() rhPlacehodler!: string; /** 是否显示当前二维码的值 */ @Input() rhDisplayValue = false; /** 是否显示二维码后缀 */ @Input() rhShowQrCode = true; /** 是否显示清理按键 */ @Input() rhEnableClearValue = false; /** 回车键按下 */ @Output() rhEneterKeyup = new EventEmitter(); @ViewChild('inputTpl') inputRef!: ElementRef; visible = false; /** 二维码展示数据,当输入框的value清空时,二维码value要保留 */ qrcodeValue = ''; constructor(public cdk: ChangeDetectorRef) { super(cdk); } onEnterKeyup($event: Event, value: string) { if ($event) { $event.preventDefault(); $event.stopImmediatePropagation(); } this.qrcodeValue = value; this.rhEneterKeyup.emit(value); } focusInput() { this.inputRef.nativeElement.focus(); this.inputRef.nativeElement.select(); } showQrcode() { if (this.qrcodeValue?.toString().trim()) { this.visible = true; } } removeValue() { this.value = null; this.focusInput(); } }