@@ -2,7 +2,7 @@ import { BaseNodeModel, GraphModel } from '@logicflow/core'
2
2
import {
3
3
defineComponent ,
4
4
h ,
5
- render ,
5
+ createApp ,
6
6
reactive ,
7
7
isVue3 ,
8
8
Teleport ,
@@ -11,6 +11,7 @@ import {
11
11
} from 'vue-demi'
12
12
13
13
let active = false
14
+ const appInstances = new Map < string , InstanceType < any > > ( )
14
15
const items = reactive < { [ key : string ] : any } > ( { } )
15
16
16
17
export function connect (
@@ -36,9 +37,14 @@ export function connect(
36
37
}
37
38
}
38
39
39
- export function disconnect ( id : string ) {
40
+ export function disconnect ( id : string , flowId : string ) {
40
41
if ( active ) {
41
42
delete items [ id ]
43
+ const app = appInstances . get ( flowId )
44
+ if ( app ) {
45
+ app . unmount ( )
46
+ appInstances . delete ( flowId )
47
+ }
42
48
}
43
49
}
44
50
@@ -99,9 +105,18 @@ export function createTeleportContainer(
99
105
// 获取 Teleport 组件
100
106
const TeleportContainer = getTeleport ( )
101
107
102
- // 创建 Teleport 组件的虚拟节点,传入 flowId
103
- const teleportVNode = h ( TeleportContainer , { flowId } )
108
+ // 不重新创建 Teleport 容器组件
109
+ if ( appInstances . has ( flowId ) ) {
110
+ return
111
+ }
112
+
113
+ // ✅ 1. 创建独立容器放到目标容器中
114
+ const mountPoint = document . createElement ( 'div' )
115
+ container . appendChild ( mountPoint )
116
+
117
+ // ✅ 2. 创建并挂载 Vue 应用到新容器
118
+ const app = createApp ( TeleportContainer , { flowId } )
119
+ app . mount ( mountPoint )
104
120
105
- // 渲染到指定容器中
106
- render ( teleportVNode , container )
121
+ appInstances . set ( flowId , app )
107
122
}
0 commit comments