gaoluyang
9 天以前 86966ec9a83b93decbd93fc8ce2be1882d4c9775
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<script lang="ts" setup>
import type { Ref } from 'vue';
 
import { computed, inject, nextTick, ref } from 'vue';
 
import { BpmModelType } from '@vben/constants';
 
import BpmModelEditor from './bpm-model-editor.vue';
import SimpleModelDesign from './simple-model-design.vue';
 
const modelData = defineModel<any>(); // 创建本地数据副本
const processData = inject('processData') as Ref;
 
const simpleDesign = ref();
 
/** 表单校验 */
async function validate() {
  // 获取最新的流程数据
  if (!processData.value) {
    throw new Error('请设计流程');
  }
  if (modelData.value.type === BpmModelType.SIMPLE) {
    // 简易设计器校验
    const validateResult = await simpleDesign.value?.validateConfig();
    if (!validateResult) {
      throw new Error('请完善设计配置');
    }
  }
  return true;
}
 
/** 处理设计器保存成功 */
async function handleDesignSuccess(data?: any) {
  if (data) {
    // 创建新的对象以触发响应式更新
    const newModelData = {
      ...modelData.value,
      bpmnXml: modelData.value.type === BpmModelType.BPMN ? data : null,
      simpleModel: modelData.value.type === BpmModelType.BPMN ? null : data,
    };
    // 使用 emit 更新父组件的数据
    await nextTick();
    // 更新表单的模型数据部分
    modelData.value = newModelData;
  }
}
 
/** 是否显示设计器 */
const showDesigner = computed(() => {
  return Boolean(modelData.value?.key && modelData.value?.name);
});
 
defineExpose({ validate });
</script>
<template>
  <div class="h-full">
    <!-- BPMN设计器 -->
    <template v-if="modelData.type === BpmModelType.BPMN">
      <BpmModelEditor
        v-if="showDesigner"
        :model-id="modelData.id"
        :model-key="modelData.key"
        :model-name="modelData.name"
        @success="handleDesignSuccess"
      />
    </template>
    <!-- Simple设计器 -->
    <template v-else>
      <SimpleModelDesign
        v-if="showDesigner"
        :model-name="modelData.name"
        :model-form-id="modelData.formId"
        :model-form-type="modelData.formType"
        :start-user-ids="modelData.startUserIds"
        :start-dept-ids="modelData.startDeptIds"
        @success="handleDesignSuccess"
        ref="simpleDesign"
      />
    </template>
  </div>
</template>