1
1
<template >
2
2
<div class =" process-panel__container" :style =" { width: `${width}px` }" >
3
- <el-collapse v-model =" activeTab" >
3
+ <el-collapse v-model =" activeTab" v-if = " isReady " >
4
4
<el-collapse-item name =" base" >
5
5
<!-- class="panel-tab__title" -->
6
6
<template #title >
@@ -108,24 +108,16 @@ const elementBusinessObject = ref<any>({}) // 元素 businessObject 镜像,提
108
108
const conditionFormVisible = ref (false ) // 流转条件设置
109
109
const formVisible = ref (false ) // 表单配置
110
110
const bpmnElement = ref ()
111
+ const isReady = ref (false )
111
112
112
113
provide (' prefix' , props .prefix )
113
114
provide (' width' , props .width )
114
- const bpmnInstances = () => (window as any )?.bpmnInstances
115
-
116
- // 监听 props.bpmnModeler 然后 initModels
117
- const unwatchBpmn = watch (
118
- () => props .bpmnModeler ,
119
- () => {
120
- // 避免加载时 流程图 并未加载完成
121
- if (! props .bpmnModeler ) {
122
- console .log (' 缺少props.bpmnModeler' )
123
- return
124
- }
125
115
126
- console .log (' props.bpmnModeler 有值了!!!' )
127
- const w = window as any
128
- w .bpmnInstances = {
116
+ // 初始化 bpmnInstances
117
+ const initBpmnInstances = () => {
118
+ if (! props .bpmnModeler ) return false
119
+ try {
120
+ const instances = {
129
121
modeler: props .bpmnModeler ,
130
122
modeling: props .bpmnModeler .get (' modeling' ),
131
123
moddle: props .bpmnModeler .get (' moddle' ),
@@ -136,17 +128,55 @@ const unwatchBpmn = watch(
136
128
replace: props .bpmnModeler .get (' replace' ),
137
129
selection: props .bpmnModeler .get (' selection' )
138
130
}
131
+
132
+ // 检查所有实例是否都存在
133
+ const allInstancesExist = Object .values (instances ).every (instance => instance )
134
+ if (allInstancesExist ) {
135
+ const w = window as any
136
+ w .bpmnInstances = instances
137
+ return true
138
+ }
139
+ return false
140
+ } catch (error ) {
141
+ console .error (' 初始化 bpmnInstances 失败:' , error )
142
+ return false
143
+ }
144
+ }
145
+
146
+ const bpmnInstances = () => (window as any )?.bpmnInstances
147
+
148
+ // 监听 props.bpmnModeler 然后 initModels
149
+ const unwatchBpmn = watch (
150
+ () => props .bpmnModeler ,
151
+ async () => {
152
+ // 避免加载时 流程图 并未加载完成
153
+ if (! props .bpmnModeler ) {
154
+ console .log (' 缺少props.bpmnModeler' )
155
+ return
156
+ }
139
157
140
- console .log (bpmnInstances (), ' window.bpmnInstances' )
141
- getActiveElement ()
142
- unwatchBpmn ()
158
+ try {
159
+ // 等待 modeler 初始化完成
160
+ await nextTick ()
161
+ if (initBpmnInstances ()) {
162
+ isReady .value = true
163
+ await nextTick ()
164
+ getActiveElement ()
165
+ } else {
166
+ console .error (' modeler 实例未完全初始化' )
167
+ }
168
+ } catch (error ) {
169
+ console .error (' 初始化失败:' , error )
170
+ }
143
171
},
144
172
{
145
173
immediate: true
146
174
}
147
175
)
148
176
149
177
const getActiveElement = () => {
178
+ if (! isReady .value || ! props .bpmnModeler ) return
179
+
150
180
// 初始第一个选中元素 bpmn:Process
151
181
initFormOnChanged (null )
152
182
props .bpmnModeler .on (' import.done' , (e ) => {
@@ -164,41 +194,48 @@ const getActiveElement = () => {
164
194
}
165
195
})
166
196
}
197
+
167
198
// 初始化数据
168
199
const initFormOnChanged = (element ) => {
200
+ if (! isReady .value || ! bpmnInstances ()) return
201
+
169
202
let activatedElement = element
170
203
if (! activatedElement ) {
171
204
activatedElement =
172
205
bpmnInstances ().elementRegistry .find ((el ) => el .type === ' bpmn:Process' ) ??
173
206
bpmnInstances ().elementRegistry .find ((el ) => el .type === ' bpmn:Collaboration' )
174
207
}
175
208
if (! activatedElement ) return
176
- console .log (`
177
- ----------
178
- select element changed:
179
- id: ${activatedElement .id }
180
- type: ${activatedElement .businessObject .$type }
181
- ----------
182
- ` )
183
- console .log (' businessObject: ' , activatedElement .businessObject )
184
- bpmnInstances ().bpmnElement = activatedElement
185
- bpmnElement .value = activatedElement
186
- elementId .value = activatedElement .id
187
- elementType .value = activatedElement .type .split (' :' )[1 ] || ' '
188
- elementBusinessObject .value = JSON .parse (JSON .stringify (activatedElement .businessObject ))
189
- conditionFormVisible .value = !! (
190
- elementType .value === ' SequenceFlow' &&
191
- activatedElement .source &&
192
- activatedElement .source .type .indexOf (' StartEvent' ) === - 1
193
- )
194
- formVisible .value = elementType .value === ' UserTask' || elementType .value === ' StartEvent'
209
+
210
+ try {
211
+ console .log (`
212
+ ----------
213
+ select element changed:
214
+ id: ${activatedElement .id }
215
+ type: ${activatedElement .businessObject .$type }
216
+ ----------
217
+ ` )
218
+ console .log (' businessObject: ' , activatedElement .businessObject )
219
+ bpmnInstances ().bpmnElement = activatedElement
220
+ bpmnElement .value = activatedElement
221
+ elementId .value = activatedElement .id
222
+ elementType .value = activatedElement .type .split (' :' )[1 ] || ' '
223
+ elementBusinessObject .value = JSON .parse (JSON .stringify (activatedElement .businessObject ))
224
+ conditionFormVisible .value = !! (
225
+ elementType .value === ' SequenceFlow' &&
226
+ activatedElement .source &&
227
+ activatedElement .source .type .indexOf (' StartEvent' ) === - 1
228
+ )
229
+ formVisible .value = elementType .value === ' UserTask' || elementType .value === ' StartEvent'
230
+ } catch (error ) {
231
+ console .error (' 初始化表单数据失败:' , error )
232
+ }
195
233
}
196
234
197
235
onBeforeUnmount (() => {
198
236
const w = window as any
199
237
w .bpmnInstances = null
200
- console .log (props , ' props1' )
201
- console .log (props .bpmnModeler , ' props.bpmnModeler1' )
238
+ isReady .value = false
202
239
})
203
240
204
241
watch (
@@ -208,3 +245,10 @@ watch(
208
245
}
209
246
)
210
247
</script >
248
+ <style lang="scss">
249
+ .process-panel__container {
250
+ position : absolute ;
251
+ top : 90px ;
252
+ right : 60px ;
253
+ }
254
+ </style >
0 commit comments