detail.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div class="app-container">
  3. <!-- TODO 审批信息 -->
  4. <!-- 申请信息 -->
  5. <el-card class="box-card" v-loading="processInstanceLoading">
  6. <div slot="header" class="clearfix">
  7. <span class="el-icon-document">申请信息【{{ processInstance.name }}】</span>
  8. </div>
  9. <el-col :span="16" :offset="6">
  10. <div>
  11. <parser :key="new Date().getTime()" :form-conf="detailForm" @submit="submitForm" />
  12. </div>
  13. </el-col>
  14. </el-card>
  15. <!-- TODO 审批记录 -->
  16. <!-- TODO 流程图 -->
  17. <el-card class="box-card" v-loading="processInstanceLoading">
  18. <div slot="header" class="clearfix">
  19. <span class="el-icon-picture-outline">流程图</span>
  20. </div>
  21. <my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" />
  22. </el-card>
  23. </div>
  24. </template>
  25. <script>
  26. import {getProcessDefinitionBpmnXML, getProcessDefinitionList} from "@/api/bpm/definition";
  27. import {DICT_TYPE, getDictDatas} from "@/utils/dict";
  28. import {getForm} from "@/api/bpm/form";
  29. import {decodeFields} from "@/utils/formGenerator";
  30. import Parser from '@/components/parser/Parser'
  31. import {createProcessInstance, getMyProcessInstancePage, getProcessInstance} from "@/api/bpm/processInstance";
  32. import {getHistoricTaskListByProcessInstanceId} from "@/api/bpm/task";
  33. // 流程实例的详情页,可用于审批
  34. export default {
  35. name: "ProcessInstanceDetail",
  36. components: {
  37. Parser
  38. },
  39. data() {
  40. return {
  41. // 遮罩层
  42. processInstanceLoading: true,
  43. // 流程实例
  44. id: undefined, // 流程实例的编号
  45. processInstance: {},
  46. // 流程表单详情
  47. detailForm: {
  48. fields: []
  49. },
  50. // BPMN 数据
  51. bpmnXML: null,
  52. bpmnControlForm: {
  53. prefix: "activiti"
  54. },
  55. // 审批记录
  56. historicTasksLoad: true,
  57. historicTasks: [],
  58. // 数据字典
  59. categoryDictDatas: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY),
  60. };
  61. },
  62. created() {
  63. this.id = this.$route.query.id;
  64. if (!this.id) {
  65. this.$message.error('未传递 id 参数,无法查看流程信息');
  66. return;
  67. }
  68. this.getDetail();
  69. },
  70. methods: {
  71. /** 获得流程实例 */
  72. getDetail() {
  73. // 获得流程实例相关
  74. this.processInstanceLoading = true;
  75. getProcessInstance(this.id).then(response => {
  76. if (!response.data) {
  77. this.$message.error('查询不到流程信息!');
  78. return;
  79. }
  80. // 设置流程信息
  81. this.processInstance = response.data;
  82. // 设置表单信息
  83. this.detailForm = {
  84. ...JSON.parse(this.processInstance.processDefinition.formConf),
  85. disabled: true, // 表单禁用
  86. formBtns: false, // 按钮隐藏
  87. fields: decodeFields(this.processInstance.processDefinition.formFields)
  88. }
  89. // 设置表单的值
  90. this.detailForm.fields.forEach(item => {
  91. const val = this.processInstance.formVariables[item.__vModel__]
  92. if (val) {
  93. item.__config__.defaultValue = val
  94. }
  95. })
  96. // 加载流程图
  97. getProcessDefinitionBpmnXML(this.processInstance.processDefinition.id).then(response => {
  98. this.bpmnXML = response.data
  99. })
  100. // 取消加载中
  101. this.processInstanceLoading = false;
  102. });
  103. // 获得流程任务列表(审批记录)
  104. this.historicTasksLoad = true;
  105. getHistoricTaskListByProcessInstanceId(this.id).then(response => {
  106. this.historicTasks = response.data;
  107. this.historicTasksLoad = true;
  108. });
  109. },
  110. /** 处理选择流程的按钮操作 **/
  111. handleSelect(row) {
  112. // 设置选择的流程
  113. this.selectProcessInstance = row;
  114. // 流程表单
  115. if (row.formId) {
  116. // 设置对应的表单
  117. this.detailForm = {
  118. ...JSON.parse(row.formConf),
  119. fields: decodeFields(row.formFields)
  120. }
  121. } else if (row.formCustomCreatePath) {
  122. this.$router.push({ path: row.formCustomCreatePath});
  123. // 这里暂时无需加载流程图,因为跳出到另外个 Tab;
  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>