import { Component, ElementRef, Input, OnInit, ViewChild, AfterViewInit, OnDestroy } from "@angular/core";
import Viewer from 'viewerjs';
@Component({
  selector: "app-image-viewer",
  templateUrl: "./image-viewer.component.html",
  styleUrls: ["./image-viewer.component.less"],
})
export class ImageViewerComponent implements OnInit, AfterViewInit,OnDestroy {
  @ViewChild("ljImgViewerId", { static: false }) ljImgViewer: ElementRef;
  // 图片地址
  @Input() imageUrl: any = [];
  // 默认预览图大小 (单位px)
  @Input() width: any = 100;
  @Input() height: any = 100;
  @Input() isPreviewNow: boolean = false;
  viewer = null;

  constructor() {}

  ngOnInit(): void {
    console.log('初始化')
  }

  ngAfterViewInit(): void {
    this.viewer = new Viewer(this.ljImgViewer["nativeElement"],{
      hide(){
        console.log('隐藏')
        this.viewer && this.viewer.destroy();
      }
    });
    this.isPreviewNow && this.viewer.show();
  }

  ngOnDestroy(): void {
    this.viewer && this.viewer.destroy();
  }
}
