create.vue 5.2 KB

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