index.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <!-- 第一步,通过流程定义的列表,选择对应的流程 -->
  3. <ContentWrap v-if="!selectProcessInstance">
  4. <el-table v-loading="loading" :data="list">
  5. <el-table-column align="center" label="流程名称" prop="name" />
  6. <el-table-column align="center" label="流程分类" prop="category">
  7. <template #default="scope">
  8. <dict-tag :type="DICT_TYPE.BPM_MODEL_CATEGORY" :value="scope.row.category" />
  9. </template>
  10. </el-table-column>
  11. <el-table-column align="center" label="流程版本" prop="version">
  12. <template #default="scope">
  13. <el-tag>v{{ scope.row.version }}</el-tag>
  14. </template>
  15. </el-table-column>
  16. <el-table-column align="center" label="流程描述" prop="description" />
  17. <el-table-column align="center" label="操作">
  18. <template #default="scope">
  19. <el-button link type="primary" @click="handleSelect(scope.row)">
  20. <Icon icon="ep:plus" />
  21. 选择
  22. </el-button>
  23. </template>
  24. </el-table-column>
  25. </el-table>
  26. </ContentWrap>
  27. <!-- 第二步,填写表单,进行流程的提交 -->
  28. <ContentWrap v-else>
  29. <el-card class="box-card">
  30. <div class="clearfix">
  31. <span class="el-icon-document">申请信息【{{ selectProcessInstance.name }}】</span>
  32. <el-button style="float: right" type="primary" @click="selectProcessInstance = undefined">
  33. <Icon icon="ep:delete" />
  34. 选择其它流程
  35. </el-button>
  36. </div>
  37. <el-col :offset="6" :span="16" style="margin-top: 20px">
  38. <my-form-create
  39. v-model:api="fApi"
  40. :option="detailForm.option"
  41. :rule="detailForm.rule"
  42. @submit="submitForm"
  43. />
  44. </el-col>
  45. </el-card>
  46. <!-- 流程图预览 -->
  47. <ProcessInstanceBpmnViewer :bpmn-xml="bpmnXML as any" />
  48. </ContentWrap>
  49. </template>
  50. <script lang="ts" setup>
  51. import { DICT_TYPE } from '@/utils/dict'
  52. import * as DefinitionApi from '@/api/bpm/definition'
  53. import * as ProcessInstanceApi from '@/api/bpm/processInstance'
  54. import { setConfAndFields2 } from '@/utils/formCreate'
  55. import type { ApiAttrs } from '@form-create/element-ui/types/config'
  56. import ProcessInstanceBpmnViewer from '../detail/ProcessInstanceBpmnViewer.vue'
  57. defineOptions({ name: 'BpmProcessInstanceCreate' })
  58. const router = useRouter() // 路由
  59. const message = useMessage() // 消息
  60. // ========== 列表相关 ==========
  61. const loading = ref(true) // 列表的加载中
  62. const list = ref([]) // 列表的数据
  63. const queryParams = reactive({
  64. suspensionState: 1
  65. })
  66. /** 查询列表 */
  67. const getList = async () => {
  68. loading.value = true
  69. try {
  70. list.value = await DefinitionApi.getProcessDefinitionList(queryParams)
  71. } finally {
  72. loading.value = false
  73. }
  74. }
  75. // ========== 表单相关 ==========
  76. const bpmnXML = ref(null) // BPMN 数据
  77. const fApi = ref<ApiAttrs>()
  78. const detailForm = ref({
  79. // 流程表单详情
  80. rule: [],
  81. option: {}
  82. })
  83. const selectProcessInstance = ref() // 选择的流程实例
  84. /** 处理选择流程的按钮操作 **/
  85. const handleSelect = async (row) => {
  86. // 设置选择的流程
  87. selectProcessInstance.value = row
  88. // 情况一:流程表单
  89. if (row.formType == 10) {
  90. // 设置表单
  91. setConfAndFields2(detailForm, row.formConf, row.formFields)
  92. // 加载流程图
  93. bpmnXML.value = await DefinitionApi.getProcessDefinitionBpmnXML(row.id)
  94. // 情况二:业务表单
  95. } else if (row.formCustomCreatePath) {
  96. await router.push({
  97. path: row.formCustomCreatePath
  98. })
  99. // 这里暂时无需加载流程图,因为跳出到另外个 Tab;
  100. }
  101. }
  102. /** 提交按钮 */
  103. const submitForm = async (formData) => {
  104. if (!fApi.value || !selectProcessInstance.value) {
  105. return
  106. }
  107. // 提交请求
  108. fApi.value.btn.loading(true)
  109. try {
  110. await ProcessInstanceApi.createProcessInstance({
  111. processDefinitionId: selectProcessInstance.value.id,
  112. variables: formData
  113. })
  114. // 提示
  115. message.success('发起流程成功')
  116. router.go(-1)
  117. } finally {
  118. fApi.value.btn.loading(false)
  119. }
  120. }
  121. /** 初始化 */
  122. onMounted(() => {
  123. getList()
  124. })
  125. </script>