Commit 052f64cc authored by JinWei's avatar JinWei

Merge branch 'feature/jj_exam' into 'master'

feat: 剑桥考试模版

See merge request !1
parents 9f3a2900 ff02c222
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -28,11 +28,11 @@ ...@@ -28,11 +28,11 @@
"ali-oss": "^6.5.1", "ali-oss": "^6.5.1",
"compressing": "^1.5.0", "compressing": "^1.5.0",
"ng-zorro-antd": "^8.5.2", "ng-zorro-antd": "^8.5.2",
"node-sass": "4.0.0",
"rxjs": "~6.5.4", "rxjs": "~6.5.4",
"spark-md5": "^3.0.0", "spark-md5": "^3.0.0",
"tslib": "^1.10.0", "tslib": "^1.10.0",
"zone.js": "~0.10.2", "zone.js": "~0.10.2"
"node-sass": "4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@angular-devkit/build-angular": "~0.900.3", "@angular-devkit/build-angular": "~0.900.3",
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
"karma-jasmine": "~2.0.1", "karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.2", "karma-jasmine-html-reporter": "^1.4.2",
"protractor": "~5.4.3", "protractor": "~5.4.3",
"querystring": "^0.2.1",
"ts-node": "~8.3.0", "ts-node": "~8.3.0",
"tslint": "~5.18.0", "tslint": "~5.18.0",
"typescript": "~3.7.5" "typescript": "~3.7.5"
......
import { ApplicationRef, ChangeDetectorRef, ElementRef, ViewChild } from "@angular/core";
export class ComponentBase {
// 储存数据用
saveKey = "";
// 储存对象
item: any = {};
ngOnChanges() { }
ngOnDestroy() { }
constructor(public appRef: ApplicationRef, public 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) {
let url = e.url;
let sp = url.split(".mp3");
let u = sp[0] + "_l.mp3";
it[key] = u;
it["audioName"] = e.name || "";
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() { }
}
<div style="margin: 30px;">
<div class="model-content"> <!-- 考试基本信息 -->
<div class="model-content">
<div style="width: 100%; display: inline-flex; flex-direction: row; flex-wrap: wrap;">
<div style="margin:30px; border: 2px #ccc solid; border-radius: 15px; width: 1000px; padding: 20px 10px 5px 10px; display: flex; justify-content: center;">
<div>
<div style="width: 100px; background-color: white; transform: translateY(-30px);"></div>
<div style="margin: 20px; display: flex; align-items: center;">
<h3 style="min-width: 150px; text-align:left">考试标题:</h3>
<textarea nz-input [(ngModel)]="item.title" (blur)="save()" style="width: 640px; min-height: 60px;"></textarea>
</div>
<div style="position: absolute; left: 200px; top: 100px; width: 800px;"> <div style="margin: 20px; display: flex; align-items: center;">
<h3 style="min-width: 150px; text-align:left">考试副标题:</h3>
<textarea nz-input [(ngModel)]="item.subtitle" (blur)="save()" style="width: 640px; min-height: 60px;"></textarea>
</div>
<input type="text" nz-input [(ngModel)]="item.text" (blur)="save()"> <div style="margin: 20px; display: flex; align-items: center; ">
<h3 style="min-width: 150px; text-align:left">题目音频:</h3>
<app-audio-recorder [audioUrl]="item.audio_url"
(audioUploaded)="onItemAudioUploadSuccess($event, item, 'audio_url')">
</app-audio-recorder>
<button *ngIf="item.audio_url" style="margin-left: 10px;" nz-button nzType="danger" (click)="onDeletaImg(item, 'audio_url')">
x
</button>
</div>
<app-upload-image-with-preview <div style="margin: 20px; display: flex; align-items: center;">
[picUrl]="item.pic_url" <h3 style="min-width: 150px; text-align:left">封面图片:</h3>
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')" <app-upload-image-with-preview style="width: 80%; max-width: 640px;" [picUrl]="item.cover"
></app-upload-image-with-preview> (imageUploaded)="onImageUploadSuccess($event)">
</app-upload-image-with-preview>
</div>
</div>
</div>
</div>
</div>
<!-- 题目列表 -->
<div *ngIf="item && item.questionArr !== undefined" style="width: 1060px; margin: 30px;">
<div *ngFor="let question of item.questionArr; let i = index"
style="border: 2px solid #ddd; border-radius: 15px; padding: 25px; margin-bottom: 25px; background-color: #fafafa;">
<!-- 题目头部 -->
<div style="display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; padding-bottom: 15px; border-bottom: 1px solid #eee;">
<h3 style="margin: 0; color: #333;">第 {{i+1}} 题</h3>
<button nz-button nzType="danger" (click)="deleteQuestion(i)">删除题目</button>
</div>
<!-- 题目图片 -->
<div style="margin-bottom: 15px; display: flex; align-items: flex-start; gap: 15px;">
<span style="min-width: 80px; line-height: 32px; font-weight: bold; color: #555;">题目图片:</span>
<div style="width: 300px;">
<app-upload-image-with-preview [picUrl]="question.pic_url" [TIP]="'点击上传题目图片'"
(imageUploaded)="onItemImgUploadSuccess($event, question, 'pic_url')">
</app-upload-image-with-preview>
</div>
<button *ngIf="question.pic_url" nz-button nzSize="small" (click)="onDeletaImg(question, 'pic_url')">删除图片</button>
</div>
<!-- 题干 -->
<div style="margin-bottom: 20px; display: flex; align-items: flex-start; gap: 15px;">
<span style="min-width: 80px; line-height: 32px; font-weight: bold; color: #555;">题干:</span>
<textarea nz-input [(ngModel)]="question.text" (blur)="save()"
style="flex: 1; max-width: 700px; min-height: 80px;"
placeholder="请输入题目题干(可选)">
</textarea>
</div>
<!-- 答案选项 -->
<div>
<div style="margin-bottom: 12px; font-weight: bold; color: #555;">
答案选项
<span style="font-weight: normal; font-size: 12px; color: #999; margin-left: 8px;">
点击左侧圆圈选择正确答案,选项内容可以是文字或图片
</span>
</div>
<nz-radio-group [ngModel]="question.correctIndex" (ngModelChange)="onCorrectAnswerChange(question, $event)">
<div *ngFor="let option of question.optionArr; let j = index"
style="border: 1px solid; border-radius: 10px; padding: 12px 15px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px;"
[style.border-color]="question.correctIndex === j ? '#52c41a' : '#ddd'"
[style.background-color]="question.correctIndex === j ? '#f6ffed' : '#fff'">
<!-- 选择正确答案 -->
<label nz-radio [nzValue]="j" style="margin: 0; flex-shrink: 0;">
<span style="font-weight: bold; font-size: 15px;">{{getOptionLabel(j)}}</span>
</label>
<!-- 正确标识 -->
<span *ngIf="question.correctIndex === j" style="color: #52c41a; font-size: 12px; white-space: nowrap; flex-shrink: 0; min-width: 42px;">✓ 正确</span>
<span *ngIf="question.correctIndex !== j" style="min-width: 42px; flex-shrink: 0;"></span>
<!-- 选项图片 -->
<div style="width: 120px; flex-shrink: 0;">
<app-upload-image-with-preview [picUrl]="option.pic_url" [TIP]="'上传图片'"
(imageUploaded)="onItemImgUploadSuccess($event, option, 'pic_url')">
</app-upload-image-with-preview>
</div>
<button *ngIf="option.pic_url" nz-button nzSize="small" (click)="onDeletaImg(option, 'pic_url')">删图片</button>
<!-- 选项文字 -->
<textarea nz-input [(ngModel)]="option.text" (blur)="save()"
style="flex: 1; min-height: 60px;"
placeholder="选项文字(可选)">
</textarea>
<!-- 删除选项 -->
<button nz-button nzType="danger" nzSize="small" (click)="deleteOptionBtnClick(question.optionArr, j)">
<i nz-icon nzType="delete" nzTheme="outline"></i>
</button>
</div>
</nz-radio-group>
<!-- 添加选项按钮 -->
<button nz-button nzType="dashed" (click)="addOneOption(question)" style="width: 150px; height: 45px; margin-top: 5px;">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>
添加选项
</button>
</div>
</div>
<app-audio-recorder <!-- 添加题目按钮 -->
[audioUrl]="item.audio_url" <div style="text-align: center; padding: 25px; border: 2px dashed #ccc; border-radius: 15px;">
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')" <button nz-button nzType="dashed" (click)="addQuestion()" style="width: 200px; height: 50px; font-size: 15px;">
></app-audio-recorder> <i nz-icon nzType="plus-circle" nzTheme="outline"></i>
<app-custom-hot-zone></app-custom-hot-zone> 添加题目
<app-upload-video></app-upload-video> </button>
<app-lesson-title-config></app-lesson-title-config> </div>
</div> </div>
</div> </div>
\ No newline at end of file
import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef, ChangeDetectorRef} from '@angular/core'; import { Component, ApplicationRef, ChangeDetectorRef, OnDestroy, OnChanges, OnInit } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd/message';
import { ComponentBase } from './ComponentBase';
@Component({ @Component({
...@@ -7,86 +8,115 @@ import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, Ap ...@@ -7,86 +8,115 @@ import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, Ap
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 = "test_0011";
// 储存对象
item;
saveKey = "JJ_EXAM";
constructor(private appRef: ApplicationRef,private changeDetectorRef: ChangeDetectorRef) { item: any = {
title: "",
subtitle: "",
audio_url: "",
cover: "",
questionArr: []
};
constructor(public appRef: ApplicationRef, public changeDetectorRef: ChangeDetectorRef,
private message: NzMessageService) {
super(appRef, changeDetectorRef);
} }
ngOnInit() { ngOnInit() {
(<any>window).courseware.getData((data) => {
this.item = {};
// 获取存储的数据
(<any> window).courseware.getData((data) => {
if (data) { if (data) {
this.item = data; this.item = data;
} }
this.initItem();
this.init(); console.log("this.item: ", JSON.stringify(this.item));
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges(); this.changeDetectorRef.detectChanges();
this.refresh(); this.refresh();
}, this.saveKey); }, this.saveKey);
} }
ngOnChanges() { ngOnChanges() {
} }
ngOnDestroy() { ngOnDestroy() {
} }
initItem() {
if (!this.item.questionArr) {
this.item.questionArr = [];
}
}
addQuestion() {
if (!this.item.questionArr) {
this.item.questionArr = [];
}
this.item.questionArr.push({
text: "",
correctIndex: null,
optionArr: []
});
this.save();
}
init() { deleteQuestion(i: number) {
this.item.questionArr.splice(i, 1);
this.save();
}
onCorrectAnswerChange(question: any, index: number) {
question.correctIndex = index;
this.save();
} }
getOptionLabel(index: number): string {
const labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'];
return labels[index] !== undefined ? labels[index] : String(index + 1);
}
/** addOneOption(ques) {
* 储存图片数据 if (!ques.optionArr) {
* @param e ques.optionArr = [];
*/ }
onImageUploadSuccess(e, key) { ques.optionArr.push({});
this.save();
}
this.item[key] = e.url; deleteOptionBtnClick(arr, i) {
this.save(); arr.splice(i, 1);
this.save();
} }
/** onItemImgUploadSuccess(e, item, key = 'pic_url') {
* 储存音频数据 item[key] = e.url;
* @param e this.save();
*/ }
onAudioUploadSuccess(e, key) {
this.item[key] = e.url; onItemAudioUploadSuccess(e, item, key = 'audio_url') {
item[key] = e.url;
this.save(); this.save();
} }
onDeletaImg(item, key) {
delete item[key];
this.save();
}
onImageUploadSuccess(e) {
this.item.cover = e.url;
this.save();
}
/**
* 储存数据
*/
save() { save() {
(<any> window).courseware.setData(this.item, null, this.saveKey); (<any>window).courseware.setData(this.item, null, this.saveKey);
this.refresh(); this.refresh();
console.log('this.item = ' + JSON.stringify(this.item));
this.message.create('success', "保存成功");
} }
/**
* 刷新 渲染页面
*/
refresh() { refresh() {
setTimeout(() => { setTimeout(() => {
this.appRef.tick(); this.appRef.tick();
...@@ -94,4 +124,3 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -94,4 +124,3 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
} }
} }
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