modelEditor.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <!-- 流程设计器,负责绘制流程等 -->
  3. <my-process-designer
  4. key="designer"
  5. v-if="xmlString !== undefined"
  6. v-model="xmlString"
  7. :value="xmlString"
  8. v-bind="controlForm"
  9. keyboard
  10. ref="processDesigner"
  11. @init-finished="initModeler"
  12. :additionalModel="controlForm.additionalModel"
  13. @save="save"
  14. />
  15. <!-- 流程属性器,负责编辑每个流程节点的属性 -->
  16. <my-properties-panel
  17. key="penal"
  18. :bpmnModeler="modeler"
  19. :prefix="controlForm.prefix"
  20. class="process-panel"
  21. :model="model"
  22. />
  23. </template>
  24. <script setup lang="ts">
  25. // 自定义元素选中时的弹出菜单(修改 默认任务 为 用户任务)
  26. import CustomContentPadProvider from '@/components/bpmnProcessDesigner/package/designer/plugins/content-pad'
  27. // 自定义左侧菜单(修改 默认任务 为 用户任务)
  28. import CustomPaletteProvider from '@/components/bpmnProcessDesigner/package/designer/plugins/palette'
  29. import * as ModelApi from '@/api/bpm/model'
  30. const router = useRouter() // 路由
  31. const { query } = useRoute() // 路由的查询
  32. const message = useMessage() // 国际化
  33. const xmlString = ref(undefined) // BPMN XML
  34. const modeler = ref(null)
  35. const controlForm = ref({
  36. simulation: true,
  37. labelEditing: false,
  38. labelVisible: false,
  39. prefix: 'flowable',
  40. headerButtonSize: 'mini',
  41. additionalModel: [CustomContentPadProvider, CustomPaletteProvider]
  42. })
  43. const model = ref<ModelApi.ModelVO>() // 流程模型的信息
  44. /** 初始化 modeler */
  45. const initModeler = (item) => {
  46. setTimeout(() => {
  47. modeler.value = item
  48. }, 10)
  49. }
  50. /** 添加/修改模型 */
  51. const save = async (bpmnXml) => {
  52. const data = {
  53. ...model.value,
  54. bpmnXml: bpmnXml // bpmnXml 只是初始化流程图,后续修改无法通过它获得
  55. } as unknown as ModelApi.ModelVO
  56. // 提交
  57. if (data.id) {
  58. await ModelApi.updateModelApi(data)
  59. message.success('修改成功')
  60. } else {
  61. await ModelApi.createModelApi(data)
  62. message.success('新增成功')
  63. }
  64. // 跳转回去
  65. close()
  66. }
  67. /** 关闭按钮 */
  68. const close = () => {
  69. router.push({ path: '/bpm/manager/model' })
  70. }
  71. /** 初始化 */
  72. onMounted(async () => {
  73. const modelId = query.modelId as unknown as number
  74. if (!modelId) {
  75. message.error('缺少模型 modelId 编号')
  76. return
  77. }
  78. // 查询模型
  79. const data = await ModelApi.getModel(modelId)
  80. xmlString.value = data.bpmnXml
  81. model.value = {
  82. ...data,
  83. bpmnXml: undefined // 清空 bpmnXml 属性
  84. }
  85. })
  86. </script>
  87. <style lang="scss">
  88. .control-form {
  89. .el-radio {
  90. width: 100%;
  91. line-height: 32px;
  92. }
  93. }
  94. .element-overlays {
  95. box-sizing: border-box;
  96. padding: 8px;
  97. background: rgba(0, 0, 0, 0.6);
  98. border-radius: 4px;
  99. color: #fafafa;
  100. }
  101. .my-process-designer {
  102. height: calc(100vh - 84px);
  103. }
  104. .process-panel__container {
  105. position: absolute;
  106. right: 0;
  107. top: 55px;
  108. height: calc(100vh - 84px);
  109. }
  110. </style>