Commit 33b16a6f authored by limingzhe's avatar limingzhe

fix: iframe err

parent 8e918acb
......@@ -11,17 +11,7 @@ import { NzMessageService, UploadXHRArgs, UploadFile } from 'ng-zorro-antd';
export class SubTemplateComponent implements OnDestroy, OnChanges {
uploading = false;
progress = 0;
@Input()
btnName = '配置龙骨动画';
@Input()
animaNames = [];
@Input()
skeJsonData = {};
@Input()
texJsonData = {};
@Input()
texPngData = {};
@Output()
save = new EventEmitter();
......@@ -60,7 +50,7 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
@ViewChild('iframe', {static: true }) iframe: ElementRef;
isShowTemplate = false;
constructor(private appRef: ApplicationRef, private nzMessageService: NzMessageService, private sanitizer: DomSanitizer) {
constructor(private el:ElementRef, private appRef: ApplicationRef, private nzMessageService: NzMessageService, private sanitizer: DomSanitizer) {
this.uploadUrl = (<any> window).courseware.uploadUrl();
this.uploadData = (<any> window).courseware.uploadData();
......@@ -72,10 +62,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
};
this.initListener();
this.setUploadUrl();
}
......@@ -121,6 +107,11 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
}
this.refreshSafeUrl();
this.initListener();
this.setUploadUrl();
}
......@@ -184,11 +175,12 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
initListener() {
console.log(this.el.nativeElement);
const iframeContent = this.el.nativeElement.querySelector('#iframe').contentWindow;
window.addEventListener('message', (e) => {
let msgData = e.data;
......@@ -208,32 +200,14 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
}
if ( ! this.iframe.nativeElement.contentWindow) {
if ( !iframeContent ) {
return;
}
console.log('this.iframe.: ', this.iframe);
// var iframecont = document.getElementById('iframe')['contentWindow'];
console.log('iframecont.: ', this.iframe);
const obj = {contentObj: {}};
const data = { msg: 'success', data: JSON.stringify(this._item.data)};
// iframecont.postMessage({ action: 'getData', data: JSON.stringify(data) }, '*');
// const data = JSON.stringify( { action: 'getData'});
this.iframe.nativeElement.contentWindow.postMessage( { action: 'getData', data: JSON.stringify(data) }, '*');
// iframecont.postMessage({ action: 'getData', data: null }, '*');
// setTimeout(() => {
// _this.frameLoaded = true;
// }, 300);
iframeContent.postMessage( { action: 'getData', data: JSON.stringify(data) }, '*');
// this.iframe.nativeElement.contentWindow.postMessage( { action: 'getData', data: JSON.stringify(data) }, '*');
}
......@@ -265,40 +239,17 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
if (msgData.action === "getUpload") {
console.log( ' in getUpload')
// if ( ! this.iframe.nativeElement.contentWindow) {
// return;
// }
const protocolStr = document.location.protocol;
// console.log('protocolStr:', protocolStr);
console.log('this.iframe:', this.iframe);
console.log("this.iframe.nativeElement.air", this.iframe.nativeElement.air);
this.iframe.nativeElement.contentWindow.postMessage({
iframeContent.postMessage({
action: 'getUpload',
uploadUrl: this.uploadUrl,
uploadData: this.uploadData
}, '*');
}
// if (msgData.action === "getUpload") {
// console.log("getUpload e: ", e);
// // this.iframe.nativeElement.contentWindow.postMessage( { action: 'getData', data: JSON.stringify(data) }, '*');
// this.iframe.nativeElement.contentWindow.air.uploadUrl = this.uploadUrl;
// this.iframe.nativeElement.contentWindow.air.uploadData = this.uploadData;
// // for (let i = 0; i < uploadCallbackQueue.length; i++) {
// // uploadCallbackQueue[i](msgData.uploadUrl, msgData.uploadData);
// // }
// this.iframe.nativeElement.contentWindow.air.getUploadCallback(this.uploadUrl, this.uploadData);
// return;
// }
// _this.checkIframeListener(msgData);
});
}
......
......@@ -19,7 +19,7 @@
</div>
<div *ngIf="item.sentenceArr.length < 4">
<div *ngIf="item.sentenceArr && item.sentenceArr.length < 4">
<button nz-button nzType="dashed" (click)="addBtnClick()" style="width: 200px; height: 50px;">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i>
......@@ -28,18 +28,21 @@
</div>
<div *ngIf="item.templateArr" >
<div *ngFor="let template of item.templateArr; let i = index" style="margin-bottom: 10px;">
<div *ngFor="let template of item.templateArr; let i = index" style="margin-bottom: 10px;">
<app-sub-template
[item]="template"
[key]="i+1"
(save)="onSaveTemplate($event, i)"
(deleteFunc)="onDeleteTemplate($event, i)"
>
</app-sub-template>
<app-sub-template
[item]="template"
[key]="i+1"
(save)="onSaveTemplate($event, i)"
(deleteFunc)="onDeleteTemplate($event, i)"
>
</app-sub-template>
</div>
</div>
<button nz-button nzType="primary" (click)="addSubTemplate()" style="border-radius: 0.5rem; border: 1px solid #ddd; margin-top: 15px;">
<i nz-icon nzType="plus" nzTheme="outline"></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