Commit 8e43efc7 authored by liujiangnan's avatar liujiangnan

feat: 迁移完成

parent 8a51c964
......@@ -30,7 +30,10 @@
],
"styles": [
"./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": []
},
......@@ -128,5 +131,8 @@
}
}
},
"defaultProject": "ng-template-generator"
}
"defaultProject": "ng-template-generator",
"cli": {
"analytics": "492245b4-c782-4ff8-9a30-b89188f9b56f"
}
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ import {AudioRecorderComponent} from './common/audio-recorder/audio-recorder.com
import { FontAwesomeModule, FaIconLibrary } from '@fortawesome/angular-fontawesome';
import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons';
import { BrLineBreakerPipe } from './pipes/br-line-breaker.pipe';
registerLocaleData(zh);
......@@ -36,6 +37,7 @@ registerLocaleData(zh);
AudioRecorderComponent,
UploadImageWithPreviewComponent,
BackgroundImagePipe,
BrLineBreakerPipe,
ResourcePipe,
TimePipe,
UploadVideoComponent,
......
@import '../style/common_mixin.css';
.model-content {
width: 100%;
height: 100%;
}
<div class="model-content">
<div class="all-courseware-container">
<div class="courseware-container d-flex" style="margin-bottom: 1rem;">
<div class="col-4" *ngFor="let i of [0,1,2]">
<app-upload-image-with-preview
[picUrl]="item.contentObj.pics[i].pic_id"
(imageUploaded)="onImageUploadSuccess($event,i)"
></app-upload-image-with-preview>
<label nz-checkbox [ngModel]="item.contentObj.pics[i].is_right" (ngModelChange)="setRightAnswer($event,i)" class="right-answer">Right</label>
</div>
</div>
<div style="position: absolute; left: 200px; top: 100px; width: 800px;">
<div class="courseware-container d-flex" style="margin-bottom: 1rem;">
<div class="col-12">
<nz-input-group
nzSize="large"
[nzPrefix]="prefixTemplate" >
<input type="text" nz-input placeholder="Enter text"
(blur)="saveText($event)"
[(ngModel)]="item.contentObj.text ">
</nz-input-group>
<ng-template #prefixTemplate>
<i class="anticon anticon-edit" ></i>
</ng-template>
</div>
</div>
<input type="text" nz-input [(ngModel)]="item.text" (blur)="save()">
<div class="courseware-container d-flex">
<div class="col-12">
<app-upload-image-with-preview
[picUrl]="item.pic_url"
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')"
></app-upload-image-with-preview>
<app-audio-recorder
[audioUrl]="item.contentObj.audio_id"
(audioUploaded)="onAudioUploadSuccess($event)"
></app-audio-recorder>
</div>
<app-audio-recorder
[audioUrl]="item.audio_url"
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')"
></app-audio-recorder>
<app-custom-hot-zone></app-custom-hot-zone>
<app-upload-video></app-upload-video>
<app-lesson-title-config></app-lesson-title-config>
</div>
</div>
\ No newline at end of file
</div>
\ No newline at end of file
.all-courseware-container{
padding: 2rem;
}
\ No newline at end of file
......@@ -5,33 +5,43 @@ import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, Ap
@Component({
selector: 'app-form',
templateUrl: './form.component.html',
styleUrls: ['./form.component.css']
styleUrls: ['./form.component.scss']
})
export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 储存数据用
saveKey = "test_0011";
// 储存对象
_answer = {};
originItemTxt = '';
item;
saveKey = "listen-choose";
picIds: Array<number>;
constructor(private appRef: ApplicationRef,private changeDetectorRef: ChangeDetectorRef) {
constructor(private appRef: ApplicationRef,
private changeDetectorRef: ChangeDetectorRef) {
}
ngOnInit() {
this.item = {};
this.item = {
contentObj: {
pics: [
{pic_id: "",is_right: false},
{pic_id: "",is_right: false},
{pic_id: "",is_right: false}
],
text: "",
audio_id: ""
}
};
// 获取存储的数据
(<any> window).courseware.getData((data) => {
(window as any).courseware.getData((data) => {
if (data) {
this.item = data;
}
this.init();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
this.refresh();
......@@ -42,40 +52,55 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnChanges() {
this._answer = {};
}
ngOnDestroy() {
}
init() {
saveText(evt) {
// const txt = evt.target.value.trim();
if (!this.item.contentObj.text) {
return;
}
if (this.originItemTxt === this.item.contentObj.text.trim()) {
return;
}
this.originItemTxt = this.item.contentObj.text.trim()
// this.item.contentObj.text = txt;
this.save();
}
/**
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, key) {
this.item[key] = e.url;
this.save();
setRightAnswer = (val, i) => {
this._answer[i] = val;
if (this.item.contentObj.pics === undefined) {
this.item.contentObj.pics = [];
}
if (this.item.contentObj.pics[i] && this.item.contentObj.pics[i] instanceof Object) {
this.item.contentObj.pics[i].is_right = val;
} else {
this.item.contentObj.pics[i] = {pic_id: 0, is_right: val};
}
this.save();
}
/**
* 储存音频数据
* @param e
*/
onAudioUploadSuccess(e, key) {
this.item[key] = e.url;
onImageUploadSuccess(evt, i) {
if (this.item.contentObj.pics === undefined) {
this.item.contentObj.pics = [];
}
if (this.item.contentObj.pics[i] && this.item.contentObj.pics[i] instanceof Object) {
this.item.contentObj.pics[i].pic_id = evt.url;
} else {
this.item.contentObj.pics[i] = {pic_id: evt.url, is_right: this._answer[i]};
}
this.save();
// console.log('onImageUploadSuccess', evt, this.item);
}
onAudioUploadSuccess (evt) {
// console.log('onAudioUploadSuccess');
this.item.contentObj.audio_id = evt.url;
this.save();
}
/**
* 储存数据
*/
......
import {Pipe, PipeTransform} from '@angular/core';
// import {ElectronUtil} from '../util/ElectronUtil';
declare const APP_PATH;
// const isInElectron = localStorage.getItem('electron');
@Pipe({
name: 'backgroundImage'
})
export class BackgroundImagePipe implements PipeTransform {
transform(value: any, coursewareSid?: string) {
// const ret = value ? `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;
transform(value: any) {
return `url(${value})`;
}
}
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';
// import {ElectronUtil} from '../util/ElectronUtil';
declare const APP_PATH;
// const isInElectron = localStorage.getItem('electron');
const isInElectron = localStorage.getItem('electron');
@Pipe({
name: 'resource'
})
export class ResourcePipe implements PipeTransform {
transform(pic_url: any, coursewareSid?: string): string {
// return pic_url;
if (pic_url && typeof pic_url === 'object') {
return pic_url;
}
// 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}`;
transform(value: any, coursewareSid?: string): string {
return value ? `/api/media-resource/${value}/file` : '';
// if (isInElectron && ElectronUtil.hasCached(coursewareSid, value)) {
// ret = `file://${APP_PATH}/courseware_cache/${coursewareSid}/${value}`;
// }
// 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>
<canvas id="canvas" #canvas></canvas>
<div class="question-container">
<div class="img-bar" nz-row nzType="flex" nzJustify="space-around">
<div
class="img-wrap tip-border"
*ngFor="let item of _data"
nz-col
nzSpan="6"
[@tip-border]="item.state || 'none'"
(click)="handleTap($event, item);$event.preventDefault()"
>
<img *ngIf="item.pic_id" [src]="item.pic_id" alt="" (dragstart)="false;$event.preventDefault();" />
</div>
</div>
<div class="p-tool d-flex">
<div class="p-tool-left d-flex">
<div class="p-tool-btn" (click)="playAudio()">
<i class="anticon anticon-sound"></i>
</div>
<div class="p-tool-btn" (click)="lcDisplayText()">
<i class="anticon anticon-edit"></i>
</div>
</div>
<div class="p-tool-right flex-fill">
<div class="i-text">
{{_lc_text}}
</div>
</div>
</div>
</div>
$my_width: percentage(4/12);
.question-container {
display: flex;
flex-direction: column;
align-items: center;
height: 100%;
padding-top: 1rem;
background: url("./assets/listen_choose_bg.jpg");
background-position: center;
background-size: cover;
background-repeat: no-repeat;
.img-bar {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
.img-wrap {
margin: 1rem;
display: flex;
justify-content: center;
align-items: center;
background: #ffffff;
position: relative;
padding-bottom: 17%;
height: 0;
overflow: hidden;
border: 0.8rem solid #fff;
border-radius: 1rem;
transform: scale(1);
img {
width: 100%;
height: 100%;
object-fit: contain;
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
}
}
}
.p-tool {
width: 80%;
max-height: 15rem;
line-height: 5rem;
margin-top: 1rem;
&-left {
width: 11rem;
padding-left: 2rem;
background-color: white;
border-top-left-radius: 2.5rem;
border-bottom-left-radius: 2.5rem;
align-items: center;
.p-tool-btn {
width: 4rem;
font-size: 2.5rem;
color: #6cc1bb;
}
.p-tool-btn:active {
transform: scale(1.2);
}
}
&-right {
padding: 1rem;
background-color: white;
border-top-right-radius: 2.5rem;
border-bottom-right-radius: 2.5rem;
color: #6cc1bb;
font-size: 2.5rem;
margin-left: 0.2rem;
.i-text {
display: flex;
height: 100%;
justify-content: center;
align-items: center;
line-height: 1.4;
overflow-y: auto;
}
}
}
.input-group {
width: 80%;
margin: 2rem 0;
.ant-btn{
width: 6rem;
height: 6rem;
font-size: 2.5em;
}
.ant-input {
height: 6rem;
line-height: 3rem;
font-size: 2.5em;
outline: none;
text-align: center;
}
}
}
import {Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener} from '@angular/core';
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 { Component, ElementRef, ViewChild, OnInit, Input, OnDestroy, HostListener, OnChanges, AfterViewInit } from '@angular/core';
import * as _ from 'lodash';
import {trigger, state, transition, style, animate, keyframes} from '@angular/animations';
......@@ -18,662 +8,115 @@ import TWEEN from '@tweenjs/tween.js';
@Component({
selector: 'app-play',
templateUrl: './play.component.html',
styleUrls: ['./play.component.css']
styleUrls: ['./play.component.scss'],
animations: [
trigger('tip-border', [
state('right', style({'border': '0.8rem solid #1da299', 'border-radius': '1rem', 'transform': 'scale(1)'})),
state('none', style({'border': '0.8rem solid #fff', 'border-radius': '1rem', 'transform': 'scale(1)'})),
state('wrong', style({'border': '0.8rem solid #ff3333', 'border-radius': '1rem', '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'))
])
]
})
export class PlayComponent implements OnInit, OnDestroy {
@ViewChild('canvas', {static: true }) canvas: ElementRef;
@ViewChild('wrap', {static: true }) wrap: ElementRef;
export class PlayComponent implements OnInit, OnDestroy, OnChanges {
// 数据
data;
saveKey = 'listen-choose';
ctx;
canvasWidth = 1280; // canvas实际宽度
canvasHeight = 720; // canvas实际高度
canvasBaseW = 1280; // canvas 资源预设宽度
canvasBaseH = 720; // canvas 资源预设高度
mx; // 点击x坐标
my; // 点击y坐标
// 资源
rawImages = new Map(res);
rawAudios = new Map(resAudio);
images = new Map();
animationId: any;
winResizeEventStream = new Subject();
audioObj = {};
renderArr;
mapScale = 1;
canvasLeft;
canvasTop;
saveKey = 'test_0011';
isPlaying = false;
audio = new Audio();
rightAudio = new Audio();
wrongAudio = new Audio();
_lc_text = '';
_data = [];
btnLeft;
btnRight;
pic1;
pic2;
canTouch = true;
curPic;
@HostListener('window:resize', ['$event'])
onResize(event) {
this.winResizeEventStream.next();
constructor() {
this.rightAudio.src = 'assets/right.mp3';
this.rightAudio.load();
this.wrongAudio.src = 'assets/wrong.mp3';
this.wrongAudio.load();
}
ngOnInit() {
this.data = {};
this.data = {
contentObj: {
pics: [
{pic_id: "assets/common/2.png",is_right: false},
{pic_id: "assets/common/3.png",is_right: true},
{pic_id: "assets/common/4.png",is_right: false}
],
text: "banana",
audio_id: "assets/right.mp3"
}
};
// 获取数据
const getData = (<any> window).courseware.getData;
const getData = ( window as any).courseware.getData;
getData((data) => {
if (data && typeof data == 'object') {
if (data && typeof data === 'object') {
this.data = data;
}
// console.log('data:' , data);
// 初始化 各事件监听
this.initListener();
// 若无数据 则为预览模式 需要填充一些默认数据用来显示
this.initDefaultData();
// 初始化 音频资源
this.initAudio();
// 初始化 图片资源
this.initImg();
// 开始预加载资源
this.load();
this._data = _.get(this.data.contentObj, 'pics', []).filter(item => item && item.pic_id);
this._data.forEach(item => item.state = 'none');
this._lc_text = '';
if (this.data.contentObj && this.data.contentObj.audio_id) {
this.audio.src = this.data.contentObj.audio_id;
this.audio.load();
}
this.audio.pause();
this.audio.currentTime = 0;
this.isPlaying = false;
}, this.saveKey);
}
ngOnDestroy() {
window['curCtx'] = null;
window.cancelAnimationFrame(this.animationId);
this.audio.pause();
this.audio = null;
}
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) {
if (!arr) {
return;
}
for (let i = 0; i < arr.length; i++) {
arr[i].update(this);
}
}
initListener() {
this.winResizeEventStream
.pipe(debounceTime(500))
.subscribe(data => {
this.renderAfterResize();
});
// ---------------------------------------------
const setParentOffset = () => {
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;
playAudio() {
if (this.data.contentObj && this.data.contentObj.audio_id) {
if (this.isPlaying) {
this.audio.pause();
this.isPlaying = false;
} else {
this.audio.play();
this.isPlaying = true;
}
if (callback) {
audio.onended = () => {
callback();
};
}
audio.play();
}
}
loadResources() {
const pr = [];
this.rawImages.forEach((value, key) => {// 预加载图片
const p = this.preload(value)
.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();
});
lcDisplayText() {
this._lc_text = this.data.contentObj.text || '';
}
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;
handleTap(ev, item) {
if (item.is_right) {
item.state = 'right';
this.rightAudio.play();
} else {
item.state = 'wrong';
this.wrongAudio.play();
setTimeout(() => {
item.state = '';
}, 1500);
}
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;
}
addUrlToAudioObj(key, url = null, vlomue = 1, loop = false, callback = null) {
const audioObj = this.audioObj;
if (url == null) {
url = key;
}
this.rawAudios.set(key, url);
const audio = new Audio();
audio.src = url;
audio.load();
audio.loop = loop;
audio.volume = vlomue;
audioObj[key] = audio;
if (callback) {
audio.onended = () => {
callback();
};
}
}
addUrlToImages(url) {
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;
}
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.pic1;
});
}
nextPage() {
if (this.curPic == this.pic2) {
return;
}
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() {
this.playAudio(this.data.audio_url);
}
pic2Clicked() {
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) {
}
mapUp(event) {
}
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';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
if (environment.production) {
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