1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import {ChangeDetectorRef, ApplicationRef, Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener} from '@angular/core';
import * as _ from 'lodash';
import {
Label,
MySprite, tweenChange,
} from './Unit';
import {res, resAudio} from './resources';
import {Subject} from 'rxjs';
import {debounceTime} from 'rxjs/operators';
import TWEEN from '@tweenjs/tween.js';
import { animate, keyframes, state, style, transition, trigger } from '@angular/animations';
@Component({
selector: 'app-play',
templateUrl: './play.component.html',
styleUrls: ['./play.component.scss'],
animations: [
trigger('tip-border', [
state('right', style({border: '0.3rem solid #52E55D', 'background-color': '#52E55D', transform: 'scale(1)'})),
state('none', style({transform: 'scale(1)'})),
state('wrong', style({border: '0.3rem solid #ff3333', 'background-color': '#ff3333', transform: 'scale(1)'})),
transition('none => wrong', animate('.2s ease-in', keyframes([
style({transform: 'scale(1)'}),
style({transform: 'scale(0.6)'}),
style({transform: 'scale(1)'}),
]))), // 第一个参数:动画时间, 第二个参数:动画延迟时间
transition('none => right', animate('.2s ease-in', keyframes([
style({transform: 'scale(1)'}),
style({transform: 'scale(0.6)'}),
style({transform: 'scale(1)'}),
]))),
transition('wrong => none', animate('.2s ease-out'))
]),
trigger('tip-circle', [
state('right', style({'background-color': '#52E55D'})),
state('none', style({})),
state('wrong', style({'background-color': '#ff3333'})),
transition('none => wrong', animate('.2s ease-in')), // 第一个参数:动画时间, 第二个参数:动画延迟时间
transition('none => right', animate('.2s ease-in')),
transition('wrong => none', animate('.2s ease-out'))
]),
trigger('zoom', [
state('in', style({
position: 'absolute', 'z-index': '1', top: '0', left: '0', right: '0', bottom: '0', margin: 'auto',
height: '60%', 'object-fit': 'contain', 'max-width': '80%'
})),
state('none', style({})),
transition('none => in', animate('.3s', keyframes([
style({
height: '10%', position: 'absolute', 'z-index': '1', top: '0', left: '0',
right: '0', bottom: '0', margin: 'auto', 'object-fit': 'contain', 'max-width': '80%',
opacity: '0'
}),
style({
height: '20%', position: 'absolute', 'z-index': '1', top: '0', left: '0',
right: '0', bottom: '0', margin: 'auto', 'object-fit': 'contain', 'max-width': '80%',
opacity: '0.2'
}),
style({
height: '30%', position: 'absolute', 'z-index': '1', top: '0', left: '0',
right: '0', bottom: '0', margin: 'auto', 'object-fit': 'contain', 'max-width': '80%',
opacity: '0.4'
}),
style({
height: '40%', position: 'absolute', 'z-index': '1', top: '0', left: '0',
right: '0', bottom: '0', margin: 'auto', 'object-fit': 'contain', 'max-width': '80%',
opacity: '0.6'
}),
style({
height: '50%', position: 'absolute', 'z-index': '1', top: '0', left: '0',
right: '0', bottom: '0', margin: 'auto', 'object-fit': 'contain', 'max-width': '80%',
opacity: '0.8'
}),
]))), // 第一个参数:动画时间, 第二个参数:动画延迟时间
transition('in => none', animate('.5s ease-out'))
])
]
})
export class PlayComponent implements OnInit, OnDestroy {
saveKey = 'ww_question';
options;
zoomIn;
rightAudio = new Audio();
wrongAudio = new Audio();
OPTION_TYPE = {TEXT: 1, PIC: 2, AUDIO: 3};
optionAudio = new Audio();
// 数据
data;
constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef) {
this.rightAudio.src = 'assets/right.mp3';
this.rightAudio.load();
this.wrongAudio.src = 'assets/wrong.mp3';
this.wrongAudio.load();
}
refresh() {
setTimeout(() => {
this.appRef.tick();
}, 1);
}
ngOnInit() {
this.data = {
contentObj: {
pic_id: 'http://staging-teach.cdn.ireadabc.com/5502addf299f5f34dc181f993f81e311.png',
title: '123123123',
options: [{
text: '1111',
pic_id: null,
right: true,
type: 3,
audio_id: 'http://staging-teach.cdn.ireadabc.com/ab0872d9ed584c06181d41d9c7c4bf75.mp3'
}, {
text: '222',
pic_id: 'http://staging-teach.cdn.ireadabc.com/d4bf481e893b0a46cac9eef21930f822.png',
right: false,
type: 2
}, {
text: '3333',
pic_id: null,
right: false,
type: 1
}, {
text: '4444',
pic_id: null,
right: false,
type: 1
}]
}
};
this.zoomIn = false;
this.options = _.get(this.data.contentObj, 'options', []).map(item => {
item.state = '';
// Ken 2019-04-15 22:38 把showPic, showText的逻辑换为type
if (_.isUndefined(item.type)) {
item.type = item.showPic ? this.OPTION_TYPE.PIC : this.OPTION_TYPE.TEXT;
}
return item;
});
// 获取数据
const getData = (window as any).courseware.getData;
getData((data) => {
if (data && typeof data === 'object') {
this.data = data;
this.zoomIn = false;
this.options = _.get(this.data.contentObj, 'options', []).map(item => {
item.state = '';
// Ken 2019-04-15 22:38 把showPic, showText的逻辑换为type
if (_.isUndefined(item.type)) {
item.type = item.showPic ? this.OPTION_TYPE.PIC : this.OPTION_TYPE.TEXT;
}
return item;
});
}
if (window['air']) {
window['air'].hideAirClassLoading(this.saveKey, this.data);
}
this.refresh();
}, this.saveKey);
}
ngOnDestroy() {
this.rightAudio.pause();
this.wrongAudio.pause();
this.optionAudio.pause();
this.rightAudio = null;
this.wrongAudio = null;
this.optionAudio = null;
}
transCharCode(index) {
return String.fromCharCode(65 + index);
}
handleAnimation(item) {
if (item.right) {
item.state = 'right';
this.rightAudio.play();
} else {
item.state = 'wrong';
this.wrongAudio.play();
setTimeout(() => {
item.state = '';
}, 1500);
}
}
onHandleZoomIn(e) {
e.stopPropagation();
this.zoomIn = !this.zoomIn;
}
playAudio(option, e) {
e.stopPropagation();
this.optionAudio.src = option.audio_id;
// this.optionAudio.load();
this.optionAudio.play();
}
}