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'; ...@@ -11,17 +11,7 @@ import { NzMessageService, UploadXHRArgs, UploadFile } from 'ng-zorro-antd';
export class SubTemplateComponent implements OnDestroy, OnChanges { export class SubTemplateComponent implements OnDestroy, OnChanges {
uploading = false; uploading = false;
progress = 0; progress = 0;
@Input()
btnName = '配置龙骨动画';
@Input()
animaNames = [];
@Input()
skeJsonData = {};
@Input()
texJsonData = {};
@Input()
texPngData = {};
@Output() @Output()
save = new EventEmitter(); save = new EventEmitter();
...@@ -60,7 +50,7 @@ export class SubTemplateComponent implements OnDestroy, OnChanges { ...@@ -60,7 +50,7 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
@ViewChild('iframe', {static: true }) iframe: ElementRef; @ViewChild('iframe', {static: true }) iframe: ElementRef;
isShowTemplate = false; 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.uploadUrl = (<any> window).courseware.uploadUrl();
this.uploadData = (<any> window).courseware.uploadData(); this.uploadData = (<any> window).courseware.uploadData();
...@@ -72,10 +62,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges { ...@@ -72,10 +62,6 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
}; };
this.initListener();
this.setUploadUrl();
} }
...@@ -121,6 +107,11 @@ export class SubTemplateComponent implements OnDestroy, OnChanges { ...@@ -121,6 +107,11 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
} }
this.refreshSafeUrl(); this.refreshSafeUrl();
this.initListener();
this.setUploadUrl();
} }
...@@ -184,10 +175,11 @@ export class SubTemplateComponent implements OnDestroy, OnChanges { ...@@ -184,10 +175,11 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
initListener() { initListener() {
console.log(this.el.nativeElement);
window.addEventListener('message', (e) => { const iframeContent = this.el.nativeElement.querySelector('#iframe').contentWindow;
window.addEventListener('message', (e) => {
let msgData = e.data; let msgData = e.data;
...@@ -208,32 +200,14 @@ export class SubTemplateComponent implements OnDestroy, OnChanges { ...@@ -208,32 +200,14 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
} }
if ( ! this.iframe.nativeElement.contentWindow) { if ( !iframeContent ) {
return; 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)}; const data = { msg: 'success', data: JSON.stringify(this._item.data)};
// iframecont.postMessage({ action: 'getData', data: JSON.stringify(data) }, '*'); iframeContent.postMessage( { action: 'getData', data: JSON.stringify(data) }, '*');
// this.iframe.nativeElement.contentWindow.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);
} }
...@@ -265,40 +239,17 @@ export class SubTemplateComponent implements OnDestroy, OnChanges { ...@@ -265,40 +239,17 @@ export class SubTemplateComponent implements OnDestroy, OnChanges {
if (msgData.action === "getUpload") { if (msgData.action === "getUpload") {
console.log( ' in 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', action: 'getUpload',
uploadUrl: this.uploadUrl, uploadUrl: this.uploadUrl,
uploadData: this.uploadData 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 @@ ...@@ -19,7 +19,7 @@
</div> </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;"> <button nz-button nzType="dashed" (click)="addBtnClick()" style="width: 200px; height: 50px;">
<i nz-icon nzType="plus-circle" nzTheme="outline"></i> <i nz-icon nzType="plus-circle" nzTheme="outline"></i>
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
</div> </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 <app-sub-template
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
</app-sub-template> </app-sub-template>
</div> </div>
</div>
<button nz-button nzType="primary" (click)="addSubTemplate()" style="border-radius: 0.5rem; border: 1px solid #ddd; margin-top: 15px;"> <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> <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