## what's the difference?
和旧的bpmn-adapter相比,新的bpmn-adapter在调用adapterIn和adapterOut时,可以额外传入一个对象作为入参
``` ts
type ExtraPropsType = {
/**
* retainedAttrsFields retainedAttrsFields会和默认的defaultRetainedProperties:
* ["properties", "startPoint", "endPoint", "pointsList"]合并
* 这意味着出现在这个数组里的字段当它的值是数组或是对象时不会被视为一个节点而是一个属性
*/
retainedAttrsFields?: string[];
/**
* excludeFields会和默认的defaultExcludeFields合并,
* 出现在这个数组中的字段在导出时会被忽略
*/
excludeFields?: {
in?: Set<string>;
out?: Set<string>;
};
/**
* transformer是一个数组,数组中的每一项都是一个对象,对象中包含in和out两个属性
* in函数接收两个参数key 和 data,key为当前处理对象的key也就是节点名称,data为当前对象,当导入时会调用这个函数,对被导入数据进行处理,得到我们期望的数据
* out函数接收一个参数data,data为当前处理节点数据,当导出时会调用这个函数,对需要导出的数据进行处理,得到我们期望的数据
*/
transformer?: {
[key: string]: {
in?: (key: string, data: any) => any;
out?: (data: any) => any;
}
};
mapping?: {
in?: {
[key: string]: string;
};
out?: {
[key: string]: string;
};
};
};
```
## 使用
``` ts
// step 1 引入adapter插件
import { BpmnXmlAdapterV2 } from '@logicflow/extension';
// step 2 注册插件
LogicFlow.use(BpmnXmlAdapterV2);
...
// step 3-1 调用默认导出
const xmlResult = lf.adapterOut(lf.getGraphRawData())
```
很多时候,我们可能需要一些额外的参数帮助我们正确的进行导入导出,这时我们需要用到上面提到的adapterOut额外的入参ExtraPropsType
``` ts
// step 3-2 使用adapterOut的第二个参数ExtraPropsType导出
// 假如我们节点属性中有一个panels属性,它是一个数组,但是我们不希望它被视为一个节点,而是一个属性,那么我们可以这样做
const extraProps = {
retainedAttrsFields: ['panels']
}
// 假如我们节点属性中有一个runboost属性,但是我们希望导出时不包含这个属性,那么我们可以这样做
extraProps.excludeFields = {
out: new Set(['runboost'])
}
```
假如我们要将包含判断条件的顺序流(sequenceFlow)以正确的XML格式导出,并且导入时正确处理得到我们想要的数据,那么我们可以这样做:
``` xml
<!-- 顺序流的XML数据格式: -->
<bpmn:sequenceFlow id="SequenceFlow_0j5q1qk" sourceRef="StartEvent_1" targetRef="Activity_0j5q1qk"/>
<!-- 包含判断条件时 -->
<bpmn:sequenceFlow id="SequenceFlow_0j5q1qk" sourceRef="StartEvent_1" targetRef="Activity_0j5q1qk">
<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression">
<![CDATA[${runboost === '1'}]]>
</bpmn:conditionExpression>
</bpmn:sequenceFlow>
<!-- 或者 -->
<bpmn:sequenceFlow id="SequenceFlow_0j5q1qk" sourceRef="StartEvent_1" targetRef="Activity_0j5q1qk">
<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression">
runboost === '1'
</bpmn:conditionExpression>
</bpmn:sequenceFlow>
```
``` ts
/**
* 以包含判断条件的顺序流为例,
* 在进行导入时,我们需要把<bpmn:sequenceFlow>的子内容<bpmn:conditionExpression>内的属性提取出来,
* 最终放入父元素bpmn:sequenceFlow的properties属性中
* 所以导入的时候我们实际需要处理的<bpmn:conditionExpression>中的内容,
* 它被处理后,数据会被合入bpmn:sequenceFlow的properties属性中
*/
extraProps.transformer = {
'bpmn:sequenceFlow': {
out(data: any) {
const { properties: { expressionType, condition } } = data;
if (condition) {
if (expressionType === 'cdata') {
return {
json:
`<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression"><![CDATA[\${${
condition
}}]]></bpmn:conditionExpression>`,
};
}
return {
json: `<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression">${condition}</bpmn:conditionExpression>`,
};
}
return {
json: '',
};
},
},
// 返回的数据会被合并进父元素bpmn:sequenceFlow的properties属性中
'bpmn:conditionExpression': {
in(_key: string, data: any) {
let condition = '';
let expressionType = '';
if (data['#cdata-section']) {
expressionType = 'cdata';
condition = /^\$\{(.*)\}$/g.exec(data['#cdata-section'])?.[1] || '';
} else if (data['#text']) {
expressionType = 'normal';
condition = data['#text'];
}
return {
'-condition': condition,
'-expressionType': expressionType,
};
},
},
}
```
***数据导入导出的原则是:导出时处理父元素;导入时处理子元素。***
- 导出时,需要从父元素的属性中拿到子元素需要到数据并拼接出子元素。
- 导入时,需要从子元素中提取我们需要的数据放入父元素的属性中。
在配置完需要的extraProps之后,我们就可以调用adapterOut方法导出数据。
``` ts
const xmlResult = lf.adapterOut(lf.getGraphRawData(), extraProps)
```
目前,我们内置了一下transformer **(仅做参考)**:
> 注意:这里内置的transformer仅做参考使用,这些transformer在编写的过程中是用来配合bpmn节点插件的,里面诸如`timerType`, `timerValue`, `definitionId`,都是通过bpmn节点插件的definitionConfig配置的。在实际使用该数据转换插件时,你完全可以不使用bpmn节点插件,通过你自己的方式为节点添加属性,自定义transformer来实现符合你需要的数据转换。
```ts
let defaultTransformer: TransformerType = {
'bpmn:startEvent': {
out(data: any) {
const { properties } = data;
return defaultTransformer[properties.definitionType]?.out(data) || {};
},
},
'bpmn:intermediateCatchEvent': {
out(data: any) {
const { properties } = data;
return defaultTransformer[properties.definitionType]?.out(data) || {};
},
},
'bpmn:intermediateThrowEvent': {
out(data: any) {
const { properties } = data;
return defaultTransformer[properties.definitionType]?.out(data) || {};
},
},
'bpmn:boundaryEvent': {
out(data: any) {
const { properties } = data;
return defaultTransformer[properties.definitionType]?.out(data) || {};
},
},
'bpmn:sequenceFlow': {
out(data: any) {
const {
properties: { expressionType, condition },
} = data;
if (condition) {
if (expressionType === 'cdata') {
return {
json:
`<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression"><![CDATA[\${${
condition
}}]]></bpmn:conditionExpression>`,
};
}
return {
json: `<bpmn:conditionExpression xsi:type="bpmn2:tFormalExpression">${condition}</bpmn:conditionExpression>`,
};
}
return {
json: '',
};
},
},
'bpmn:timerEventDefinition': {
out(data: any) {
// 这里的timerType, timerValue, definitionId
// 都是通过通过的Bpmn节点插件扩展节点时,通过definitionConfig配置的属性,实际使用时需要根据自己的设置的属性对out函数进行修改
const {
properties: { timerType, timerValue, definitionId },
} = data;
const typeFunc = () => `<
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
一个专注于业务自定义的流程图编辑框架,支持实现脑图、ER图、UML、工作流等各种图编辑场景。它提供了丰富的功能和灵活的定制选项,可以帮助开发者快速构建适用于不同业务场景的流程图编辑器。无论是企业内部的流程管理系统,还是个人项目中的流程设计工具,LogicFlow 都能够满足各种需求。
资源推荐
资源详情
资源评论
收起资源包目录
自定义流程图框架:一个专注于业务自定义的流程图编辑框架,支持实现脑图、ER图、UML、工作流等各种图编辑场景 (756个子文件)
commit-msg 68B
index.css 25KB
index.css 9KB
index.css 6KB
index.css 3KB
style.css 2KB
iconfont.css 2KB
style.css 1KB
menu.css 1KB
index.css 1KB
style.css 866B
index.css 849B
style.css 816B
style.css 816B
uml.css 657B
style.css 482B
index.css 417B
App.css 360B
index.css 272B
index.css 256B
style.css 199B
index.css 171B
index.css 156B
index.css 134B
index.css 64B
style.css 57B
index.css 44B
index.css 38B
iconfont.eot 2KB
.eslintignore 305B
.eslintignore 198B
.gitignore 322B
.gitignore 231B
.gitignore 169B
.gitignore 39B
.gitignore 2B
.gitkeep 0B
index.html 25KB
index.html 7KB
index.html 4KB
index.html 3KB
destroy.html 3KB
index.html 3KB
index.html 3KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 2KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1KB
index.html 1023B
index.html 974B
index.html 937B
index.html 929B
index.html 845B
index.html 691B
index.html 641B
background.html 579B
index.html 568B
index.html 563B
index.html 559B
index.html 554B
index.html 547B
index.html 493B
index.html 491B
index.html 491B
index.html 452B
index.html 451B
index.html 426B
index.html 404B
index.html 70B
favicon.ico 4KB
favicon.ico 4KB
webpack.config.js 32KB
adapter_out.test.js 18KB
adapter_in.test.js 17KB
index.js 13KB
webpackDevServer.config.js 7KB
jest.config.js 7KB
build.js 7KB
jest.config.js 6KB
04_execute.test.js 6KB
index.js 6KB
index.js 6KB
index.js 5KB
02_recorder.test.js 5KB
start.js 5KB
config.js 4KB
bpmn-adapter.test.js 4KB
env.js 4KB
webpack.config.base.js 3KB
共 756 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
UnknownToKnown
- 粉丝: 1w+
- 资源: 653
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- PSO-SDAE基于粒子群优化堆叠去噪自编码器的数据回归预测多变量回归预测(Matlab完整源码和数据)
- 基于卷积神经网络MobileNet 的情感识别源码.7z
- 一个很好的elasticsearchJavarest客户端 它以类似于mybatis的方式操作和访问elasticsearch
- student.sql
- 一个简单的卷积神经网络(Convolutional Neural Network, CNN)示例
- EXP9-1-dataPageDisplay.php
- buildType设计模式课程设计
- 省市区下拉选择:3个el-select(json)
- 堆排序(Heap Sort)是一种基于比较的排序算法
- ebatis 是一个简单方便上手的声明式 Elasticsearch ORM 框架
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功