Commit 6097235f authored by Tt's avatar Tt

题目调整完成

parent 761b51d8
import { ApplicationRef, ChangeDetectorRef, ElementRef, ViewChild } from "@angular/core";
export class ComponentBase {
// 储存数据用
saveKey = "";
// 储存对象
item: any = {};
ngOnChanges() { }
ngOnDestroy() { }
constructor(private appRef: ApplicationRef, private changeDetectorRef: ChangeDetectorRef) { }
ngOnInit() {
// 获取存储的数据
(<any>window).courseware.getData((data) => {
if (data) {
this.item = data;
this.itemStr = JSON.stringify(this.item, null, 4).trim();
}
this.init();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
this.refresh();
}, this.saveKey);
}
@ViewChild("itemTextarea", { static: true }) itemTextarea: ElementRef;
copyData() {
this.itemTextarea.nativeElement.select();
document.execCommand("copy");
}
/**
* 储存图片数据
* @param e
*/
// onAssetUploadSuccess(e: any, ...key: Array<string>) {
// let item = this.item;
// for (let i = 0; i < key.length; i++) {
// if (i + 1 == key.length) {
// if (key[i] == "audio") {
// let sp = e.url.split(".mp3");
// let u = sp[0] + "_l.mp3";
// item[key[i]] = u;
// item["audioName"] = e.name || "";
// } else {
// item[key[i]] = e.url;
// }
// this.save();
// return;
// }
// item = item[key[i]];
// }
// }
/**
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, key, it = this.item) {
it[key] = e.url;
this.save();
}
/**
* 储存音频数据
* @param e
*/
onAudioUploadSuccess(e, key, it = this.item, audioName) {
let url = e.url;
it[key] = url;
it[audioName] = e.audioName || "";
console.log(JSON.stringify(e));
this.save();
}
save() {
(<any>window).courseware.setData(this.item, null, this.saveKey);
this.itemStr = JSON.stringify(this.item, null, 4).trim();
this.refresh();
console.log('this.item = ' + JSON.stringify(this.item));
}
itemStr = "";
load() {
this.itemStr = this.itemTextarea.nativeElement.value;
if (this.isJSON(this.itemStr)) {
this.item = JSON.parse(this.itemStr);
this.init();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
this.refresh();
}
}
isJSON(str) {
if (typeof str == 'string') {
try {
var obj = JSON.parse(str);
if (typeof obj == 'object' && obj) {
return true;
}
return false;
} catch (e) {
return false;
}
}
return false;
}
/**
* 刷新 渲染页面
*/
refresh() {
setTimeout(() => {
this.appRef.tick();
}, 1);
}
init() { }
}
...@@ -33,3 +33,30 @@ ...@@ -33,3 +33,30 @@
padding: 10px; padding: 10px;
margin: 10px; margin: 10px;
} }
.button-right {
border-style: dotted;
border-color: rgb(42, 142, 72);
width: 100px;
height: 50px;
color: rgb(42, 142, 72);
background-color: white;
}
.button-wrong {
border-style: dotted;
border-color: rgb(180, 0, 0);
width: 100px;
height: 50px;
color: rgb(180, 0, 0);
background-color: white;
}
.button-disable {
border-style: dotted;
border-color: black;
width: 100px;
height: 50px;
color: black;
background-color: white;
}
\ No newline at end of file
This diff is collapsed.
import { import { Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef } from '@angular/core';
Component, import { JsonPipe } from '@angular/common';
EventEmitter, import { ComponentBase } from './ComponentBase';
Input,
OnDestroy,
OnChanges,
OnInit,
Output,
ApplicationRef,
ChangeDetectorRef,
} from "@angular/core";
import { JsonPipe } from "@angular/common";
import { log } from "ng-zorro-antd";
@Component({ @Component({
selector: "app-form", selector: 'app-form',
templateUrl: "./form.component.html", templateUrl: './form.component.html',
styleUrls: ["./form.component.css"], styleUrls: ['./form.component.css']
}) })
export class FormComponent implements OnInit, OnChanges, OnDestroy { export class FormComponent extends ComponentBase implements OnInit, OnChanges, OnDestroy {
// 储存数据用 // 储存数据用
saveKey = "ssiwb2501"; saveKey = "ssapp2501";
// 储存对象 // 储存对象
item; item: any = {
type = 0; score: 0,
dataType; title: '',
questionText: "",
// 样式选项 questionType: "read",
styles = [ questionTextAudio: "",
{ id: 0, name: '样式1', image: 'http://staging-teach.cdn.ireadabc.com/b41bf63c28c65bc46c3a1ae77e70cb75.png' }, bgAudio: "",
{ id: 1, name: '样式2', image: 'http://staging-teach.cdn.ireadabc.com/49f2cb0d2b76bf866788a2c0244af69e.png' } questions: [],
]; };
// 字母索引数组 // item: any = {
singleLetterIndexes = [0, 1, 2, 3, 4]; // 对应character_0到character_4 // title: '幸运大转盘',
doubleLetterIndexes = [0, 1, 2, 3, 4]; // 对应character_00到character_44 // questionText: "亲爱的小玩家,游戏马上就要开始啦!请动动手指转动转盘,当转盘停止,注意观察指针指向的魔法图片,并大声说出魔法咒语,魔法咒语正确,你就可以获得一张魔法卡牌。 游戏结束后,根据获得的魔法卡牌数量,你将获得相应的能量石奖励!开始挑战吧!",
// questionTextAudio: "http://staging-teach.cdn.ireadabc.com/18ebee93b3eabcd55649a01366431af7.mp3",
constructor( // questions: [],
private appRef: ApplicationRef, // };
private changeDetectorRef: ChangeDetectorRef
) {} isVisible = false;
deleteTitle = "是否删除题目";
createShell() { deleteCallback = function () { };
this.item.wordList.push({ openDelete(title, callback) {
word: "", this.deleteCallback = callback;
audio: "", this.deleteTitle = title;
backWord: "", this.isVisible = true;
backWordAudio: "",
});
this.save();
}
removeShell(idx) {
this.item.wordList.splice(idx, 1);
this.save();
}
ngOnInit() {
this.item = { title: "", audio_title: "" };
this.dataType = {
single: { words: "", wordArr: [] },
single_audio: "",
single_show: true,
character_00: { words: "", wordArr: [] },
character_11: { words: "", wordArr: [] },
character_22: { words: "", wordArr: [] },
character_33: { words: "", wordArr: [] },
character_44: { words: "", wordArr: [] },
character_0: { words: "", wordArr: [] },
character_1: { words: "", wordArr: [] },
character_2: { words: "", wordArr: [] },
character_3: { words: "", wordArr: [] },
character_4: { words: "", wordArr: [] },
character_0_show: true,
character_1_show: true,
character_2_show: true,
character_3_show: true,
character_4_show: true,
character_00_show: true,
character_11_show: true,
character_22_show: true,
character_33_show: true,
character_44_show: true,
};
this.type = 0;
// 获取存储的数据
(<any>window).courseware.getData((data) => {
if (data) {
this.item = data;
}
this.init();
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
this.refresh();
}, this.saveKey);
}
ngOnChanges() {}
ngOnDestroy() {}
init() {
if (this.item.type) {
this.type = this.item.type;
}
// 加载数据
if (this.item.dataType) {
this.dataType = this.item.dataType;
}
}
/**
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, key) {
this.item[key] = e.url;
this.save();
} }
handleCancel() {
/** this.isVisible = false;
* 储存音频数据
* @param e
*/
onAudioUploadSuccess(e, key) {
this.item[key] = e.url;
this.save();
} }
handleOk() {
onAudioUploadSuccessByItem(e, it, key) { this.deleteCallback && this.deleteCallback();
it[key] = e.url; this.handleCancel();
this.save();
} }
onWordAudioUploadSuccess(e, idx) { addQuestion() {
this.item.wordList[idx].audio = e.url; this.item.questions.push({
type: 'img',
imgSize: 'big', // 默认大图片
audio: '',
image: '',
time: null,
// word: '',
audioName: "",
});
this.save(); this.save();
} }
onBackWordAudioUploadSuccess(e, idx) { removeQuestion(idx) {
this.item.wordList[idx].backWordAudio = e.url; this.openDelete("确定删除题目?", () => {
this.save(); this.item.questions.splice(idx, 1);
this.save();
})
} }
copyQuestion(idx) {
onUpWordClicked(key, index) { let data = this.item.questions[idx]
if (this.dataType[key].wordArr[index].type == "normal") { this.item.questions.push(JSON.parse(JSON.stringify(data)));
this.dataType[key].wordArr[index].type = "red";
} else {
this.dataType[key].wordArr[index].type = "normal";
}
this.save(); this.save();
} }
deleteBgAudio() {
onSaveWord(key) { this.item.bgAudio = "";
// console.log(this.dataType); this.item.audioBgName = "";
let res = [];
let words = this.dataType[key].words.split("");
for (let w of words) {
res.push({ word: w, type: "normal" });
}
this.dataType[key].wordArr = res;
this.save(); this.save();
} }
// addOption(idx) {
/** // if (this.item.questions[idx].options.length == 4) return;
* 储存数据 // this.item.questions[idx].options.push({
*/ // text: '',
save() { // audio: '',
this.item.type = this.type; // image: '',
this.item.dataType = this.dataType; // word: '',
// });
(<any>window).courseware.setData(this.item, null, this.saveKey); // this.save();
// }
this.refresh();
console.log("this.item = " + JSON.stringify(this.item)); // removeOption(idx, n) {
} // this.openDelete("确定删除选项?", () => {
// this.item.questions[idx].options.splice(n, 1);
/** // this.save();
* 刷新 渲染页面 // })
*/ // }
refresh() { ngChange() {
setTimeout(() => {
this.appRef.tick();
}, 1);
}
onSetType() {
this.save(); this.save();
} }
} }
...@@ -342,8 +342,8 @@ export class PlayComponent implements OnInit, OnDestroy { ...@@ -342,8 +342,8 @@ export class PlayComponent implements OnInit, OnDestroy {
initBackground() { initBackground() {
// 创建背景元素 // 创建背景元素
var element = this.g_cartoon.createCartoonElement(`background`, "MySprite") var element = this.g_cartoon.createCartoonElement(`background`, "MySprite")
// 初始化背景图像,使用resources.js中的bg资源 // 初始化背景图像,使用resources.js中的bei_jing资源
element.ref.init(this.g_cartoon.images.get("bg")); element.ref.init(this.g_cartoon.images.get("bei_jing"));
// 计算背景缩放比例,确保背景能够覆盖整个画布 // 计算背景缩放比例,确保背景能够覆盖整个画布
// 使用g_mapScale作为基础缩放比例,确保与其他元素保持一致的缩放 // 使用g_mapScale作为基础缩放比例,确保与其他元素保持一致的缩放
......
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