From 4be6ed89ee1223a4269cd6f9eebf3799da69b799 Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 5 Oct 2026 17:45:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BE=AE=E5=89=8D=E7=AB=AF):=20=E8=BF=9C?= =?UTF-8?q?=E7=AB=AF=E5=AE=BF=E4=B8=BB=E6=94=AF=E6=8C=81=20mount/unmount?= =?UTF-8?q?=20=E5=BE=AE=E5=BA=94=E7=94=A8=E5=A5=91=E7=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - remoteLoader 拆出 LoadRemoteModule,先探测远端模块的 mount/unmount,再回退组件工厂 - RemoteAppHost 兼容两种契约:微应用由远端自带运行时挂载,组件工厂由宿主渲染 --- src/apps/remoteLoader.ts | 21 +++++--- src/views/RemoteAppHost.vue | 102 ++++++++++++++++++++++++++++-------- 2 files changed, 94 insertions(+), 29 deletions(-) diff --git a/src/apps/remoteLoader.ts b/src/apps/remoteLoader.ts index 9fbb3f8..3ab37d7 100644 --- a/src/apps/remoteLoader.ts +++ b/src/apps/remoteLoader.ts @@ -42,7 +42,20 @@ export function GetRemoteHostRuntime(): RemoteHostRuntime { } /** - * 加载远端组件 + * 加载远端模块命名空间(不做契约解析,交由调用方判断 mount / createComponent) + * + * @param RemoteEntry 远端入口 URL + */ +export async function LoadRemoteModule(RemoteEntry: string): Promise> { + if (!RemoteEntry) { + throw new Error('远端入口地址为空') + } + // 运行期 URL:@vite-ignore 阻止打包器静态分析(远端不在本仓库内) + return (await import(/* @vite-ignore */ RemoteEntry)) as Record +} + +/** + * 加载远端组件(组件工厂契约) * * @param RemoteEntry 远端入口 URL(如 https://sub.xxx/remoteEntry.js 或 /remote-demo/entry.js) * @param ExportName 导出名(默认 default;工厂约定忽略此参数) @@ -53,11 +66,7 @@ export async function LoadRemoteComponent( RemoteEntry: string, ExportName = 'default', ): Promise { - if (!RemoteEntry) { - throw new Error('远端入口地址为空') - } - // 运行期 URL:@vite-ignore 阻止打包器静态分析(远端不在本仓库内) - const mod: Record = await import(/* @vite-ignore */ RemoteEntry) + const mod = await LoadRemoteModule(RemoteEntry) // 约定 1:工厂(宿主把运行时以参数传入) const factory = mod.createComponent diff --git a/src/views/RemoteAppHost.vue b/src/views/RemoteAppHost.vue index 129b08a..0603e3a 100644 --- a/src/views/RemoteAppHost.vue +++ b/src/views/RemoteAppHost.vue @@ -1,34 +1,69 @@ @@ -63,6 +116,9 @@ watch( .remote-app-host { padding: 16px; box-sizing: border-box; - height: 100%; + min-height: 100%; +} +.remote-mount { + min-height: 200px; }