1. 修改 Parser.vue 组件,实现 submit 传递 conf 和 values 参数

2. 完成流程创建的前端 UI 界面
This commit is contained in:
YunaiV 2022-01-09 00:17:52 +08:00
parent 749cb5d762
commit 8a10568b24
7 changed files with 147 additions and 88 deletions

View File

@ -17,6 +17,7 @@ import org.mapstruct.factory.Mappers;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Function;
/** /**
* Bpm 流程定义的 Convert * Bpm 流程定义的 Convert
@ -59,10 +60,18 @@ public interface BpmDefinitionConvert {
BpmProcessDefinitionExtDO convert2(BpmDefinitionCreateReqDTO bean); BpmProcessDefinitionExtDO convert2(BpmDefinitionCreateReqDTO bean);
@Named("convertList3") default List<BpmProcessDefinitionRespVO> convertList3(List<ProcessDefinition> list,
List<BpmProcessDefinitionRespVO> convertList3(List<ProcessDefinition> list); Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap) {
return CollectionUtils.convertList(list, processDefinition -> {
BpmProcessDefinitionRespVO respVO = convert3(processDefinition);
BpmProcessDefinitionExtDO processDefinitionExtDO = processDefinitionDOMap.get(processDefinition.getId());
if (processDefinitionExtDO != null) {
respVO.setFormId(processDefinitionExtDO.getFormId());
}
return respVO;
});
}
@Named("convert3")
@Mapping(source = "suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState") @Mapping(source = "suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState")
BpmProcessDefinitionRespVO convert3(ProcessDefinition bean); BpmProcessDefinitionRespVO convert3(ProcessDefinition bean);

View File

@ -79,8 +79,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
Map<String, Deployment> deploymentMap = getDeploymentMap(deploymentIds); Map<String, Deployment> deploymentMap = getDeploymentMap(deploymentIds);
// 获得 BpmProcessDefinitionDO Map // 获得 BpmProcessDefinitionDO Map
List<BpmProcessDefinitionExtDO> processDefinitionDOs = Collections.emptyList(); List<BpmProcessDefinitionExtDO> processDefinitionDOs = processDefinitionMapper.selectListByProcessDefinitionIds(
processDefinitionDOs = processDefinitionMapper.selectListByProcessDefinitionIds(
convertList(processDefinitions, ProcessDefinition::getId)); convertList(processDefinitions, ProcessDefinition::getId));
Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs, Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs,
BpmProcessDefinitionExtDO::getProcessDefinitionId); BpmProcessDefinitionExtDO::getProcessDefinitionId);
@ -104,8 +103,16 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
} else if (Objects.equals(SuspensionState.ACTIVE.getStateCode(), listReqVO.getSuspensionState())) { } else if (Objects.equals(SuspensionState.ACTIVE.getStateCode(), listReqVO.getSuspensionState())) {
definitionQuery.active(); definitionQuery.active();
} }
// 执行查询
List<ProcessDefinition> processDefinitions = definitionQuery.list();
// 获得 BpmProcessDefinitionDO Map
List<BpmProcessDefinitionExtDO> processDefinitionDOs = processDefinitionMapper.selectListByProcessDefinitionIds(
convertList(processDefinitions, ProcessDefinition::getId));
Map<String, BpmProcessDefinitionExtDO> processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs,
BpmProcessDefinitionExtDO::getProcessDefinitionId);
// 执行查询并返回 // 执行查询并返回
return BpmDefinitionConvert.INSTANCE.convertList3(definitionQuery.list()); return BpmDefinitionConvert.INSTANCE.convertList3(processDefinitions, processDefinitionDOMap);
} }
@Override @Override

View File

@ -8,6 +8,14 @@ export function getProcessDefinitionPage(query) {
}) })
} }
export function getProcessDefinitionList(query) {
return request({
url: '/bpm/process-definition/list',
method: 'get',
params: query
})
}
export function getProcessDefinitionBpmnXML(id) { export function getProcessDefinitionBpmnXML(id) {
return request({ return request({
url: '/bpm/process-definition/get-bpmn-xml?id=' + id, url: '/bpm/process-definition/get-bpmn-xml?id=' + id,

View File

@ -8,6 +8,14 @@ export function getMyProcessInstancePage(query) {
}) })
} }
export function createProcessInstance(data) {
return request({
url: '/bpm/process-instance/create',
method: 'POST',
data: data
})
}
export function cancelProcessInstance(id, reason) { export function cancelProcessInstance(id, reason) {
return request({ return request({
url: '/bpm/process-instance/cancel', url: '/bpm/process-instance/cancel',

View File

@ -173,8 +173,13 @@ export default {
submitForm() { submitForm() {
this.$refs[this.formConf.formRef].validate(valid => { this.$refs[this.formConf.formRef].validate(valid => {
if (!valid) return false if (!valid) return false
// sumit // submit
this.$emit('submit', this[this.formConf.formModel]) // update by
// this.$emit('submit', this[this.formConf.formModel])
this.$emit('submit', {
conf: this.formConfCopy,
values: this[this.formConf.formModel]
})
return true return true
}) })
} }

View File

@ -1,70 +1,65 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 列表 --> <!-- 第一步通过流程定义的列表选择对应的流程 -->
<el-table v-loading="loading" :data="list"> <div v-if="!selectProcessInstance">
<el-table-column label="定义编号" align="center" prop="id" width="400" /> <el-table v-loading="loading" :data="list">
<el-table-column label="定义名称" align="center" prop="name" width="100"> <el-table-column label="流程名称" align="center" prop="name" width="200">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" @click="handleBpmnDetail(scope.row)"> <el-button type="text" @click="handleBpmnDetail(scope.row)">
<span>{{ scope.row.name }}</span> <span>{{ scope.row.name }}</span>
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="定义分类" align="center" prop="category" width="100"> <el-table-column label="流程分类" align="center" prop="category" width="100">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ getDictDataLabel(DICT_TYPE.BPM_MODEL_CATEGORY, scope.row.category) }}</span> <span>{{ getDictDataLabel(DICT_TYPE.BPM_MODEL_CATEGORY, scope.row.category) }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="表单信息" align="center" prop="formId"> <el-table-column label="流程版本" align="center" prop="processDefinition.version" width="80">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button v-if="scope.row.formId" type="text" @click="handleFormDetail(scope.row)"> <el-tag size="medium" v-if="scope.row">v{{ scope.row.version }}</el-tag>
<span>{{ scope.row.formName }}</span> </template>
</el-button> </el-table-column>
<label v-else>暂无表单</label> <el-table-column label="流程描述" align="center" prop="description" width="300" show-overflow-tooltip />
</template> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
</el-table-column> <template slot-scope="scope">
<el-table-column label="流程版本" align="center" prop="processDefinition.version" width="80"> <el-button type="text" size="small" icon="el-icon-plus" @click="handleSelect(scope.row)">选择</el-button>
<template slot-scope="scope"> </template>
<el-tag size="medium" v-if="scope.row">v{{ scope.row.version }}</el-tag> </el-table-column>
<el-tag size="medium" type="warning" v-else>未部署</el-tag> </el-table>
</template> </div>
</el-table-column> <!-- 第二步填写表单进行流程的提交 -->
<el-table-column label="状态" align="center" prop="version" width="80"> <div v-else>
<template slot-scope="scope"> <el-card class="box-card" >
<el-tag type="success" v-if="scope.row.suspensionState === 1">激活</el-tag> <div slot="header" class="clearfix">
<el-tag type="warning" v-if="scope.row.suspensionState === 2">挂起</el-tag> <span class="el-icon-document">{{ selectProcessInstance.name }}</span>
</template> <el-button style="float: right;" type="primary" @click="selectProcessInstance = undefined">选择其它流程</el-button>
</el-table-column> </div>
<el-table-column label="部署时间" align="center" prop="deploymentTime" width="180"> <el-col :span="16" :offset="6">
<template slot-scope="scope"> <div>
<span>{{ parseTime(scope.row.deploymentTime) }}</span> <parser :key="new Date().getTime()" :form-conf="detailForm" @submit="submitForm" />
</template> </div>
</el-table-column> </el-col>
<el-table-column label="定义描述" align="center" prop="description" width="300" show-overflow-tooltip /> </el-card>
</el-table> </div>
<!-- 流程表单配置详情 --> <el-card class="box-card">
<el-dialog title="表单详情" :visible.sync="detailOpen" width="50%" append-to-body> <div slot="header" class="clearfix">
<parser :key="new Date().getTime()" :form-conf="detailForm" /> <span class="el-icon-picture-outline">流程图</span>
</el-dialog> </div>
<!-- 流程模型图的预览 -->
<el-dialog title="流程图" :visible.sync="showBpmnOpen" width="80%" append-to-body>
<my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" /> <my-process-viewer key="designer" v-model="bpmnXML" v-bind="bpmnControlForm" />
</el-dialog> </el-card>
<!-- 分页组件 -->
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/>
</div> </div>
</template> </template>
<script> <script>
import {getProcessDefinitionBpmnXML, getProcessDefinitionPage} from "@/api/bpm/definition"; import {getProcessDefinitionBpmnXML, getProcessDefinitionList} from "@/api/bpm/definition";
import {DICT_TYPE, getDictDatas} from "@/utils/dict"; import {DICT_TYPE, getDictDatas} from "@/utils/dict";
import {getForm} from "@/api/bpm/form"; import {getForm} from "@/api/bpm/form";
import {decodeFields} from "@/utils/formGenerator"; import {decodeFields} from "@/utils/formGenerator";
import Parser from '@/components/parser/Parser' import Parser from '@/components/parser/Parser'
import {createProcessInstance} from "@/api/bpm/processInstance";
export default { export default {
name: "processDefinition", name: "processDefinition",
@ -79,49 +74,51 @@ export default {
total: 0, total: 0,
// //
list: [], list: [],
//
queryParams: {
pageNo: 1,
pageSize: 10
},
// //
detailOpen: false,
detailForm: { detailForm: {
fields: [] fields: []
}, },
// BPMN // BPMN
showBpmnOpen: false,
bpmnXML: null, bpmnXML: null,
bpmnControlForm: { bpmnControlForm: {
prefix: "activiti" prefix: "activiti"
}, },
//
selectProcessInstance: undefined, //
// //
categoryDictDatas: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY), categoryDictDatas: getDictDatas(DICT_TYPE.BPM_MODEL_CATEGORY),
}; };
}, },
created() { created() {
const key = this.$route.query && this.$route.query.key
if (key) {
this.queryParams['key'] = key
}
this.getList(); this.getList();
}, },
methods: { methods: {
/** 查询流程定义列表 */ /** 查询流程定义列表 */
getList() { getList() {
this.loading = true; this.loading = true;
getProcessDefinitionPage(this.queryParams).then(response => { getProcessDefinitionList({
this.list = response.data.list; suspensionState: 1
this.total = response.data.total; }).then(response => {
this.loading = false; this.list = response.data
this.loading = false
} }
); );
}, },
/** 流程表单的详情按钮操作 */ /** 处理选择流程的按钮操作 **/
handleFormDetail(row) { handleSelect(row) {
//
if (!row.formId) {
this.$message.error('该流程未绑定表单,无法发起流程!请重新选择你要发起的流程');
return;
}
//
this.selectProcessInstance = row;
//
getForm(row.formId).then(response => { getForm(row.formId).then(response => {
// //
const data = response.data const data = response.data
@ -129,16 +126,36 @@ export default {
...JSON.parse(data.conf), ...JSON.parse(data.conf),
fields: decodeFields(data.fields) fields: decodeFields(data.fields)
} }
// });
this.detailOpen = true
}) //
},
/** 流程图的详情按钮操作 */
handleBpmnDetail(row) {
getProcessDefinitionBpmnXML(row.id).then(response => { getProcessDefinitionBpmnXML(row.id).then(response => {
this.bpmnXML = response.data this.bpmnXML = response.data
// })
this.showBpmnOpen = true },
/** 提交按钮 */
submitForm(params) {
if (!params) {
return;
}
//
const conf = params.conf;
conf.disabled = true; //
conf.formBtns = false; //
//
const variables = params.values;
createProcessInstance({
processDefinitionId: this.selectProcessInstance.id,
variables: variables
}).then(response => {
this.msgSuccess("发起流程成功");
//
this.$store.dispatch("tagsView/delView", this.$route);
this.$router.go(-1);
}).catch(() => {
conf.disabled = false; //
conf.formBtns = true; //
}) })
}, },
} }
@ -149,4 +166,9 @@ export default {
.my-process-designer { .my-process-designer {
height: calc(100vh - 200px); height: calc(100vh - 200px);
} }
.box-card {
width: 100%;
margin-bottom: 20px;
}
</style> </style>

View File

@ -47,7 +47,7 @@
<!-- 列表 --> <!-- 列表 -->
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="编号" align="center" prop="id" width="300" /> <el-table-column label="编号" align="center" prop="id" width="320" />
<el-table-column label="流程名" align="center" prop="name" /> <el-table-column label="流程名" align="center" prop="name" />
<el-table-column label="流程分类" align="center" prop="category"> <el-table-column label="流程分类" align="center" prop="category">
<template slot-scope="scope"> <template slot-scope="scope">