mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-18 19:40:03 +08:00
feat(editor,stage): 支持切换runtimeUrl
This commit is contained in:
parent
0196eb343a
commit
92534fc915
@ -128,7 +128,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { EventEmitter } from 'events';
|
||||
|
||||
import { provide } from 'vue';
|
||||
import { provide, watch } from 'vue';
|
||||
|
||||
import type { MApp } from '@tmagic/core';
|
||||
|
||||
@ -209,6 +209,22 @@ const stageOptions: StageOptions = {
|
||||
|
||||
stageOverlayService.set('stageOptions', stageOptions);
|
||||
|
||||
watch(
|
||||
() => props.runtimeUrl,
|
||||
(url) => {
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
const stage = editorService.get('stage');
|
||||
if (!stage) {
|
||||
return;
|
||||
}
|
||||
|
||||
stage.reloadIframe(url);
|
||||
},
|
||||
);
|
||||
|
||||
provide('services', services);
|
||||
|
||||
provide('codeOptions', props.codeOptions);
|
||||
|
@ -236,6 +236,10 @@ export default class StageCore extends EventEmitter {
|
||||
this.actionManager?.enableMultiSelect();
|
||||
}
|
||||
|
||||
public reloadIframe(url: string) {
|
||||
this.renderer?.reloadIframe(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁实例
|
||||
*/
|
||||
|
@ -172,14 +172,31 @@ export default class StageRender extends EventEmitter {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁实例
|
||||
*/
|
||||
public destroy(): void {
|
||||
public reloadIframe(url: string) {
|
||||
if (this.renderType !== RenderType.IFRAME) return;
|
||||
|
||||
const el = this.iframe?.parentElement;
|
||||
this.destroyIframe();
|
||||
this.runtimeUrl = url;
|
||||
this.createIframe();
|
||||
this.mount(el as HTMLDivElement);
|
||||
this.runtime = null;
|
||||
}
|
||||
|
||||
public destroyIframe() {
|
||||
this.iframe?.removeEventListener('load', this.iframeLoadHandler);
|
||||
this.contentWindow = null;
|
||||
this.iframe?.remove();
|
||||
this.iframe = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁实例
|
||||
*/
|
||||
public destroy(): void {
|
||||
this.destroyIframe();
|
||||
// @ts-ignore
|
||||
globalThis.runtime = undefined;
|
||||
this.removeAllListeners();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user