create.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="app-container">
  3. <!-- 第一步,通过流程定义的列表,选择对应的流程 -->
  4. <div v-if="!selectProcessInstance">
  5. <el-table v-loading="loading" :data="list">
  6. <el-table-column label="流程名称" align="center" prop="name" width="200">
  7. <template slot-scope="scope">
  8. <el-button type="text" @click="handleBpmnDetail(scope.row)">
  9. <span>{{ scope.row.name }}</span>
  10. </el-button>
  11. </template>
  12. </el-table-column>
  13. <el-table-column label="流程分类" align="center" prop="category" width="100">
  14. <template slot-scope="scope">
  15. <dict-tag :type="DICT_TYPE.BPM_MODEL_CATEGORY" :value="scope.row.category" />
  16. </template>
  17. </el-table-column>
  18. <el-table-column label="流程版本" align="center" prop="processDefinition.version" width="80">
  19. <template slot-scope="scope">
  20. <el-tag size="medium" v-if="scope.row">v{{ scope.row.version }}</el-tag>
  21. </template>
  22. </el-table-column>
  23. <el-table-column label="流程描述" align="center" prop="description" width="300" show-overflow-tooltip />
  24. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  25. <template slot-scope="scope">
  26. <el-button type="text" size="small" icon="el-icon-plus" @click="handleSelect(scope.row)">选择</el-button>
  27. </template>
  28. </el-table-column>
  29. </el-table>
  30. </div>
  31. <!-- 第二步,填写表单,进行流程的提交 -->
  32. <div v-else>
  33. <el-card class="box-card" >
  34. <div slot="header" class="clearfix">
  35. <span class="el-icon-document">申请信息【{{ selectProcessInstance.name }}】</span>
  36. <el-button style="float: right;" type="primary" @click="selectProcessInstance = undefined">选择其它流程</el-button>
  37. </div>
  38. <el-col :span="16" :offset="6">
  39. <div>
  40. <parser :key="new Date().getTime()" :form-conf="detailForm" @submit="submitForm" />
  41. </div>
  42. </el-col>
  43. </el-card>
  44. <el-card class="box-card">
  45. <div slot="header" class="clearfix">
  46. <span class="el-icon-picture-outline">流程图</span>
  47. </div>
  48. <my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" />
  49. </el-card>
  50. </div>
  51. </div>
  52. </template>
  53. <script>
  54. import {getProcessDefinitionBpmnXML, getProcessDefinitionList} from "@/api/bpm/definition";
  55. import {DICT_TYPE, getDictDatas} from "@/utils/dict";
  56. import {decodeFields} from "@/utils/formGenerator";
  57. import Parser from '@/components/parser/Parser'
  58. import {createProcessInstance} from "@/api/bpm/processInstance";
  59. // 流程实例的发起
  60. export default {
  61. name: "ProcessInstanceCreate",
  62. components: {
  63. Parser
  64. },
  65. data() {
  66. return {
  67. // 遮罩层
  68. loading: true,
  69. // 表格数据
  70. list: [],
  71. // 流程表单详情
  72. detailForm: {
  73. fields: []
  74. },
  75. // BPMN 数据
  76. bpmnXML: null,
  77. bpmnControlForm: {
  78. prefix: "activiti"
  79. },
  80. // 流程表单
  81. selectProcessInstance: undefined, // 选择的流程实例
  82. // 数据字典
  83. categoryDictDatas: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY),
  84. };
  85. },
  86. created() {
  87. this.getList();
  88. },
  89. methods: {
  90. /** 查询流程定义列表 */
  91. getList() {
  92. this.loading = true;
  93. getProcessDefinitionList({
  94. suspensionState: 1
  95. }).then(response => {
  96. this.list = response.data
  97. this.loading = false
  98. }
  99. );
  100. },
  101. /** 处理选择流程的按钮操作 **/
  102. handleSelect(row) {
  103. // 设置选择的流程
  104. this.selectProcessInstance = row;
  105. // 流程表单
  106. if (row.formId) {
  107. // 设置对应的表单
  108. this.detailForm = {
  109. ...JSON.parse(row.formConf),
  110. fields: decodeFields(row.formFields)
  111. }
  112. // 加载流程图
  113. getProcessDefinitionBpmnXML(row.id).then(response => {
  114. this.bpmnXML = response.data
  115. })
  116. } else if (row.formCustomCreatePath) {
  117. this.$router.push({ path: row.formCustomCreatePath});
  118. // 这里暂时无需加载流程图,因为跳出到另外个 Tab;
  119. }
  120. },
  121. /** 提交按钮 */
  122. submitForm(params) {
  123. if (!params) {
  124. return;
  125. }
  126. // 设置表单禁用
  127. const conf = params.conf;
  128. conf.disabled = true; // 表单禁用
  129. conf.formBtns = false; // 按钮隐藏
  130. // 提交表单,创建流程
  131. const variables = params.values;
  132. createProcessInstance({
  133. processDefinitionId: this.selectProcessInstance.id,
  134. variables: variables
  135. }).then(response => {
  136. this.$modal.msgSuccess("发起流程成功");
  137. // 关闭当前窗口
  138. this.$tab.closeOpenPage();
  139. this.$router.go(-1);
  140. }).catch(() => {
  141. conf.disabled = false; // 表单开启
  142. conf.formBtns = true; // 按钮展示
  143. })
  144. },
  145. }
  146. };
  147. </script>
  148. <style lang="scss">
  149. .my-process-designer {
  150. height: calc(100vh - 200px);
  151. }
  152. .box-card {
  153. width: 100%;
  154. margin-bottom: 20px;
  155. }
  156. </style>