Commit d4dde87d authored by Dumplings X's avatar Dumplings X

fix

parent 55d8ec14
This diff is collapsed.
import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, ApplicationRef} from '@angular/core';
import {
Component,
EventEmitter,
Input,
OnDestroy,
OnChanges,
OnInit,
Output,
ApplicationRef,
ChangeDetectorRef
} from '@angular/core';
......@@ -9,13 +19,40 @@ import {Component, EventEmitter, Input, OnDestroy, OnChanges, OnInit, Output, Ap
})
export class FormComponent implements OnInit, OnChanges, OnDestroy {
// 储存数据用
saveKey = "test_0011";
// 储存对象
item;
picArr = [];
_item: any;
constructor(private appRef: ApplicationRef) {
KEY = 'hw_online_008';
// @Input()
set item(item) {
this._item = item;
// this.init();
}
get item() {
return this._item;
}
@Output()
update = new EventEmitter();
bgItem;
hotZoneItemArr;
constructor(private appRef: ApplicationRef,
public changeDetectorRef: ChangeDetectorRef) {
}
......@@ -23,68 +60,205 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
ngOnInit() {
this.item = {};
this.item.contentObj = {};
// 获取存储的数据
(<any> window).courseware.getData((data) => {
const getData = (<any> window).courseware.getData;
getData((data) => {
if (data) {
this.item = data;
} else {
this.item = {};
}
if ( !this.item.contentObj ) {
this.item.contentObj = {};
}
console.log('~data:', data);
this.init();
this.refresh();
}, this.saveKey);
this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();
}
this.refresh();
}, this.KEY);
// this.initData();
}
ngOnChanges() {
}
ngOnDestroy() {
}
init() {
if (this.item.contentObj.picArr) {
this.picArr = this.item.contentObj.picArr;
} else {
this.picArr = this.getDefaultPicArr();
this.item.contentObj.picArr = this.picArr;
}
this.bgItem = this.item.contentObj.bgItem || {};
this.hotZoneItemArr = this.item.contentObj.hotZoneItemArr || [];
console.log('item:' , this.item);
// this.picArr = this.getDefaultPicArr();
// this.item.contentObj.picArr = this.picArr;
// console.log('this.item:;', this.picArr);
}
getDefaultPicArr() {
const arr = [];
/**
* 储存图片数据
* @param e
*/
onImageUploadSuccess(e, key) {
return arr;
}
this.item[key] = e.url;
this.save();
changeOptions(data) {
console.log('data: ', data);
this.save();
}
/**
* 储存音频数据
* @param e
*/
onAudioUploadSuccess(e, key) {
this.item[key] = e.url;
getOptions() {
const options = [];
const arr = this.hotZoneItemArr;
for (let i = 0; i < arr.length; i++) {
const data = {};
data['key'] = arr[i]['key'];
data['index'] = arr[i]['index'];
data['label'] = 'item-' + (arr[i]['index'] + 1);
data['value'] = arr[i]['index'];
options.push(data);
}
return options;
}
refreshOptions() {
const picArr = this.picArr;
for (let i = 0; i < picArr.length; i++) {
picArr[i].options = this.getOptions();
}
}
deleteItem(data, arr = null) {
if (!arr) {
arr = this.picArr;
}
const index = arr.indexOf(data);
if (index !== -1) {
arr.splice(index, 1);
}
// this.update.emit(this.item);
// this.refreshOptions();
this.save();
}
onImageUploadSuccessByItem(e, item, id = null) {
if (id != null) {
item[id + '_pic_url'] = e.url;
} else {
item.pic_url = e.url;
}
this.save();
// this.update.emit(this.item);
// console.log('this.item: ', this.item);
}
onAudioUploadSuccessByItem(e, item, id = null) {
if (id != null) {
item[id + '_audio_url'] = e.url;
} else {
item.audio_url = e.url;
}
// this.update.emit(this.item);
this.save();
}
/**
* 储存数据
*/
addPic() {
this.picArr.push({
pic_url: '',
audio_url: '',
text: '',
options: this.getOptions()
// text: '',
// radioValue: 'A'
});
// this.refreshOptions();
this.saveItem();
}
radioClick(it, radioValue) {
it.radioValue = radioValue;
this.saveItem();
}
clickCheckBox() {
console.log(' in clickCheckBox');
this.saveItem();
}
saveItem() {
// this.update.emit(this.item);
this.save();
}
saveData(e) {
console.log('savedata e:', e);
this.bgItem = e.bgItem;
this.hotZoneItemArr = e.hotZoneItemArr;
this.item.contentObj.bgItem = this.bgItem;
this.item.contentObj.hotZoneItemArr = this.hotZoneItemArr;
this.refreshOptions();
this.save();
}
save() {
(<any> window).courseware.setData(this.item, null, this.saveKey);
(<any> window).courseware.setData(this.item, null, this.KEY);
this.refresh();
}
/**
* 刷新 渲染页面
*/
refresh() {
setTimeout(() => {
this.appRef.tick();
......
This diff is collapsed.
This diff is collapsed.
......@@ -12,6 +12,8 @@ const res = [
['petal_2', "assets/default/petal_2.png"],
['petal_3', "assets/default/petal_3.png"],
['t_right', "assets/play/teacher/right.png"],
['t_arrow', "assets/play/teacher/arrow.png"],
];
......
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