Commit 7ed15fa4 authored by liujiangnan's avatar liujiangnan

feat: 迁移完成

parent 8a51c964
...@@ -30,7 +30,10 @@ ...@@ -30,7 +30,10 @@
], ],
"styles": [ "styles": [
"./node_modules/ng-zorro-antd/ng-zorro-antd.min.css", "./node_modules/ng-zorro-antd/ng-zorro-antd.min.css",
"src/styles.css" "./node_modules/font-awesome/css/font-awesome.css",
"./node_modules/bootstrap/dist/css/bootstrap.min.css",
"./node_modules/animate.css/animate.min.css",
"src/styles.scss"
], ],
"scripts": [] "scripts": []
}, },
...@@ -128,5 +131,8 @@ ...@@ -128,5 +131,8 @@
} }
} }
}, },
"defaultProject": "ng-template-generator" "defaultProject": "ng-template-generator",
} "cli": {
"analytics": "0d24335e-393e-4bb2-af07-a8a8ae7c4634"
}
}
\ No newline at end of file
...@@ -24,6 +24,7 @@ import {AudioRecorderComponent} from './common/audio-recorder/audio-recorder.com ...@@ -24,6 +24,7 @@ import {AudioRecorderComponent} from './common/audio-recorder/audio-recorder.com
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome'; import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { fas } from '@fortawesome/free-solid-svg-icons'; import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons'; import { far } from '@fortawesome/free-regular-svg-icons';
import { BrLineBreakerPipe } from './pipes/br-line-breaker.pipe';
registerLocaleData(zh); registerLocaleData(zh);
...@@ -36,6 +37,7 @@ registerLocaleData(zh); ...@@ -36,6 +37,7 @@ registerLocaleData(zh);
AudioRecorderComponent, AudioRecorderComponent,
UploadImageWithPreviewComponent, UploadImageWithPreviewComponent,
BackgroundImagePipe, BackgroundImagePipe,
BrLineBreakerPipe,
ResourcePipe, ResourcePipe,
TimePipe, TimePipe,
UploadVideoComponent, UploadVideoComponent,
......
@import '../style/common_mixin.css';
.model-content {
width: 100%;
height: 100%;
}
<div class="p-box" *ngFor="let word of item.contentObj.wordnum;index as num;">
<nz-card nzTitle="Word Spelling [{{num + 1}} / {{item.contentObj.wordnum.length}}]" [nzExtra]="extraTemplate">
<div>
<div class="spelling-box" *ngFor="let box of defaultBoxes; index as i">
<div class="model-content"> <div *ngIf="word.words[i]">
<div class="w-radio"
(click)="select(i,num)">
<div class="r-radio"
[class.green]="word.words[i].selected"></div>
</div>
<input class="p-letter-input" name="Input" type="text" maxlength="1" tabindex="0"
[(ngModel)]="word.words[i].value"
(keyup)="keyup($event,word.words[i].value,num);">
<div style="position: absolute; left: 200px; top: 100px; width: 800px;"> </div>
<input type="text" nz-input [(ngModel)]="item.text" (blur)="save()"> </div>
<span class="p-hint">
1. Type letters of word in left <br>
2. Press Enter to confirm <br>
3. Click round point to set 'Missing Letter'
</span>
</div>
<div class="mt-3">
<div class="show" *ngFor="let it of word.words">
<div *ngIf="it.selected" class="blank"><p></p></div>
<div *ngIf="!it.selected"><p>{{it.value}}</p></div>
</div>
</div>
<app-upload-image-with-preview <nz-divider></nz-divider>
[picUrl]="item.pic_url"
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')"
></app-upload-image-with-preview>
<app-audio-recorder <div class="p-media-box d-flex">
[audioUrl]="item.audio_url" <div>
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')" <app-upload-image-with-preview [picUrl]="word.pic_id"
></app-audio-recorder> (imageUploaded)="onImageUploadSuccess($event, num)"
<app-custom-hot-zone></app-custom-hot-zone> ></app-upload-image-with-preview>
<app-upload-video></app-upload-video> </div>
<app-lesson-title-config></app-lesson-title-config> <nz-divider nzType="vertical"></nz-divider>
</div> <div>
<app-audio-recorder
[audioUrl]="word.spelling_audio"
(audioUploaded)="onVocabularyAudioUploadSuccess($event,num)"
></app-audio-recorder>
</div>
</div>
</nz-card>
<ng-template #extraTemplate>
<button nz-button nzType="danger" nz-popconfirm nzTitle="Are you sure ?" (nzOnConfirm)="DeletWord(num)">Delete
</button>
</ng-template>
</div> </div>
\ No newline at end of file
<button nz-button nzType="primary" (click)="AddWord()">
+ Add Word
</button>
p {
margin: 0;
}
.spelling-box {
// width: 2.5rem;
// height: 2.5rem;
display: inline-block;
margin: 0.2rem;
input {
width: 2.7rem;
height: 2.7rem;
text-align: center;
display: inline-block;
border: 0.1rem solid #888;
line-height: 2.7rem;
font-weight: 900;
font-size: 1.8rem;
}
.r-radio {
width: 0.5rem;
height: 0.5rem;
border: 1px solid #888;
border-radius: 50%;
}
.green {
background-color: #8dd897;
}
.w-radio {
width: 1rem;
height: 1rem;
margin: 20% auto;
border: 1px solid;
border-radius: 50%;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
}
}
button {
margin-top: 2%;
margin-left: 5%;
}
.show {
display: inline-block;
div {
display: inline;
}
p {
display: block;
line-height: 2.5rem;
border-radius: 15%;
margin: 0 1px;
font-weight: 900;
font-size: 1.8rem;
}
.blank {
border: 2px solid;
margin: 0 3px;
display: inline-block;
width: 2.5rem;
height: 2.5rem;
border-radius: 20%;
vertical-align: bottom;
}
}
.p-box {
padding: 2rem;
margin-bottom: 1.5rem;
nz-card {
border-radius: 0.5rem;
}
}
.p-letter-input:focus {
border-color: #1eb461 !important;
}
.p-media-box {
& > div:nth-child(1) {
width: 18rem;
}
nz-divider {
height: 10rem;
margin: 0 2rem;
}
}
.p-hint {
margin-left: 1rem;
color: #888;
font-size: 10px;
display: inline-block;
}
import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef} from '@angular/core'; import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef} from '@angular/core';
import * as _ from 'lodash';
@Component({ @Component({
selector: 'app-form', selector: 'app-form',
templateUrl: './form.component.html', templateUrl: './form.component.html',
styleUrls: ['./form.component.css'] styleUrls: ['./form.component.scss']
}) })
export class FormComponent implements OnInit, OnChanges, OnDestroy { export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 储存数据用 // 储存数据用
saveKey = "test_0011"; saveKey = 'spelling';
// 储存对象 // 储存对象
item; item;
originContent;
defaultBoxes = new Array(15);
words = [];
bol: number;
inputs: any;
wordnum = [];
constructor(private appRef: ApplicationRef,private changeDetectorRef: ChangeDetectorRef) {
constructor(private appRef: ApplicationRef,
private changeDetectorRef: ChangeDetectorRef) {
this.bol = 0;
this.inputs = document.getElementsByName('Input');
} }
ngOnInit() { ngOnInit() {
this.item = {}; this.item = {
contentObj: {
}
};
// 获取存储的数据 // 获取存储的数据
(<any> window).courseware.getData((data) => { (window as any).courseware.getData((data) => {
if (data) { if (data) {
this.item = data; this.item = data;
} }
...@@ -50,32 +61,85 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -50,32 +61,85 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
init() { init() {
if (!this.item.contentObj.wordnum) {
this.item.contentObj.wordnum = [];
this.AddWord();
}
}
updateVocabulary() {
this.save();
} }
onVocabularyAudioUploadSuccess(e, num) {
this.item.contentObj.wordnum[num].spelling_audio = e.url;
this.updateVocabulary();
}
/** onImageUploadSuccess(e, num) {
* 储存图片数据 this.item.contentObj.wordnum[num].pic_id = e.url;
* @param e this.updateVocabulary();
*/
onImageUploadSuccess(e, key) {
this.item[key] = e.url;
this.save();
} }
/** keyup(event, value, num) {
* 储存音频数据 const word = _.get(this.item, `contentObj.wordnum[${num}]`);
* @param e if (event.keyCode === 13) {
*/ this.updateVocabulary();
onAudioUploadSuccess(e, key) { } else {
for (let i = 0; i < this.inputs.length; i++) {
if (event.path[0] === this.inputs[i]) {
if (value !== '' && event.keyCode <= 90 && event.keyCode >= 65) {
if (i === this.inputs.length - 1) {
} else {
this.inputs[i + 1].focus();
}
} else {
if (event.key === 'Backspace') {
if (i === 0) {
} else {
if (this.bol !== 1) {
this.bol++;
} else {
word.words[i].selected = false;
this.bol = 0;
this.inputs[i - 1].focus();
}
}
}
}
}
}
}
}
this.item[key] = e.url; select(i, num) {
this.save(); const word = _.get(this.item, `contentObj.wordnum[${num}].words[${i}]`);
if (word.value !== '') {
word.selected = !word.selected;
this.updateVocabulary();
}
} }
AddWord() {
this.words = [];
for (let i = 0; i < 15; i++) {
this.words.push({
value: '',
selected: false
});
}
this.item.contentObj.wordnum.push({
words: this.words,
spelling_audio: '',
pic_id: ''
});
}
DeletWord(num) {
this.item.contentObj.wordnum.splice(num, 1);
this.updateVocabulary();
}
/** /**
* 储存数据 * 储存数据
*/ */
......
import {Pipe, PipeTransform} from '@angular/core'; import {Pipe, PipeTransform} from '@angular/core';
// import {ElectronUtil} from '../util/ElectronUtil';
declare const APP_PATH;
// const isInElectron = localStorage.getItem('electron');
@Pipe({ @Pipe({
name: 'backgroundImage' name: 'backgroundImage'
}) })
export class BackgroundImagePipe implements PipeTransform { export class BackgroundImagePipe implements PipeTransform {
transform(value: any, coursewareSid?: string) { transform(value: any) {
// const ret = value ? `url(${value})` : ''; return `url(${value})`;
const ret = value ? `url(${value})` : '';
return ret;
// let ret = value > 0 ? `url(/api/media-resource/${value}/file)` : '';
// if (isInElectron && ElectronUtil.hasCached(coursewareSid, value)) {
// ret = `url(file://${APP_PATH}/courseware_cache/${coursewareSid}/${value})`;
// }
// return ret;
} }
} }
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({
name: 'brLineBreaker'
})
export class BrLineBreakerPipe implements PipeTransform {
transform(value: any, args?: any): any {
return value ? value.replace(/\n/g, '<br />') : '';
}
}
...@@ -2,25 +2,17 @@ import {Pipe, PipeTransform} from '@angular/core'; ...@@ -2,25 +2,17 @@ import {Pipe, PipeTransform} from '@angular/core';
// import {ElectronUtil} from '../util/ElectronUtil'; // import {ElectronUtil} from '../util/ElectronUtil';
declare const APP_PATH; declare const APP_PATH;
// const isInElectron = localStorage.getItem('electron'); const isInElectron = localStorage.getItem('electron');
@Pipe({ @Pipe({
name: 'resource' name: 'resource'
}) })
export class ResourcePipe implements PipeTransform { export class ResourcePipe implements PipeTransform {
transform(pic_url: any, coursewareSid?: string): string { transform(value: any, coursewareSid?: string): string {
// return pic_url; return value ? `/api/media-resource/${value}/file` : '';
if (pic_url && typeof pic_url === 'object') { // if (isInElectron && ElectronUtil.hasCached(coursewareSid, value)) {
return pic_url; // ret = `file://${APP_PATH}/courseware_cache/${coursewareSid}/${value}`;
}
// console.log('resource', pic_url)
return `${pic_url}?t=${Math.random()}`;
// let ret = value ? `/api/resource/${value}/file` : '';
// let ret = res_id ? `/resource/audio/${res_id}` : '';
// if (isInElectron && ElectronUtil.hasCached(coursewareSid, res_id)) {
// ret = `file://${APP_PATH}/courseware_cache/${coursewareSid}/${res_id}`;
// } // }
// return ret; // return ret;
} }
......
.game-container {
width: 100%;
height: 100%;
background: #ffffff;
background-size: cover;
}
#canvas {
}
@font-face
{
font-family: 'BRLNSDB';
src: url("../../assets/font/BRLNSDB.TTF") ;
}
<div class="game-container" #wrap> <div class="content">
<canvas id="canvas" #canvas></canvas> <div class="monkey-move">
<div class="tree">
<div>
<div class="trunk"></div>
</div>
<div class="leaves" #leavesNode>
<div class="leaf" *ngFor="let le of otherwordnum" >
<img [class]="le.rigof ? 'on':'off'" src="../../assets/spelling/leaves.png" alt="">
</div>
</div>
<div class="mo" #monkey>
<div class="monkey"><img src="../../assets/spelling/monkey.png" alt=""></div>
</div>
</div>
<div class="house">
<img src="../../assets/spelling/house.png" alt="">
</div>
</div>
<div class="spelling" *ngIf="words.length !== 0">
<div class="word">
<div *ngFor="let ss of wordnum;let b = index">
<div *ngFor="let it of words; let i = index"
[class]="b!==num? 'disappear':''">
<div *ngIf="it.selected"
[class]="!it.text ? 'blank' : (it.text === it.value ? 'blank proper' : 'blank mistake')"
(click)="onHandleChoose(i)">
<p>{{it.text}}</p>
</div>
<div *ngIf="!it.selected">
<p>{{it.value}}</p>
</div>
</div>
</div>
</div>
</div>
<div class="img-key" *ngIf="words.length !== 0">
<div class="img-audio k-16-9">
<div class="k-full-fill">
<img (click)="playSpellingAudio()" [src]="wordnum[num].pic_id" alt=""
(dragstart)="false;$event.preventDefault();">
</div>
</div>
<div class="word">
<div *ngFor="let item of letter;" (click)="add(item)">
<p>{{item}}</p>
</div>
</div>
</div>
</div> </div>
.content {
text-align: center;
width: 100%;
padding: 0 2em;
height: 100%;
justify-content: space-between;
background-color: #f3fdfe;
.spelling {
.word {
display: flex;
padding-bottom: 4vh;
font-family: "ChalkboardSE-Regular", "Helvetica Neue", Helvetica, Arial, sans-serif;
div {
display: inherit
}
p {
display: block;
line-height: 8.4vh;
border-radius: 15%;
margin: 0.2vh;
font-weight: 900;
font-size: 7vh;
//background-color: #85144b;
}
.blank {
border: 2px solid;
margin-right: 0.1vh;
margin-top: auto;
margin-bottom: auto;
//margin: 0 1vh;
display: inline-block;
width: 8.4vh;
height: 8.4vh;
border-radius: 20%;
vertical-align: top;
//background-color: #00C0FF;
}
.proper {
border: 2px solid #66cc33;
background-color: #c0f88b5c;
}
.mistake {
border: 2px solid #ff9999;
background-color: #ffd7d1;
}
.disappear {
display: none;
}
}
}
.img-key {
// padding-top: 5%;
display: flex;
.img-audio {
width: 100vh;
border: 1px solid #d6d6d6;
border-radius: 1rem;
background-color: #fefefe;
margin-right: 1rem;
img {
width: 100%;
height: 100%;
object-fit: contain;
}
}
.word {
display: flex;
flex-wrap: wrap;
div {
display: inline-block;
width: 6vh;
height: 6vh;
border-radius: 15%;
margin: 0.4vh;
vertical-align: top;
border: 2px solid;
:hover {
background-color: black;
color: white;
}
p {
display: block;
line-height: 5.5vh;
font-weight: 700;
font-size: 4vh;
}
}
}
}
.monkey-move {
padding-top: 10%;
display: flex;
.tree {
margin-left: 15%;
width: 85%;
position: relative;
.trunk {
width: 140%;
height: 1rem;
background-color: #ccffcc;
margin-left: -20%;
}
.monkey {
z-index: 2;
img {
width: 15vh;
height: 15vh;
margin-top: -1.9rem;
}
}
.mo {
margin-left: -15%;
transition: all 2s;
position: absolute;
}
.leaf {
margin-top: -4%;
// float: left;
width: 100%;
height: 100%;
border-radius: 100%;
margin-top: -0.5rem;
z-index: 1;
}
.leaves {
display: flex;
margin-top: -5%;
}
.on {
width: 6vh;
height: 6vh;
opacity: 1;
}
.off {
width: 6vh;
height: 6vh;
opacity: 0;
transition: all 2s;
}
}
}
.house {
// margin-right: -10%;
margin-top: -5%;
width: 50%;
height: 50%;
img {
width: 50%;
height: 100%;
}
}
}
import {Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener} from '@angular/core'; import { Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener, OnChanges, AfterViewInit } 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';
@Component({ @Component({
selector: 'app-play', selector: 'app-play',
templateUrl: './play.component.html', templateUrl: './play.component.html',
styleUrls: ['./play.component.css'] styleUrls: ['./play.component.scss']
}) })
export class PlayComponent implements OnInit, OnDestroy { export class PlayComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit {
@ViewChild('canvas', {static: true }) canvas: ElementRef;
@ViewChild('wrap', {static: true }) wrap: ElementRef;
// 数据 // 数据
data; data;
saveKey = 'spelling';
ctx;
canvasWidth = 1280; // canvas实际宽度 letter: any[];
canvasHeight = 720; // canvas实际高度 blankindex = [];
num: number;
canvasBaseW = 1280; // canvas 资源预设宽度 Spelling_audio = new Audio();
canvasBaseH = 720; // canvas 资源预设高度 wordnum = [];
otherwordnum = [];
mx; // 点击x坐标 @ViewChild('leavesNode', {static: true })
my; // 点击y坐标 leavesNode: ElementRef;
@ViewChild('monkey', {static: true })
mo: ElementRef;
// 资源 monkey: any;
rawImages = new Map(res); leaf: any;
rawAudios = new Map(resAudio); words = [];
index: number;
images = new Map(); indexnum: number;
left: any;
animationId: any; rightAudio = new Audio();
winResizeEventStream = new Subject(); wrongAudio = new Audio();
isnull: any;
audioObj = {};
constructor() {
renderArr; this.num = 0;
mapScale = 1; this.indexnum = 0;
this.index = 0;
canvasLeft; this.letter = 'abcdefghijklmnopqrstuvwxyz'.split('');
canvasTop; this.rightAudio.src = 'assets/right.mp3';
this.rightAudio.load();
saveKey = 'test_0011'; this.wrongAudio.src = 'assets/wrong.mp3';
this.wrongAudio.load();
btnLeft;
btnRight;
pic1;
pic2;
canTouch = true;
curPic;
@HostListener('window:resize', ['$event'])
onResize(event) {
this.winResizeEventStream.next();
} }
ngOnInit() { ngOnInit() {
this.data = {
this.data = {}; contentObj: {
wordnum: [{
pic_id: "assets/spelling/monkey.png",
rigof: true,
spelling_audio: "assets/right.mp3",
words: [
{value: "m", selected: false},
{value: "o", selected: true, istrue: false, text: ""},
{value: "n", selected: true, istrue: false, text: ""},
{value: "k", selected: false},
{value: "e", selected: false},
{value: "y", selected: false}
]
}]
}
};
// 获取数据 // 获取数据
const getData = (<any> window).courseware.getData; const getData = ( window as any).courseware.getData;
getData((data) => { getData((data) => {
if (data && typeof data === 'object') {
if (data && typeof data == 'object') {
this.data = data; this.data = data;
} }
// console.log('data:' , data); this.init();
window["air"].hideAirClassLoading(this.saveKey, this.data)
// 初始化 各事件监听
this.initListener();
// 若无数据 则为预览模式 需要填充一些默认数据用来显示
this.initDefaultData();
// 初始化 音频资源
this.initAudio();
// 初始化 图片资源
this.initImg();
// 开始预加载资源
this.load();
}, this.saveKey); }, this.saveKey);
} }
ngOnDestroy() { ngOnDestroy() {
window['curCtx'] = null;
window.cancelAnimationFrame(this.animationId);
} }
ngOnChanges(data) {
load() {
// 预加载资源
this.loadResources().then(() => {
window["air"].hideAirClassLoading(this.saveKey, this.data);
this.init();
this.update();
});
}
init() {
this.initCtx();
this.initData();
this.initView();
}
initCtx() {
this.canvasWidth = this.wrap.nativeElement.clientWidth;
this.canvasHeight = this.wrap.nativeElement.clientHeight;
this.canvas.nativeElement.width = this.wrap.nativeElement.clientWidth;
this.canvas.nativeElement.height = this.wrap.nativeElement.clientHeight;
this.ctx = this.canvas.nativeElement.getContext('2d');
this.canvas.nativeElement.width = this.canvasWidth;
this.canvas.nativeElement.height = this.canvasHeight;
window['curCtx'] = this.ctx;
}
updateItem(item) {
if (item) {
item.update();
}
} }
updateArr(arr) { ngAfterViewInit() {
if (!arr) {
return;
}
for (let i = 0; i < arr.length; i++) {
arr[i].update(this);
}
} }
init(){
if (this.data.contentObj.wordnum === undefined) {
this.wordnum = [{
pic_id: '',
}];
this.otherwordnum = [];
initListener() { this.isnull = false;
} else {
this.winResizeEventStream this.isnull = true;
.pipe(debounceTime(500)) this.wordnum = [...this.data.contentObj.wordnum];
.subscribe(data => { this.otherwordnum = [...this.data.contentObj.wordnum];
this.renderAfterResize(); this.load();
this.otherwordnum.forEach((value) => {
value.rigof = true;
}); });
this.monkey = this.mo.nativeElement;
this.leaf = this.leavesNode.nativeElement.children;
// --------------------------------------------- this.monkey.style.left = '0px';
const setParentOffset = () => { this.left = Math.abs(this.monkey.offsetLeft);
const rect = this.canvas.nativeElement.getBoundingClientRect();
this.canvasLeft = rect.left;
this.canvasTop = rect.top;
};
const setMxMyByTouch = (event) => {
if (event.touches.length <= 0) {
return;
}
if (this.canvasLeft == null) {
setParentOffset();
}
this.mx = event.touches[0].pageX - this.canvasLeft;
this.my = event.touches[0].pageY - this.canvasTop;
};
const setMxMyByMouse = (event) => {
this.mx = event.offsetX;
this.my = event.offsetY;
};
// ---------------------------------------------
let firstTouch = true;
const touchDownFunc = (e) => {
if (firstTouch) {
firstTouch = false;
removeMouseListener();
}
setMxMyByTouch(e);
this.mapDown(e);
};
const touchMoveFunc = (e) => {
setMxMyByTouch(e);
this.mapMove(e);
};
const touchUpFunc = (e) => {
setMxMyByTouch(e);
this.mapUp(e);
};
const mouseDownFunc = (e) => {
if (firstTouch) {
firstTouch = false;
removeTouchListener();
}
setMxMyByMouse(e);
this.mapDown(e);
};
const mouseMoveFunc = (e) => {
setMxMyByMouse(e);
this.mapMove(e);
};
const mouseUpFunc = (e) => {
setMxMyByMouse(e);
this.mapUp(e);
};
const element = this.canvas.nativeElement;
const addTouchListener = () => {
element.addEventListener('touchstart', touchDownFunc);
element.addEventListener('touchmove', touchMoveFunc);
element.addEventListener('touchend', touchUpFunc);
element.addEventListener('touchcancel', touchUpFunc);
};
const removeTouchListener = () => {
element.removeEventListener('touchstart', touchDownFunc);
element.removeEventListener('touchmove', touchMoveFunc);
element.removeEventListener('touchend', touchUpFunc);
element.removeEventListener('touchcancel', touchUpFunc);
};
const addMouseListener = () => {
element.addEventListener('mousedown', mouseDownFunc);
element.addEventListener('mousemove', mouseMoveFunc);
element.addEventListener('mouseup', mouseUpFunc);
};
const removeMouseListener = () => {
element.removeEventListener('mousedown', mouseDownFunc);
element.removeEventListener('mousemove', mouseMoveFunc);
element.removeEventListener('mouseup', mouseUpFunc);
};
addMouseListener();
addTouchListener();
}
playAudio(key, now = false, callback = null) {
const audio = this.audioObj[key];
if (audio) {
if (now) {
audio.pause();
audio.currentTime = 0;
}
if (callback) {
audio.onended = () => {
callback();
};
}
audio.play();
} }
} }
load() {
this.words = _.get(this.data.contentObj.wordnum[this.num], 'words', []);
loadResources() { this.words.forEach((value, index) => {
const pr = []; if (value.selected === true) {
this.rawImages.forEach((value, key) => {// 预加载图片 value.istrue = false;
value.text = '';
const p = this.preload(value) this.blankindex.push(index);
.then(img => {
this.images.set(key, img);
})
.catch(err => console.log(err));
pr.push(p);
});
this.rawAudios.forEach((value, key) => {// 预加载音频
const a = this.preloadAudio(value)
.then(() => {
// this.images.set(key, img);
})
.catch(err => console.log(err));
pr.push(a);
});
return Promise.all(pr);
}
preload(url) {
return new Promise((resolve, reject) => {
const img = new Image();
// img.crossOrigin = "anonymous";
img.onload = () => resolve(img);
img.onerror = reject;
img.src = url;
});
}
preloadAudio(url) {
return new Promise((resolve, reject) => {
const audio = new Audio();
audio.oncanplay = (a) => {
resolve();
};
audio.onerror = () => {
reject();
};
audio.src = url;
audio.load();
});
}
renderAfterResize() {
this.canvasWidth = this.wrap.nativeElement.clientWidth;
this.canvasHeight = this.wrap.nativeElement.clientHeight;
this.init();
}
checkClickTarget(target) {
const rect = target.getBoundingBox();
if (this.checkPointInRect(this.mx, this.my, rect)) {
return true;
}
return false;
}
getWorlRect(target) {
let rect = target.getBoundingBox();
if (target.parent) {
const pRect = this.getWorlRect(target.parent);
rect.x += pRect.x;
rect.y += pRect.y;
}
return rect;
}
checkPointInRect(x, y, rect) {
if (x >= rect.x && x <= rect.x + rect.width) {
if (y >= rect.y && y <= rect.y + rect.height) {
return true;
} }
} });
return false; this.index = this.blankindex[this.indexnum];
} }
add(i) {
if (!this.isnull) {
return 0;
addUrlToAudioObj(key, url = null, vlomue = 1, loop = false, callback = null) {
const audioObj = this.audioObj;
if (url == null) {
url = key;
} }
this.words[this.index].text = i;
this.rawAudios.set(key, url); if (i === this.words[this.index].value) {
this.words[this.index].istrue = true;
const audio = new Audio(); this.indexnum++;
audio.src = url; } else {
audio.load(); this.words[this.index].istrue = false;
audio.loop = loop; this.wrongAudio.play();
audio.volume = vlomue;
audioObj[key] = audio;
if (callback) {
audio.onended = () => {
callback();
};
} }
} if (this.indexnum < this.blankindex.length) {
} else {
addUrlToImages(url) { this.indexnum = 0;
this.rawImages.set(url, url);
}
// ======================================================编写区域==========================================================================
/**
* 添加默认数据 便于无数据时的展示
*/
initDefaultData() {
if (!this.data.pic_url) {
this.data.pic_url = 'assets/play/default/pic.jpg';
this.data.pic_url_2 = 'assets/play/default/pic.jpg';
}
}
/**
* 添加预加载图片
*/
initImg() {
this.addUrlToImages(this.data.pic_url);
this.addUrlToImages(this.data.pic_url_2);
}
/**
* 添加预加载音频
*/
initAudio() {
// 音频资源
this.addUrlToAudioObj(this.data.audio_url);
this.addUrlToAudioObj(this.data.audio_url_2);
// 音效
this.addUrlToAudioObj('click', this.rawAudios.get('click'), 0.3);
}
/**
* 初始化数据
*/
initData() {
const sx = this.canvasWidth / this.canvasBaseW;
const sy = this.canvasHeight / this.canvasBaseH;
const s = Math.min(sx, sy);
this.mapScale = s;
// this.mapScale = sx;
// this.mapScale = sy;
this.renderArr = [];
}
/**
* 初始化试图
*/
initView() {
this.initPic();
this.initBottomPart();
}
initBottomPart() {
const btnLeft = new MySprite();
btnLeft.init(this.images.get('btn_left'));
btnLeft.x = this.canvasWidth - 150 * this.mapScale;
btnLeft.y = this.canvasHeight - 100 * this.mapScale;
btnLeft.setScaleXY(this.mapScale);
this.renderArr.push(btnLeft);
this.btnLeft = btnLeft;
const btnRight = new MySprite();
btnRight.init(this.images.get('btn_right'));
btnRight.x = this.canvasWidth - 50 * this.mapScale;
btnRight.y = this.canvasHeight - 100 * this.mapScale;
btnRight.setScaleXY(this.mapScale);
this.renderArr.push(btnRight);
this.btnRight = btnRight;
}
initPic() {
const maxW = this.canvasWidth * 0.7;
const pic1 = new MySprite();
pic1.init(this.images.get(this.data.pic_url));
pic1.x = this.canvasWidth / 2;
pic1.y = this.canvasHeight / 2;
pic1.setScaleXY(maxW / pic1.width);
this.renderArr.push(pic1);
this.pic1 = pic1;
const label1 = new Label();
label1.text = this.data.text;
label1.textAlign = 'center';
label1.fontSize = 50;
label1.fontName = 'BRLNSDB';
label1.fontColor = '#ffffff';
pic1.addChild(label1);
const pic2 = new MySprite();
pic2.init(this.images.get(this.data.pic_url_2));
pic2.x = this.canvasWidth / 2 + this.canvasWidth;
pic2.y = this.canvasHeight / 2;
pic2.setScaleXY(maxW / pic2.width);
this.renderArr.push(pic2);
this.pic2 = pic2;
this.curPic = pic1;
}
btnLeftClicked() {
this.lastPage();
}
btnRightClicked() {
this.nextPage();
}
lastPage() {
if (this.curPic == this.pic1) {
return;
} }
let truenum = 0;
this.canTouch = false; this.blankindex.forEach((value) => {
if (this.words[value].istrue === true) {
const moveLen = this.canvasWidth; truenum++;
tweenChange(this.pic1, {x: this.pic1.x + moveLen}, 1); }
tweenChange(this.pic2, {x: this.pic2.x + moveLen}, 1, () => {
this.canTouch = true;
this.curPic = this.pic1;
}); });
} if (truenum === this.blankindex.length) {
const step = this.leaf[this.num].offsetLeft + this.leaf[this.num].clientWidth / 2 - this.monkey.clientWidth / 2 + this.left;
nextPage() { this.monkey.style.left = step.toString() + 'px';
this.rightAudio.play();
if (this.curPic == this.pic2) { if (this.num + 1 >= this.wordnum.length) {
return; setTimeout(() => {
this.blankindex.forEach((value) => {
this.words[value].istrue = false;
for (let s = 0; s < this.wordnum.length; s++) {
this.otherwordnum[s].rigof = false;
}
});
}, 1500);
this.indexnum = 0;
} else {
setTimeout(() => {
this.num++;
this.indexnum = 0;
this.blankindex.length = 0;
this.load();
this.otherwordnum[this.num - 1].rigof = false;
}, 1500);
}
} }
this.index = this.blankindex[this.indexnum];
this.canTouch = false;
const moveLen = this.canvasWidth;
tweenChange(this.pic1, {x: this.pic1.x - moveLen}, 1);
tweenChange(this.pic2, {x: this.pic2.x - moveLen}, 1, () => {
this.canTouch = true;
this.curPic = this.pic2;
});
} }
pic1Clicked() { playSpellingAudio() {
this.playAudio(this.data.audio_url); if (this.data.contentObj && this.data.contentObj.wordnum[this.num].spelling_audio) {
} this.Spelling_audio.src = this.data.contentObj.wordnum[this.num].spelling_audio;
this.Spelling_audio.load();
pic2Clicked() { this.Spelling_audio.play();
this.playAudio(this.data.audio_url_2);
}
mapDown(event) {
if (!this.canTouch) {
return;
} }
if ( this.checkClickTarget(this.btnLeft) ) {
this.btnLeftClicked();
return;
}
if ( this.checkClickTarget(this.btnRight) ) {
this.btnRightClicked();
return;
}
if ( this.checkClickTarget(this.pic1) ) {
this.pic1Clicked();
return;
}
if ( this.checkClickTarget(this.pic2) ) {
this.pic2Clicked();
return;
}
} }
mapMove(event) { onHandleChoose(index) {
this.index = index;
} this.blankindex.forEach((value, indexs) => {
if (value === this.index) {
mapUp(event) { this.indexnum = indexs;
}
} });
update() {
// ----------------------------------------------------------
this.animationId = window.requestAnimationFrame(this.update.bind(this));
// 清除画布内容
this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
// tween 更新动画
TWEEN.update();
// ----------------------------------------------------------
this.updateArr(this.renderArr);
} }
} }
@mixin hide-overflow-text {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
@mixin k-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@mixin k-img-bg {
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
@mixin hide-overflow-text {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
@mixin k-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@mixin k-img-bg {
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
...@@ -3,6 +3,8 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; ...@@ -3,6 +3,8 @@ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module'; import { AppModule } from './app/app.module';
import { environment } from './environments/environment'; import { environment } from './environments/environment';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
if (environment.production) { if (environment.production) {
enableProdMode(); enableProdMode();
......
/* You can add global styles to this file, and also import other style files */
/* You can add global styles to this file, and also import other style files */
@mixin hide-overflow-text {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
@mixin k-no-select {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
@mixin k-img-bg {
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment