upload-dragon-bones.component.ts 3.75 KB
Newer Older
李维's avatar
李维 committed
1 2 3 4 5 6 7 8 9 10 11
import {Component, ElementRef, EventEmitter, Input, Output, OnInit, OnChanges, ViewChild} from '@angular/core';
import {NzMessageService, UploadChangeParam, UploadFile, UploadFileStatus} from 'ng-zorro-antd';
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';


@Component({
  selector: 'upload-dragon-bones',
  templateUrl: './upload-dragon-bones.component.html',
  styleUrls: ['./upload-dragon-bones.component.scss']
})
export class UploadDragonBonesComponent implements OnInit, OnChanges {
李维's avatar
李维 committed
12
  @Input() dragonBones = {
李维's avatar
李维 committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    skeJsonData: {url: "", name: ""},
    texJsonData: {url: "", name: ""},
    texPngData: {url: "", name: ""}
  };
  @Input() buttonText: string = "配置骨骼动画"
  @Output() change = new EventEmitter();
  @ViewChild('videoNode', {static: true }) videoNode: ElementRef;

  uploadUrl;
  uploadData;
  animaPanelVisible: boolean = false;
  isSkeJsonLoading = false;
  isTexJsonLoading = false;
  isTexPngLoading = false;
  skeJsonData = {};
  texJsonData = {};
  texPngData = {};
李维's avatar
李维 committed
30
  _dragonBones = {
李维's avatar
李维 committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
    skeJsonData: {url: "", name: ""},
    texJsonData: {url: "", name: ""},
    texPngData: {url: "", name: ""}
  };

  constructor(private nzMessageService: NzMessageService) {
    this.uploadUrl = (<any> window).courseware.uploadUrl();
    this.uploadData = (<any> window).courseware.uploadData();
    window['air'].getUploadCallback = (url, data) => {
      this.uploadUrl = url;
      this.uploadData = data;
    };
  }

  ngOnInit() {
李维's avatar
李维 committed
46 47 48
    if(this.dragonBones) {
      if(!this.dragonBones.skeJsonData) {
        this.dragonBones.skeJsonData = {url: "", name: ""}
李维's avatar
李维 committed
49
      }
李维's avatar
李维 committed
50 51
      if(!this.dragonBones.texJsonData) {
        this.dragonBones.texJsonData = {url: "", name: ""}
李维's avatar
李维 committed
52
      }
李维's avatar
李维 committed
53 54
      if(!this.dragonBones.texPngData) {
        this.dragonBones.texPngData = {url: "", name: ""}
李维's avatar
李维 committed
55 56
      }
    } else {
李维's avatar
李维 committed
57
      this.dragonBones = {
李维's avatar
李维 committed
58 59 60 61 62
        skeJsonData: {url: "", name: ""},
        texJsonData: {url: "", name: ""},
        texPngData: {url: "", name: ""}
      };
    }
李维's avatar
李维 committed
63
    this._dragonBones = this.dragonBones;
李维's avatar
李维 committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  }

  ngOnChanges() {

  }

  animaPanelCancel() {
    this.animaPanelVisible = false;
  }

  animaPanelOk() {
    this.animaPanelVisible = false;
    this.change.emit({
      texPngData: this.texPngData,
      texJsonData: this.texJsonData,
      skeJsonData: this.skeJsonData,
    })
  }

  setAnimaBtnClick(dragonBones) {
    const {skeJsonData, texJsonData, texPngData} = dragonBones;
    this.skeJsonData = skeJsonData || {};
    this.texJsonData = texJsonData || {};
    this.texPngData = texPngData || {};

    this.animaPanelVisible = true;
  }

  skeJsonHandleChange(e) {
    switch (e.type) {
      case 'start':
        this.isSkeJsonLoading = true;
        break;

      case 'success':
        this.skeJsonData['url'] = e.file.response.url;
        this.skeJsonData['name'] = e.file.name;
        this.nzMessageService.success('上传成功');
        this.isSkeJsonLoading = false;
        break;

      case 'progress':
        break;
    }
  }

  texJsonHandleChange(e) {
    switch (e.type) {
      case 'start':
        this.isTexJsonLoading = true;
        break;

      case 'success':
        this.texJsonData['url'] = e.file.response.url;
        this.texJsonData['name'] = e.file.name;
        this.nzMessageService.success('上传成功');
        this.isTexJsonLoading = false;
        break;

      case 'progress':
        break;
    }
  }

  texPngHandleChange(e) {
    switch (e.type) {
      case 'start':
        this.isTexPngLoading = true;
        break;

      case 'success':
        this.texPngData['url'] = e.file.response.url;
        this.texPngData['name'] = e.file.name;
        this.nzMessageService.success('上传成功');
        this.isTexPngLoading = false;
        break;

      case 'progress':
        break;
    }
  }
  
}