Commit 870b1602 authored by wangxin's avatar wangxin

加载上传资源

parent 7756cba8
...@@ -13,25 +13,62 @@ ...@@ -13,25 +13,62 @@
></app-audio-recorder> ></app-audio-recorder>
</div> </div>
<div style="width: 300px; margin-top: 100px"> <div *ngFor="let it of picArr; let i = index" style="padding: 0.5vw">
<button nz-button nzType="primary">添加选项</button> <div class="border" style="display: flex; align-items: center">
<div class="item-box" style="width: 30%">
<h5 style="padding-bottom: 1vw">选项-{{ i + 1 }}</h5>
<div style="display: flex; align-items: center">
<span style="padding-right: 10px"> 图片:</span>
</div> </div>
<div style="width: 300px; margin-top: 50px">
<span>图1: </span>
<app-upload-image-with-preview <app-upload-image-with-preview
[picUrl]="item.pic_url" style="width: 100%"
(imageUploaded)="onImageUploadSuccess($event, 'pic_url')" [picUrl]="it.pic_url"
(imageUploaded)="onImageUploadSuccessByItem($event, it)"
></app-upload-image-with-preview>
<div style="display: flex; justify-items: center; padding-top: 10px">
<button
style="margin-left: 10px"
nz-button
nzType="danger"
(click)="deleteItem(it)"
> >
</app-upload-image-with-preview> <span>删除</span>
</button>
</div>
</div> </div>
<div style="margin-top: 5px"> <!--中间部分-->
<span>音频: </span> <div style="width: 30%; margin-left: 5%; padding: 1vw">
<div style="display: flex; align-items: center; margin-bottom: 0.5vw">
<span style="width: 50px"> 音频: </span>
</div>
<app-audio-recorder <app-audio-recorder
[audioUrl]="item.audio_url" [audioUrl]="it.audio_url"
(audioUploaded)="onAudioUploadSuccess($event, 'audio_url')" (audioUploaded)="onAudioUploadSuccessByItem($event, it)"
></app-audio-recorder> >
</app-audio-recorder>
<div
style="display: flex; align-items: center; margin-bottom: 0.5vw"
></div>
</div>
</div>
</div>
<div nz-col nzSpan="8" class="add-btn-box" style="margin-top: 100px">
<button
style="margin: auto; width: 60%; height: 60%"
nz-button
nzType="dashed"
class="add-btn"
(click)="addPic()"
>
<em nz-icon nzType="plus-circle" nzTheme="outline"></em>
添加选项
</button>
</div> </div>
</div> </div>
</div> </div>
...@@ -18,9 +18,10 @@ import { JsonPipe } from "@angular/common"; ...@@ -18,9 +18,10 @@ import { JsonPipe } from "@angular/common";
}) })
export class FormComponent implements OnInit, OnChanges, OnDestroy { export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 储存数据用 // 储存数据用
saveKey = "test_001"; saveKey = "andy_001";
// 储存对象 // 储存对象
item; item;
picArr = [];
constructor( constructor(
private appRef: ApplicationRef, private appRef: ApplicationRef,
...@@ -44,7 +45,6 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -44,7 +45,6 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() { ngOnInit() {
this.item = {}; this.item = {};
this.item["total"] = 0;
// 获取存储的数据 // 获取存储的数据
(<any>window).courseware.getData((data) => { (<any>window).courseware.getData((data) => {
...@@ -80,7 +80,28 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -80,7 +80,28 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
*/ */
onAudioUploadSuccess(e, key) { onAudioUploadSuccess(e, key) {
this.item[key] = e.url; this.item[key] = e.url;
this.item["total"] = this.item["total"] + 1; this.save();
}
onImageUploadSuccessByItem(e, item, id = null) {
if (id != null) {
item["pic_url_" + id] = e.url;
console.log("upload pic 1" + e.url);
} else {
item.pic_url = e.url;
console.log("upload pic 2" + e.url);
}
this.save();
console.log("this.item: ", this.picArr);
}
onAudioUploadSuccessByItem(e, item, id = null) {
if (id != null) {
item["audio_url_" + id] = e.url;
} else {
item.audio_url = e.url;
}
this.save(); this.save();
} }
...@@ -94,10 +115,37 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy { ...@@ -94,10 +115,37 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
this.save(); this.save();
} }
saveItem() {
console.log(" in saveItem");
console.log("this.item" + JSON.stringify(this.item));
this.save();
}
deleteItem(data) {
const index = this.picArr.indexOf(data);
if (index !== -1) {
this.picArr.splice(index, 1);
}
this.save();
}
addPic() {
const data = {
pic_url: "",
audio_url: "",
};
this.picArr.push(data);
this.saveItem();
}
/** /**
* 储存数据 * 储存数据
*/ */
save() { save() {
this.item["options"] = this.picArr;
(<any>window).courseware.setData(this.item, null, this.saveKey); (<any>window).courseware.setData(this.item, null, this.saveKey);
this.refresh(); this.refresh();
......
...@@ -96,22 +96,21 @@ cc.Class({ ...@@ -96,22 +96,21 @@ cc.Class({
}, },
preloadItem() { preloadItem() {
// this.addPreloadImage(); this.addPreloadImage();
// this.addPreloadAudio(); this.addPreloadAudio();
// this.addPreloadAnima(); this.addPreloadAnima();
// this.preload(); this.preload();
this.initView();
}, },
addPreloadImage() { addPreloadImage() {
for (var i = 0; i < this.data.total; i++) { for (var i = 0; i < this.data.options; i++) {
this._imageResList.push({ url: this.data["pic_url_" + i] }); this._imageResList.push({ url: this.data.options[i]["pic_url_" + i] });
} }
}, },
addPreloadAudio() { addPreloadAudio() {
for (var i = 0; i < this.data.total; i++) { for (var i = 0; i < this.data.total; i++) {
this._audioResList.push({ url: this.data["audio_url_" + i] }); this._audioResList.push({ url: this.data.options[i]["audio_url_" + i] });
} }
}, },
...@@ -162,10 +161,6 @@ cc.Class({ ...@@ -162,10 +161,6 @@ cc.Class({
this.playAudioByUrl(this.data.audio_title); this.playAudioByUrl(this.data.audio_title);
}); });
if (window && window["air"]) {
window["air"].hideAirClassLoading();
}
// for (var i = 0; i < this.data.total; i++) { // for (var i = 0; i < this.data.total; i++) {
// const op_s = cc.instantiate(this.op_sound); // const op_s = cc.instantiate(this.op_sound);
// op_s.getComponent("op_sound")._opId = i; // op_s.getComponent("op_sound")._opId = i;
......
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