【弄nèng - Activiti6】应用篇之iview中使用img显示Activiti流程图

291 阅读1分钟

文章目录

本文建议你熟悉Activiti之后在阅读,是Activiti的应用篇。直接上应用代码。
使用Activiti时,页面需要显示流程图,否段返回的是图片流,前端使用的是iview

1. 前端

 <!-- 图片MODAL -->
    <Modal v-model="img_modal" draggable title="流程设计" width="800" height="800">
      <div>
        <img :src="imageUrl" style="height: 100%;width: 100%;" />
      </div>
    </Modal>
showImage (id) {
      this.img_modal = true
      var url = "http://localhost:8081/act/procdef/read?id=" + id + "&type=image";
      this.imageUrl = url
    },

2. 后端

controller

@ApiOperation(value = "读取资源", notes = "读取资源,通过ProcessDefinitionId")
    @GetMapping("/read")
    public void resourceRead(String id,
                             @RequestParam(required = false) String proInsId,
                             String type,
                             HttpServletResponse response) {
        log.info("读取资源, processDefinitionId:{}, proInsId:{}, type:{}", id, proInsId, type);
        InputStream resourceAsStream = actReProcdefService.readResource(id, proInsId, type);
        byte[] b = new byte[1024];
        int len = -1;
        int lenEnd = 1024;
        while (true) {
            try {
                if (!((len = resourceAsStream.read(b, 0, lenEnd)) != -1)) break;
                response.getOutputStream().write(b, 0, len);
            } catch (IOException e) {
                throw new YYException("读取资源文件失败", e);
            }
        }
    }

service

@Override
    public InputStream readResource(String id, String proInsId, String type) {
        if (StringUtils.isBlank(id)) {
            ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
                    .processInstanceId(proInsId)
                    .singleResult();
            id = processInstance.getProcessDefinitionId();
        }
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
                .processDefinitionId(id)
                .singleResult();

        String resourceName = "";
        if (ActivitiConstant.IMAGE.equals(type)) {
            resourceName = processDefinition.getDiagramResourceName();
        } else if (ActivitiConstant.XML.equals(type)) {
            resourceName = processDefinition.getResourceName();
        }
        InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);

        return resourceAsStream;
    }

源码地址

IT-CLOUD :IT服务管理平台,集成基础服务,中间件服务,监控告警服务等。\