create.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. <span>{{ getDictDataLabel(DICT_TYPE.BPM_MODEL_CATEGORY, scope.row.category) }}</span>
  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 {getForm} from "@/api/bpm/form";
  57. import {decodeFields} from "@/utils/formGenerator";
  58. import Parser from '@/components/parser/Parser'
  59. import {createProcessInstance} from "@/api/bpm/processInstance";
  60. export default {
  61. name: "processDefinition",
  62. components: {
  63. Parser
  64. },
  65. data() {
  66. return {
  67. // 遮罩层
  68. loading: true,
  69. // 总条数
  70. total: 0,
  71. // 表格数据
  72. list: [],
  73. // 流程表单详情
  74. detailForm: {
  75. fields: []
  76. },
  77. // BPMN 数据
  78. bpmnXML: null,
  79. bpmnControlForm: {
  80. prefix: "activiti"
  81. },
  82. // 流程表单
  83. selectProcessInstance: undefined, // 选择的流程实例
  84. // 数据字典
  85. categoryDictDatas: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY),
  86. };
  87. },
  88. created() {
  89. this.getList();
  90. },
  91. methods: {
  92. /** 查询流程定义列表 */
  93. getList() {
  94. this.loading = true;
  95. getProcessDefinitionList({
  96. suspensionState: 1
  97. }).then(response => {
  98. this.list = response.data
  99. this.loading = false
  100. }
  101. );
  102. },
  103. /** 处理选择流程的按钮操作 **/
  104. handleSelect(row) {
  105. // 如果无表单,则无法发起流程
  106. if (!row.formId) {
  107. this.$message.error('该流程未绑定表单,无法发起流程!请重新选择你要发起的流程');
  108. return;
  109. }
  110. // 设置选择的流程
  111. this.selectProcessInstance = row;
  112. // 加载对应的表单
  113. getForm(row.formId).then(response => {
  114. // 设置值
  115. const data = response.data
  116. this.detailForm = {
  117. ...JSON.parse(data.conf),
  118. fields: decodeFields(data.fields)
  119. }
  120. });
  121. // 加载流程图
  122. getProcessDefinitionBpmnXML(row.id).then(response => {
  123. this.bpmnXML = response.data
  124. })
  125. },
  126. /** 提交按钮 */
  127. submitForm(params) {
  128. if (!params) {
  129. return;
  130. }
  131. // 设置表单禁用
  132. const conf = params.conf;
  133. conf.disabled = true; // 表单禁用
  134. conf.formBtns = false; // 按钮隐藏
  135. // 提交表单,创建流程
  136. const variables = params.values;
  137. createProcessInstance({
  138. processDefinitionId: this.selectProcessInstance.id,
  139. variables: variables
  140. }).then(response => {
  141. this.msgSuccess("发起流程成功");
  142. // 关闭当前窗口
  143. this.$store.dispatch("tagsView/delView", this.$route);
  144. this.$router.go(-1);
  145. }).catch(() => {
  146. conf.disabled = false; // 表单开启
  147. conf.formBtns = true; // 按钮展示
  148. })
  149. },
  150. }
  151. };
  152. </script>
  153. <style lang="scss">
  154. .my-process-designer {
  155. height: calc(100vh - 200px);
  156. }
  157. .box-card {
  158. width: 100%;
  159. margin-bottom: 20px;
  160. }
  161. </style>