form.component.ts 1.9 KB
Newer Older
范雪寒's avatar
范雪寒 committed
1 2
import { Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef } from '@angular/core';
import { JsonPipe } from '@angular/common';
范雪寒's avatar
范雪寒 committed
3
import { ComponentBase } from './ComponentBase';
范雪寒's avatar
范雪寒 committed
4 5 6 7 8 9 10


@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css']
})
范雪寒's avatar
范雪寒 committed
11
export class FormComponent extends ComponentBase implements OnInit, OnChanges, OnDestroy {
范雪寒's avatar
范雪寒 committed
12 13

  // 储存数据用
范雪寒's avatar
范雪寒 committed
14
  saveKey = "card_machine";
范雪寒's avatar
范雪寒 committed
15
  // 储存对象
范雪寒's avatar
范雪寒 committed
16 17 18 19
  item: any = {
    title: '',
    questionText: '',
    questionTextAudio: '',
20
    audioFileName: '',
范雪寒's avatar
范雪寒 committed
21 22 23 24 25 26
    questions: [],
  };

  addQuestion() {
    this.item.questions.push({
      type: 'img',
范雪寒's avatar
范雪寒 committed
27
      audio: '',
范雪寒's avatar
范雪寒 committed
28 29
      text: '',
      image: ''
范雪寒's avatar
范雪寒 committed
30 31 32 33
    });
    this.save();
  }

范雪寒's avatar
范雪寒 committed
34 35
  removeQuestion(idx) {
    this.item.questions.splice(idx, 1);
范雪寒's avatar
范雪寒 committed
36 37
    this.save();
  }
38 39 40 41 42

  saveAudioFileName(name) {
    this.item.audioFileName=name;
    this.save();
  }
liujiangnan's avatar
liujiangnan committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57

  handle_dragover(e) {
    e.preventDefault();
  }

  handle_drop(e) {
    e.preventDefault();
    const dt = e.dataTransfer.getData("text/plain");
    console.log("handle_drop===", dt);
    // 网络文件 dt 的数据遵循如下格式
    // 图片 "http://staging-teach.cdn.ireadabc.com/f38f9928-c3bd-47f8-9ed1-43c0e03d2f30.png";
    // 音频(JSON字符串) {url: "http://staging-teach.cdn.ireadabc.com/1c8694612563f4e2da707f1f6a37d066_l.mp3", name: "test.mp3"};
    // 视频(JSON字符串) {url: "http://staging-teach.cdn.ireadabc.com/c37a3945121274a1f7d95717327539ec_l.mp4", name: "视频.mp4"};
    // 骨骼动画(JSON字符串) {"ske":{"url":"http://staging-teach.cdn.ireadabc.com/3d4a36b83aada60709771fbe15e2b6db.json","name":"飞鸟_ske.json"},"tex":{"url":"http://staging-teach.cdn.ireadabc.com/08a676a5f456634f9c6c90e9efd3c2ea.json","name":"飞鸟_tex.json"},"png":{"url":"http://staging-teach.cdn.ireadabc.com/874393ecf5e0cd42a09f5b34d48854d2.png","name":"飞鸟_tex.png"}};
  }
范雪寒's avatar
范雪寒 committed
58
}