index.vue 4.0 KB

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