workflow-bpmn-modeler-andtv-vue3 10.0.9 → 10.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package/index.vue CHANGED
@@ -80,7 +80,7 @@
80
80
  <!-- 主内容区域 -->
81
81
  <a-layout class="content-layout">
82
82
  <a-layout-content class="canvas-container">
83
- <div ref="canvas" class="canvas" />
83
+ <div ref="canvas" class="canvas" :id="canvasId" />
84
84
  </a-layout-content>
85
85
  <a-layout-sider class="property-panel">
86
86
  <PropertyPanel v-if="modeler" :modeler="modeler" :users="users" :groups="groups" :categorys="categorys" />
@@ -176,6 +176,16 @@ const simpleInit = async () => {
176
176
 
177
177
  console.log('Starting simple initialization...')
178
178
 
179
+ // 强制设置容器样式
180
+ canvas.value.style.width = '100%'
181
+ canvas.value.style.height = '100%'
182
+ canvas.value.style.minHeight = '400px'
183
+ canvas.value.style.display = 'block'
184
+
185
+ // 等待DOM更新
186
+ await nextTick()
187
+ await new Promise(resolve => setTimeout(resolve, 50))
188
+
179
189
  // 创建简单的BPMN模型器实例
180
190
  modeler.value = new Modeler({
181
191
  container: canvas.value,
@@ -195,6 +205,7 @@ const simpleInit = async () => {
195
205
  // 创建基本流程图
196
206
  await modeler.value.importXML(getInitStr())
197
207
 
208
+ isInitialized.value = true
198
209
  console.log('Simple initialization completed successfully')
199
210
  return true
200
211
  } catch (error) {
@@ -203,19 +214,84 @@ const simpleInit = async () => {
203
214
  }
204
215
  }
205
216
 
217
+ // 强制重新初始化方法
218
+ const forceReinit = async () => {
219
+ try {
220
+ console.log('Force reinitializing BPMN Modeler...')
221
+
222
+ // 清理现有实例
223
+ if (modeler.value) {
224
+ modeler.value.destroy()
225
+ modeler.value = null
226
+ }
227
+
228
+ isInitialized.value = false
229
+
230
+ // 等待一段时间
231
+ await new Promise(resolve => setTimeout(resolve, 100))
232
+
233
+ // 重新初始化
234
+ const success = await simpleInit()
235
+
236
+ if (success) {
237
+ console.log('Force reinitialization successful')
238
+ } else {
239
+ console.error('Force reinitialization failed')
240
+ }
241
+
242
+ return success
243
+ } catch (error) {
244
+ console.error('Force reinitialization error:', error)
245
+ return false
246
+ }
247
+ }
248
+
249
+ // 强制刷新BPMN显示
250
+ const forceRefresh = async () => {
251
+ try {
252
+ if (!modeler.value) {
253
+ console.error('Modeler not available for refresh')
254
+ return false
255
+ }
256
+
257
+ console.log('Force refreshing BPMN display...')
258
+
259
+ // 强制重新渲染
260
+ modeler.value.get('canvas').zoom('fit-viewport')
261
+
262
+ // 等待一段时间后调整palette
263
+ setTimeout(() => {
264
+ adjustPalette()
265
+ }, 100)
266
+
267
+ console.log('BPMN display refreshed')
268
+ return true
269
+ } catch (error) {
270
+ console.error('Failed to refresh BPMN display:', error)
271
+ return false
272
+ }
273
+ }
274
+
206
275
  // 暴露给父组件
207
276
  defineExpose({
208
277
  manualInit,
209
278
  simpleInit,
279
+ forceReinit,
280
+ forceRefresh,
281
+ isInitialized,
210
282
  getProcess,
211
283
  saveXML,
212
284
  saveImg,
213
285
  save
214
286
  })
287
+ // 生成唯一的canvas ID
288
+ const canvasId = `bpmn-canvas-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
289
+
215
290
  const canvas = ref<HTMLElement | null>(null)
216
291
  const modeler = ref<Modeler | null>(null)
217
292
  const taskList = ref<any[]>([])
218
293
  const zoom = ref<number>(1)
294
+ const isInitialized = ref<boolean>(false)
219
295
 
220
296
  watch(() => props.xml, (val: string) => {
221
297
  if (val) {
@@ -224,18 +300,29 @@ watch(() => props.xml, (val: string) => {
224
300
  })
225
301
 
226
302
  onMounted(async () => {
227
- // 延迟初始化,确保DOM完全渲染
303
+ console.log('Component mounted, starting initialization...')
304
+
305
+ // 等待DOM完全渲染
228
306
  await nextTick()
229
307
 
308
+ // 强制等待一段时间确保容器就绪
309
+ await new Promise(resolve => setTimeout(resolve, 100))
310
+
230
311
  const initializeModeler = async () => {
231
312
  try {
232
- // 确保容器存在且有尺寸
233
- if (!canvas.value || canvas.value.offsetWidth === 0 || canvas.value.offsetHeight === 0) {
234
- console.log('Canvas container not ready, waiting...')
313
+ // 确保canvas容器存在
314
+ if (!canvas.value) {
315
+ console.error('Canvas ref not found')
235
316
  return false
236
317
  }
237
318
 
238
- console.log('Canvas container found, initializing modeler...')
319
+ // 强制设置容器尺寸
320
+ canvas.value.style.width = '100%'
321
+ canvas.value.style.height = '100%'
322
+ canvas.value.style.minHeight = '400px'
323
+ canvas.value.style.display = 'block'
324
+
325
+ console.log('Canvas container prepared, initializing modeler...')
239
326
 
240
327
  // 生成实例
241
328
  modeler.value = new Modeler({
@@ -247,20 +334,40 @@ onMounted(async () => {
247
334
  ],
248
335
  moddleExtensions: {
249
336
  flowable: flowableModdle
337
+ },
338
+ // 确保画布正确初始化
339
+ canvas: {
340
+ deferUpdate: false
250
341
  }
251
342
  })
252
343
 
253
344
  // 等待下一个tick确保DOM更新
254
345
  await nextTick()
255
346
 
256
- // 新增流程定义
257
- if (!props.xml) {
258
- newDiagram()
259
- } else {
260
- createNewDiagram(props.xml)
261
- }
347
+ // 强制触发BPMN渲染
348
+ setTimeout(async () => {
349
+ try {
350
+ // 标记为已初始化
351
+ isInitialized.value = true
352
+
353
+ // 新增流程定义
354
+ if (!props.xml) {
355
+ await newDiagram()
356
+ } else {
357
+ await createNewDiagram(props.xml)
358
+ }
359
+
360
+ // 强制刷新画布
361
+ if (modeler.value) {
362
+ modeler.value.get('canvas').zoom('fit-viewport')
363
+ }
364
+
365
+ console.log('BPMN Modeler initialized successfully')
366
+ } catch (error) {
367
+ console.error('Error in post-initialization:', error)
368
+ }
369
+ }, 200)
262
370
 
263
- console.log('BPMN Modeler initialized successfully')
264
371
  return true
265
372
  } catch (error) {
266
373
  console.error('BPMN Modeler initialization failed:', error)
@@ -268,50 +375,35 @@ onMounted(async () => {
268
375
  }
269
376
  }
270
377
 
271
- // 立即尝试初始化
378
+ // 尝试初始化
272
379
  let initialized = await initializeModeler()
273
380
 
274
- // 如果初始化失败,使用多种策略重试
381
+ // 如果失败,使用更激进的重试策略
275
382
  if (!initialized) {
276
- // 策略1: 使用MutationObserver监听DOM变化
277
- const observer = new MutationObserver(async () => {
278
- if (canvas.value && canvas.value.offsetWidth > 0 && canvas.value.offsetHeight > 0) {
279
- observer.disconnect()
280
- await initializeModeler()
281
- }
282
- })
383
+ console.log('Initial initialization failed, trying alternative approach...')
283
384
 
284
- // 监听父容器变化
285
- if (canvas.value?.parentElement) {
286
- observer.observe(canvas.value.parentElement, {
287
- childList: true,
288
- subtree: true,
289
- attributes: true,
290
- attributeFilter: ['style', 'class']
385
+ // 使用requestAnimationFrame确保在下一帧尝试
386
+ const tryWithRAF = () => {
387
+ requestAnimationFrame(async () => {
388
+ initialized = await initializeModeler()
389
+ if (!initialized) {
390
+ // 如果还是失败,再等一帧
391
+ requestAnimationFrame(async () => {
392
+ initialized = await initializeModeler()
393
+ if (!initialized) {
394
+ console.error('All initialization attempts failed')
395
+ }
396
+ })
397
+ }
291
398
  })
292
399
  }
293
400
 
294
- // 策略2: 定时重试(最多10秒)
295
- let retryCount = 0
296
- const maxRetries = 50 // 10秒,每200ms重试一次
297
-
298
- const retryTimer = setInterval(async () => {
299
- retryCount++
300
- initialized = await initializeModeler()
301
-
302
- if (initialized || retryCount >= maxRetries) {
303
- clearInterval(retryTimer)
304
- observer.disconnect()
305
- if (!initialized) {
306
- console.error('Failed to initialize BPMN Modeler after maximum retries')
307
- }
308
- }
309
- }, 200)
401
+ tryWithRAF()
310
402
  }
311
403
  })
312
404
 
313
- const newDiagram = (): void => {
314
- createNewDiagram(getInitStr())
405
+ const newDiagram = async (): Promise<void> => {
406
+ await createNewDiagram(getInitStr())
315
407
  }
316
408
 
317
409
  // 让图能自适应屏幕
@@ -401,77 +493,64 @@ const createNewDiagram = async (data: string): Promise<void> => {
401
493
  // 调整左侧工具栏排版
402
494
  const adjustPalette = (): void => {
403
495
  try {
404
- // 获取 bpmn 设计器实例
405
- const canvasElement = canvas.value
406
- if (!canvasElement) {
407
- console.warn('Canvas element not found for palette adjustment')
408
- return
409
- }
410
-
411
- // 检查DOM结构是否存在
412
- if (!canvasElement.children || canvasElement.children.length === 0) {
413
- console.warn('Canvas children not found for palette adjustment')
414
- return
415
- }
416
-
417
- const djsPalette = canvasElement.children[0]?.children[1]?.children[4] as HTMLElement
418
- if (!djsPalette) {
419
- console.warn('BPMN palette element not found')
420
- return
421
- }
422
-
423
- const djsPalStyle: Record<string, string> = {
424
- width: '130px',
425
- padding: '5px',
426
- background: 'white',
427
- left: '20px',
428
- borderRadius: '0'
429
- }
430
- for (const key in djsPalStyle) {
431
- (djsPalette.style as any)[key] = djsPalStyle[key]
432
- }
433
- const palette = djsPalette.children[0] as HTMLElement
434
- if (!palette) {
435
- console.warn('Palette children not found')
436
- return
437
- }
438
-
439
- const allGroups = palette.children
440
- if (allGroups.length === 0) {
441
- console.warn('No palette groups found')
442
- return
443
- }
444
-
445
- ;(allGroups[0] as HTMLElement).style.display = 'none'
446
- // 修改控件样式
447
- for (let gKey = 0; gKey < allGroups.length; gKey++) {
448
- const group = allGroups[gKey] as HTMLElement
449
- for (let cKey = 0; cKey < group.children.length; cKey++) {
450
- const control = group.children[cKey] as HTMLElement
451
- const controlStyle: Record<string, string> = {
452
- display: 'flex',
453
- justifyContent: 'flex-start',
454
- alignItems: 'center',
455
- width: '100%',
456
- padding: '5px'
496
+ // 等待DOM完全渲染
497
+ setTimeout(() => {
498
+ try {
499
+ // 获取 bpmn 设计器实例
500
+ const canvasElement = canvas.value
501
+ if (!canvasElement) {
502
+ console.warn('Canvas element not found for palette adjustment')
503
+ return
457
504
  }
458
- if (
459
- control.className &&
460
- control.dataset &&
461
- control.className.indexOf('entry') !== -1
462
- ) {
463
- const controlProps = new BpmData().getControl(
464
- control.dataset.action
465
- )
466
- control.innerHTML = `<div style='font-size: 14px;font-weight:500;margin-left:15px;'>${
467
- controlProps['title']
468
- }</div>`
469
- for (const csKey in controlStyle) {
470
- (control.style as any)[csKey] = controlStyle[csKey]
471
- }
505
+
506
+ // 查找BPMN palette元素
507
+ const djsPalette = document.querySelector('.djs-palette') as HTMLElement
508
+ if (!djsPalette) {
509
+ console.warn('BPMN palette element not found')
510
+ return
472
511
  }
512
+
513
+ console.log('Found palette element, adjusting styles...')
514
+
515
+ // 设置palette样式
516
+ djsPalette.style.width = '160px'
517
+ djsPalette.style.padding = '8px'
518
+ djsPalette.style.background = 'white'
519
+ djsPalette.style.left = '20px'
520
+ djsPalette.style.top = '20px'
521
+ djsPalette.style.borderRadius = '8px'
522
+ djsPalette.style.boxShadow = '0 2px 8px rgba(0,0,0,0.1)'
523
+ djsPalette.style.zIndex = '1000'
524
+
525
+ // 查找palette entries
526
+ const paletteEntries = djsPalette.querySelector('.djs-palette-entries') as HTMLElement
527
+ if (paletteEntries) {
528
+ paletteEntries.style.padding = '8px'
529
+
530
+ // 调整每个entry的样式
531
+ const entries = paletteEntries.querySelectorAll('.djs-palette-entry')
532
+ entries.forEach((entry: HTMLElement) => {
533
+ entry.style.margin = '4px 0'
534
+ entry.style.padding = '8px'
535
+ entry.style.borderRadius = '4px'
536
+ entry.style.cursor = 'pointer'
537
+ entry.style.transition = 'background-color 0.2s'
538
+
539
+ // 添加hover效果
540
+ entry.addEventListener('mouseenter', () => {
541
+ entry.style.backgroundColor = '#f0f0f0'
542
+ })
543
+ entry.addEventListener('mouseleave', () => {
544
+ entry.style.backgroundColor = 'transparent'
545
+ })
546
+ })
547
+ }
548
+
549
+ console.log('Palette adjustment completed')
550
+ } catch (e) {
551
+ console.warn('Failed to adjust palette:', e)
473
552
  }
474
- }
553
+ }, 300)
475
554
  } catch (e) {
476
555
  console.warn('Failed to adjust palette:', e)
477
556
  }
@@ -613,6 +692,52 @@ const downloadFile = (filename: string, data: string, type: string): void => {
613
692
  @import url('https://cdn.jsdelivr.net/npm/bpmn-js@8.10.0/dist/assets/bpmn-font/css/bpmn-codes.css');
614
693
  @import url('https://cdn.jsdelivr.net/npm/bpmn-js@8.10.0/dist/assets/bpmn-font/css/bpmn-embedded.css');
615
694
 
695
+ /* 强制BPMN样式 */
696
+ .djs-container {
697
+ width: 100% !important;
698
+ height: 100% !important;
699
+ position: relative !important;
700
+ }
701
+
702
+ .djs-canvas {
703
+ width: 100% !important;
704
+ height: 100% !important;
705
+ background: white !important;
706
+ }
707
+
708
+ .djs-palette {
709
+ position: absolute !important;
710
+ left: 20px !important;
711
+ top: 20px !important;
712
+ z-index: 10 !important;
713
+ background: white !important;
714
+ border: 1px solid #ccc !important;
715
+ border-radius: 4px !important;
716
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1) !important;
717
+ }
718
+
719
+ .djs-palette-entries {
720
+ padding: 8px !important;
721
+ }
722
+
723
+ .djs-palette-entry {
724
+ margin: 4px 0 !important;
725
+ padding: 8px !important;
726
+ border-radius: 4px !important;
727
+ cursor: pointer !important;
728
+ transition: background-color 0.2s !important;
729
+ }
730
+
731
+ .djs-palette-entry:hover {
732
+ background-color: #f0f0f0 !important;
733
+ }
734
+
735
+ /* 确保viewport正确显示 */
736
+ .viewport {
737
+ width: 100% !important;
738
+ height: 100% !important;
739
+ }
740
+
616
741
  /* 视图模式样式 */
617
742
  .view-mode {
618
743
  .ant-layout-header,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "workflow-bpmn-modeler-andtv-vue3",
3
- "version": "10.0.9",
3
+ "version": "10.1.1",
4
4
  "description": "基于 `Vue3` + `TypeScript` + `Ant Design Vue` 和 `bpmn.io@8.10` ,实现 flowable 的 modeler 模型设计器",
5
5
  "main": "dist/workflow-bpmn-modeler-andtv-vue3.common.js",
6
6
  "module": "dist/workflow-bpmn-modeler-andtv-vue3.common.js",