初步完善模型发布流程

This commit is contained in:
yunlong.li 2021-11-18 18:23:56 +08:00
parent 3f90e79d8a
commit a829e8d083
9 changed files with 236 additions and 148 deletions

View File

@ -1,32 +1,21 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow; package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.TodoTaskRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO;
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.*;
import org.activiti.engine.repository.Model; import org.activiti.engine.repository.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException;
/** /**
* 工作流模型 * 工作流模型
@ -49,14 +38,14 @@ public class ModelController {
@PostMapping("/create") @PostMapping("/create")
@ApiOperation(value = "新建模型") @ApiOperation(value = "新建模型")
public CommonResult<String> newModel(@RequestBody ModelCreateVO modelCreateVO) { public CommonResult<String> newModel(@RequestBody ModelVO modelVO) {
return bpmModelService.newModel(modelCreateVO); return bpmModelService.newModel(modelVO);
} }
@PostMapping("/update") @PostMapping("/update")
@ApiOperation(value = "修改模型属性") @ApiOperation(value = "修改模型属性")
public CommonResult<String> updateModel(@RequestBody ModelUpdateVO modelUpdateVO) { public CommonResult<String> updateModel(@RequestBody ModelVO modelVO) {
return bpmModelService.updateModel(modelUpdateVO); return bpmModelService.updateModel(modelVO);
} }
@PostMapping("/delete") @PostMapping("/delete")
@ -72,9 +61,9 @@ public class ModelController {
} }
@GetMapping("/exportBpmnXml") @GetMapping("/exportBpmnXml")
@ApiOperation(value = "导出模型") @ApiOperation(value = "导出模型Xml")
public void export(@RequestParam String deploymentId, HttpServletResponse response) throws IOException { public void export(@RequestParam String modelId, HttpServletResponse response) throws IOException {
FileResp fileResp = bpmModelService.exportBpmnXml(deploymentId); FileResp fileResp = bpmModelService.exportBpmnXml(modelId);
ServletUtils.writeAttachment(response, fileResp.getFileName(), fileResp.getFileByte()); ServletUtils.writeAttachment(response, fileResp.getFileName(), fileResp.getFileByte());
} }

View File

@ -1,24 +0,0 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 新增模型 VO
* @author yunlongn
*/
@Data
public class ModelCreateVO {
@ApiModelProperty(value = "模型名字", required = true)
private String name;
@ApiModelProperty(value = "模型描述")
private String description;
@ApiModelProperty(value = "版本号")
private Integer revision;
@ApiModelProperty(value = "key值")
private String key;
}

View File

@ -8,9 +8,9 @@ import lombok.Data;
* @author yunlongn * @author yunlongn
*/ */
@Data @Data
public class ModelUpdateVO { public class ModelVO {
@ApiModelProperty(value = "模型Id", required = true) @ApiModelProperty(value = "模型Id")
private String id; private String id;
@ApiModelProperty(value = "模型名字", required = true) @ApiModelProperty(value = "模型名字", required = true)
@ -27,6 +27,4 @@ public class ModelUpdateVO {
@ApiModelProperty(value = "bpmnXml") @ApiModelProperty(value = "bpmnXml")
private String bpmnXml; private String bpmnXml;
} }

View File

@ -1,16 +1,12 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow; package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO;
import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.PageResult;
import org.activiti.engine.repository.Model; import org.activiti.engine.repository.Model;
import javax.servlet.http.HttpServletResponse;
/** /**
* 工作流模型接口 * 工作流模型接口
* @author yunlongn * @author yunlongn
@ -27,16 +23,16 @@ public interface BpmModelService {
/** /**
* 新增一个模型 * 新增一个模型
* @param modelCreateVO 模型对象 * @param modelVO 模型对象
* @return 返回成功 * @return 返回成功
*/ */
CommonResult<String> newModel(ModelCreateVO modelCreateVO); CommonResult<String> newModel(ModelVO modelVO);
/** /**
* 修改模型属性填充bpmn数据 * 修改模型属性填充bpmn数据
* @param modelUpdateVO 模型对象 * @param modelVO 模型对象
* @return 返回成功 * @return 返回成功
*/ */
CommonResult<String> updateModel(ModelUpdateVO modelUpdateVO); CommonResult<String> updateModel(ModelVO modelVO);
/** /**
* 部署模型 使模型成为一个 process * 部署模型 使模型成为一个 process

View File

@ -1,12 +1,9 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl; package cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.impl;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.FileResp;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelCreateVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelPageReqVo;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelRespVo; import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.workflow.vo.model.ModelUpdateVO;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants; import cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants;
import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService; import cn.iocoder.yudao.adminserver.modules.bpm.service.workflow.BpmModelService;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
@ -15,26 +12,20 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.activiti.api.runtime.shared.query.Pageable;
import org.activiti.bpmn.converter.BpmnXMLConverter; import org.activiti.bpmn.converter.BpmnXMLConverter;
import org.activiti.bpmn.model.BpmnModel; import org.activiti.bpmn.model.BpmnModel;
import org.activiti.engine.RepositoryService; import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.Model; import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ModelQuery; import org.activiti.engine.repository.ModelQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import javax.servlet.http.HttpServletResponse;
import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -64,55 +55,59 @@ public class BpmModelServiceImpl implements BpmModelService {
} }
@Override @Override
public CommonResult<String> newModel(ModelCreateVO modelCreateVO) { public CommonResult<String> newModel(ModelVO modelVO) {
try { try {
//初始化一个空模型 //初始化一个空模型
Model model = repositoryService.newModel(); Model model = repositoryService.newModel();
String name = Optional.ofNullable(modelCreateVO.getName()).orElse("new-process"); String name = Optional.ofNullable(modelVO.getName()).orElse("new-process");
//设置一些默认信息 //设置一些默认信息
model.setName(name); model.setName(name);
model.setKey(Optional.ofNullable(modelCreateVO.getKey()).orElse("processKey")); model.setKey(Optional.ofNullable(modelVO.getKey()).orElse("processKey"));
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO)); model.setMetaInfo(JsonUtils.toJsonString(modelVO));
repositoryService.saveModel(model); repositoryService.saveModel(model);
return CommonResult.success("保存成功"); if (!ObjectUtils.isEmpty(modelVO.getBpmnXml())) {
repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
}
return CommonResult.success(model.getId());
}catch (Exception e){ }catch (Exception e){
log.info("模型创建失败modelCreateVO = {} e = {} ", modelCreateVO, ExceptionUtils.getStackTrace(e)); log.info("模型创建失败modelVO = {} e = {} ", modelVO, ExceptionUtils.getStackTrace(e));
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
} }
} }
@Override @Override
public CommonResult<String> updateModel(ModelUpdateVO modelUpdateVO) { public CommonResult<String> updateModel(ModelVO modelVO) {
try { try {
Model model = repositoryService.getModel(modelUpdateVO.getId()); Model model = repositoryService.getModel(modelVO.getId());
if (ObjectUtils.isEmpty(model)) { if (ObjectUtils.isEmpty(model)) {
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
} }
// 只能修改名字跟描述 // 只能修改名字跟描述
ModelCreateVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelCreateVO.class); ModelVO modelCreateVO = JsonUtils.parseObject(model.getMetaInfo(), ModelVO.class);
if (ObjectUtils.isEmpty(modelCreateVO)) { if (ObjectUtils.isEmpty(modelCreateVO)) {
modelCreateVO = new ModelCreateVO(); modelCreateVO = new ModelVO();
} }
modelCreateVO.setName(modelUpdateVO.getName()); modelCreateVO.setName(modelVO.getName());
modelCreateVO.setDescription(modelUpdateVO.getDescription()); modelCreateVO.setDescription(modelVO.getDescription());
model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO)); model.setMetaInfo(JsonUtils.toJsonString(modelCreateVO));
model.setName(modelUpdateVO.getName()); model.setName(modelVO.getName());
model.setKey(modelVO.getKey());
// 更新模型 // 更新模型
repositoryService.saveModel(model); repositoryService.saveModel(model);
repositoryService.addModelEditorSource(model.getId(), modelUpdateVO.getBpmnXml().getBytes(StandardCharsets.UTF_8)); repositoryService.addModelEditorSource(model.getId(), modelVO.getBpmnXml().getBytes(StandardCharsets.UTF_8));
return CommonResult.success("保存成功"); return CommonResult.success("保存成功");
}catch (Exception e){ }catch (Exception e){
log.info("模型更新失败modelUpdateVO = {} e = {} ", modelUpdateVO, ExceptionUtils.getStackTrace(e)); log.info("模型更新失败modelVO = {}", modelVO, e);
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR); throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
} }
} }
@Override @Override
public CommonResult<String> deploy(String modelId) { public CommonResult<String> deploy(String modelId) {
// 获取模型 try {
Model modelData = repositoryService.getModel(modelId); Model modelData = repositoryService.getModel(modelId);
if (ObjectUtils.isEmpty(modelData)) { if (ObjectUtils.isEmpty(modelData)) {
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
@ -121,7 +116,6 @@ public class BpmModelServiceImpl implements BpmModelService {
if (bytes == null) { if (bytes == null) {
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS); throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
} }
try {
// 将xml转换为流 // 将xml转换为流
ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes); ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
XMLInputFactory xif = XMLInputFactory.newInstance(); XMLInputFactory xif = XMLInputFactory.newInstance();
@ -148,21 +142,21 @@ public class BpmModelServiceImpl implements BpmModelService {
} }
@Override @Override
public FileResp exportBpmnXml(String deploymentId) { public FileResp exportBpmnXml(String modelId) {
try {
// 查询流程定义 Model modelData = repositoryService.getModel(modelId);
ProcessDefinition pd = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult(); if (ObjectUtils.isEmpty(modelData)) {
if (ObjectUtils.isEmpty(pd)) { throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_EDITOR_SOURCE_NOT_EXISTS);
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_PROCESS_DEFINITION_NOT_EXISTS);
} }
String resourceName = Optional.ofNullable(pd.getDiagramResourceName()).orElse(pd.getResourceName()); byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
InputStream inputStream = repositoryService.getResourceAsStream(deploymentId,
resourceName);
FileResp fileResp = new FileResp(); FileResp fileResp = new FileResp();
fileResp.setFileName(String.format("%s.bpmn", Optional.ofNullable(modelData.getName()).orElse("流程图")));
fileResp.setFileName(String.format("%s.bpmn", Optional.ofNullable(pd.getName()).orElse("流程图"))); fileResp.setFileByte(bytes);
fileResp.setFileByte(IoUtil.readBytes(inputStream));
return fileResp; return fileResp;
} catch (Exception e) {
log.info("模型部署失败modelId = {} e = {} ", modelId, ExceptionUtils.getStackTrace(e));
throw ServiceExceptionUtil.exception(BpmErrorCodeConstants.BPMN_MODEL_ERROR);
}
} }
@Override @Override

View File

@ -8,3 +8,41 @@ export function page(query) {
params: query params: query
}) })
} }
export function exportBpmnXml(query) {
return request({
url: '/workflow/models/exportBpmnXml',
method: 'get',
params: query
})
}
export function modelUpdate(data) {
return request({
url: '/workflow/models/update',
method: 'POST',
data: data
})
}
export function modelSave(data) {
return request({
url: '/workflow/models/create',
method: 'POST',
data: data
})
}
export function modelDelete(data) {
return request({
url: '/workflow/models/delete?modelId='+ data.modelId,
method: 'POST',
data: data
})
}
export function modelDeploy(data) {
return request({
url: '/workflow/models/deploy?modelId='+ data.modelId,
method: 'POST',
data: data
})
}

View File

@ -2,10 +2,7 @@
<div> <div>
<el-button-group> <el-button-group>
<el-tooltip class="item" effect="dark" content="保存并发布" placement="bottom"> <el-tooltip class="item" effect="dark" content="保存并发布" placement="bottom">
<el-button type="primary" size="small" @click="deploy"><i class="fa fa-save"> 保存并发布</i></el-button> <el-button type="primary" size="small" @click="save"><i class="fa fa-save"> 保存</i></el-button>
</el-tooltip>
<el-tooltip class="item" effect="dark" content="保存草稿" placement="bottom">
<el-button type="primary" size="small" @click="save"><i class="fa fa-save"> 保存草稿</i></el-button>
</el-tooltip> </el-tooltip>
<el-tooltip class="item" effect="dark" content="打开流程文件" placement="bottom"> <el-tooltip class="item" effect="dark" content="打开流程文件" placement="bottom">
<el-button type="primary" size="small" @click="importXml"><i class="fa fa-folder-open"></i></el-button> <el-button type="primary" size="small" @click="importXml"><i class="fa fa-folder-open"></i></el-button>
@ -32,10 +29,13 @@
<el-tooltip class="item" effect="dark" content="缩小" placement="bottom"> <el-tooltip class="item" effect="dark" content="缩小" placement="bottom">
<el-button size="small" @click="zoom(-0.05)"><i class="fa fa-search-minus"></i></el-button> <el-button size="small" @click="zoom(-0.05)"><i class="fa fa-search-minus"></i></el-button>
</el-tooltip> </el-tooltip>
<el-tooltip class="item" effect="dark" content="重置" placement="bottom"> <el-tooltip class="item" effect="dark" content="重置大小" placement="bottom">
<el-button size="small" @click="zoom(0)"><i class="fa fa-arrows"></i></el-button> <el-button size="small" @click="zoom(0)"><i class="fa fa-arrows"></i></el-button>
</el-tooltip> </el-tooltip>
</el-button-group> </el-button-group>
<div class="closeClass" @click="beforeClose()"><i class="el-icon-close"></i></div>
</div> </div>
</template> </template>
@ -74,15 +74,15 @@
} }
_svg = svg; _svg = svg;
}) })
that.post(this.Apis.deployProcess, { // that.post(this.Apis.deployProcess, {
processKey: "s1111", // processKey: "s1111",
processName: "阿达达", // processName: "",
resourceName: "test01", // resourceName: "test01",
xml: _xml, // xml: _xml,
svg: _svg // svg: _svg
}, function (data) { // }, function (data) {
console.log(data) // console.log(data)
}); // });
}, },
save(){ save(){
let that = this; let that = this;
@ -129,11 +129,24 @@
let newScale = !val ? 1.0 : ((this.scale + val) <= 0.2) ? 0.2 : (this.scale + val); let newScale = !val ? 1.0 : ((this.scale + val) <= 0.2) ? 0.2 : (this.scale + val);
this.modeler.get('canvas').zoom(newScale); this.modeler.get('canvas').zoom(newScale);
this.scale = newScale; this.scale = newScale;
},
beforeClose(val) {
this.$emit("beforeClose");
} }
} }
} }
</script> </script>
<style scoped> <style scoped>
.closeClass{
float: right;
width: 50px;
height: 50px;
font-size: 20px;
}
.closeClass:hover{
cursor:pointer;
}
</style> </style>

View File

@ -4,7 +4,7 @@
<el-row> <el-row>
<el-col :span="24"> <el-col :span="24">
<vue-header class="bpmn-viewer-header" :processData="initData" :modeler="bpmnModeler" @restart="restart" @importXml="importXml" <vue-header class="bpmn-viewer-header" :processData="initData" :modeler="bpmnModeler" @restart="restart" @importXml="importXml"
@handleExportSvg="handleExportSvg" @handleExportBpmn="handleExportBpmn" @processSave="processSave"></vue-header> @handleExportSvg="handleExportSvg" @handleExportBpmn="handleExportBpmn" @processSave="processSave" @beforeClose="beforeClose"></vue-header>
</el-col> </el-col>
</el-row> </el-row>
<el-row style="margin-left: 1%"> <el-row style="margin-left: 1%">
@ -61,6 +61,7 @@
}, },
props: { props: {
product: String, product: String,
bpmnData: Object,
bpmnXml: { bpmnXml: {
type: String, type: String,
required: false required: false
@ -80,8 +81,13 @@
mounted() { mounted() {
let processId = new Date().getTime(); let processId = new Date().getTime();
this.initTemplate = templateXml.initTemplate(processId) this.initTemplate = templateXml.initTemplate(processId)
this.initData = {key: "process" + processId, name: "流程" + processId, xml: this.initTemplate}
if (this.bpmnXml != null) { this.initData = {
key: this.bpmnData.key ? this.bpmnData.key : "process" + processId,
name: this.bpmnData.name ? this.bpmnData.name : "流程" + processId,
description: this.bpmnData.metaInfo ? JSON.parse(this.bpmnData.metaInfo).description : "" ,
xml: this.initTemplate}
if (this.bpmnXml != null && this.bpmnXml !== "") {
this.initTemplate = this.bpmnXml this.initTemplate = this.bpmnXml
} }
this.init(); this.init();
@ -205,14 +211,21 @@
}, },
processSave(data){ processSave(data){
let initData = this.initData; let initData = this.initData;
data.procId = initData.key; const dataXml = this.bpmnData
data.name = initData.name; dataXml.bpmnXml = this.xmlShow;
this.$emit("processSave",data); dataXml.name = initData.name;
dataXml.key = initData.key;
dataXml.description = initData.description;
this.$emit("processSave",dataXml);
}, },
restart() { restart() {
let processId = new Date().getTime(); let processId = new Date().getTime();
this.initTemplate = templateXml.initTemplate(processId) this.initTemplate = templateXml.initTemplate(processId)
this.initData = {key: "process" + processId, name: "流程" + processId, xml: this.initTemplate} this.initData = {
key: this.bpmnData.key ? this.bpmnData.key : "process" + processId,
name: this.bpmnData.name ? this.bpmnData.name : "流程" + processId,
description: this.bpmnData.metaInfo ? JSON.parse(this.bpmnData.metaInfo).description : "" ,
xml: this.initTemplate}
this.initDiagram(this.initTemplate) this.initDiagram(this.initTemplate)
}, },
importXml() { importXml() {
@ -244,6 +257,9 @@
} }
} }
return moddleExtensions; return moddleExtensions;
},
beforeClose() {
this.$emit("beforeClose");
} }
} }
} }

View File

@ -10,17 +10,18 @@
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" <el-button
v-hasPermi="['system:login-log:export']">导出</el-button> type="primary"
<el-button type="warning" icon="el-icon-download" size="mini" @click="openBpmn" icon="el-icon-plus"
v-hasPermi="['system:login-log:export']">新建</el-button> size="mini"
@click="openBpmn"
v-hasPermi="['infra:config:create']"
>新建流程</el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
<el-table v-loading="loading" :data="list"> <el-table v-loading="loading" :data="list">
<el-table-column label="ID" align="center" prop="id" /> <el-table-column label="ID" align="center" prop="id" />
<el-table-column label="name" align="center" prop="metaInfo" > <el-table-column label="name" align="center" prop="metaInfo" >
@ -33,18 +34,30 @@
<span>{{ JSON.parse(scope.row.metaInfo).description }}</span> <span>{{ JSON.parse(scope.row.metaInfo).description }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="创建时间" align="center" prop="createTime" >
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" >
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-setting" @click="change(scope.row)">设计流程</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="modelDelete(scope.row)">删除</el-button>
<el-button size="mini" type="text" icon="el-icon-thumb" @click="modelDeploy(scope.row)">发布</el-button>
</template>
</el-table-column>
</el-table> </el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
@pagination="getList"/> @pagination="getList"/>
<el-dialog title="新建流程" :visible.sync="showBpmnBool" :before-close="close" :fullscreen="true"> <el-dialog :visible.sync="showBpmnBool" :before-close="close" :fullscreen="true">
<vue-bpmn product="activiti" @processSave="processSave"></vue-bpmn> <vue-bpmn v-if="showBpmnBool" product="activiti" @processSave="processSave" :bpmnXml="bpmnXML" :bpmnData="bpmnData" @beforeClose="close"></vue-bpmn>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { page } from "@/api/bpm/model"; import { page, exportBpmnXml, modelUpdate, modelSave, modelDelete, modelDeploy } from "@/api/bpm/model";
import VueBpmn from "@/components/bpmn/VueBpmn"; import VueBpmn from "@/components/bpmn/VueBpmn";
export default { export default {
@ -61,6 +74,7 @@ export default {
// //
list: [], list: [],
bpmnXML: null, bpmnXML: null,
bpmnData: {},
// //
queryParams: { queryParams: {
pageNo: 1, pageNo: 1,
@ -98,27 +112,81 @@ export default {
this.resetForm("queryForm"); this.resetForm("queryForm");
this.handleQuery(); this.handleQuery();
}, },
/** 导出按钮操作 */ processSave(data) {
handleExport() { const that = this;
const queryParams = this.queryParams; // id
this.$confirm('是否确认导出所有操作日志数据项?', "警告", { if (data.id) {
confirmButtonText: "确定", let postData = JSON.parse(data.metaInfo)
cancelButtonText: "取消", postData.bpmnXml = data.bpmnXml
type: "warning" postData.id = data.id
}).then(function() { postData.name = data.name
return exportLoginLog(queryParams); postData.key = data.key
}).then(response => { postData.description = data.description
this.downloadExcel(response, '登录日志.xls'); modelUpdate(postData).then(response => {
this.msgSuccess("保存成功");
}) })
}, this.showBpmnBool = false
processSave() { this.getList();
console.log("processSave") return
}
modelSave(data).then(response => {
that.bpmnData.id = response.data
this.msgSuccess("保存成功");
})
this.showBpmnBool = false
this.getList();
}, },
openBpmn() { openBpmn() {
this.bpmnData = {}
this.bpmnXML = ""
this.showBpmnBool = true this.showBpmnBool = true
}, },
close() { close() {
this.showBpmnBool = false this.showBpmnBool = false
this.getList();
},
change(row) {
const that = this;
this.bpmnXML = ""
this.bpmnData = {}
exportBpmnXml({
modelId: row.id
}).then(response => {
that.bpmnXML = response
that.bpmnData = row
that.showBpmnBool = true
})
},
modelDelete(row) {
const that = this;
this.$confirm('是否删除该流程!!', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
modelDelete({
modelId: row.id
}).then(response => {
that.getList();
that.msgSuccess("删除成功");
})
})
},
modelDeploy(row) {
const that = this;
this.$confirm('是否部署该流程!!', "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "success"
}).then(function() {
modelDeploy({
modelId: row.id
}).then(response => {
that.getList();
that.msgSuccess("部署成功");
})
})
} }
} }
}; };