当前位置:网站首页>bpmn-process-designer基础上进行自定义样式(工具、元素、菜单)
bpmn-process-designer基础上进行自定义样式(工具、元素、菜单)
2022-08-01 11:39:00 【Program W】
文章目录
一、自定义工具Palette
处理思路:
可以看到工具区就是基本样式,所以在此基础上加一个class就ok了
- 找到自定义工具
CustomPalette

例如这里对开始事件工具进行自定义
bpmn-icon-start-event-none red,red是我们自己添加的

二、自定义样式Palette和PopupMenu
可以用于左边工具区
palette和下拉菜单popup-menu
- 在
index.scss添加@import "./custom-palette.scss";
custom-palette.scss
.bpmn-icon-start-event-none.red {
color: red !important;
}
custom-popup-menu.scss
// gateway .bpmn-icon-gateway-eventbased {
display: none !important;
}
- 效果


三、自定义图形元素svg样式(包含了节点和连线)
通过
additionalModel使用自定义渲染modules/custom-renderer我们可以看到初始样式的设置
import BpmnRenderer from 'bpmn-js/lib/draw/BpmnRenderer';
export default function CustomRenderer(eventBus, styles, pathMap, canvas, textRenderer) {
// 设置初始样式配置(stroke线条、fill填充内部、label就是图形内部那个文本)
const config = {
defaultFillColor: '',
defaultStrokeColor: '#000000',
defaultLabelColor: '#000000'
};
BpmnRenderer.call(this, config, eventBus, styles, pathMap, canvas, textRenderer, 2000);
}
CustomRenderer.$inject = ['eventBus', 'styles', 'pathMap', 'canvas', 'textRenderer'];
const F = function() {
}; // 核心,利用空对象作为中介;
F.prototype = BpmnRenderer.prototype; // 核心,将父类的原型赋值给空对象F;
CustomRenderer.prototype = new F(); // 核心,将 F的实例赋值给子类;
CustomRenderer.prototype.constructor = CustomRenderer; // 修复子类CustomRenderer的构造器指向,防止原型链的混乱;
自定义元素颜色
- 在设置
dark/light时,使用的方法可以作为我们的参照,这里的theme只有stroke和fill两个属性,无法设置label,从源码中我们可以知道
changePageMode(mode) {
const theme = mode
? {
// dark
stroke: '#ffffff',
fill: '#333333'
}
: {
// light
stroke: '#000000',
fill: '#ffffff'
};
const elements = this.modeler.get('elementRegistry').getAll();
this.modeler.get('modeling').setColor(elements, theme);
}
this.modeler.get('modeling')参照bpmn-js源码/lib/features/modeling
Modeling.prototype.getHandlers = function() {
var handlers = BaseModeling.prototype.getHandlers.call(this);
handlers['element.updateModdleProperties'] = UpdateModdlePropertiesHandler;
handlers['element.updateProperties'] = UpdatePropertiesHandler;
handlers['canvas.updateRoot'] = UpdateCanvasRootHandler;
handlers['lane.add'] = AddLaneHandler;
handlers['lane.resize'] = ResizeLaneHandler;
handlers['lane.split'] = SplitLaneHandler;
handlers['lane.updateRefs'] = UpdateFlowNodeRefsHandler;
handlers['id.updateClaim'] = IdClaimHandler;
handlers['element.setColor'] = SetColorHandler; // import SetColorHandler from './cmd/SetColorHandler';
handlers['element.updateLabel'] = UpdateLabelHandler;
return handlers;
};
SetColorHandler,从这里可以看出它的传参以及setColor()方法的作用就是对指定元素进行颜色渲染
var DEFAULT_COLORS = {
fill: undefined,
stroke: undefined
};
// ......省略
SetColorHandler.prototype.postExecute = function(context) {
var elements = context.elements,
colors = context.colors || DEFAULT_COLORS;
var self = this;
var di = {
};
if ('fill' in colors) {
assign(di, {
'background-color': this._normalizeColor(colors.fill) });
}
if ('stroke' in colors) {
assign(di, {
'border-color': this._normalizeColor(colors.stroke) });
}
然后就是元素选取了
elementColorPicker组件
<template>
<div>
<div class="block">
<span class="demonstration">线条颜色</span>
<el-color-picker v-model="stroke" @change="handleChangeStroke"></el-color-picker>
</div>
<div class="block">
<span class="demonstration">填充颜色</span>
<el-color-picker v-model="fill" @change="handleChangeFill"></el-color-picker>
</div>
</div>
</template>
<script>
export default {
name: 'ElementColorPicker',
props: {
id: String,
type: String
},
data() {
return {
documentation: '',
stroke: '#000000',
fill: '#ffffff'
};
},
watch: {
},
methods: {
handleChangeStroke(stroke) {
this.$emit('color', stroke, this.fill, this.id, this.type)
},
handleChangeFill(fill) {
this.$emit('color', this.stroke, fill, this.id, this.type)
}
}
};
</script>
- 在
PropertiesPanel组件加一个自定义组件element-color-picker
<el-collapse-item name="color" key="color">
<div slot="title" class="panel-tab__title"><i class="el-icon-magic-stick"></i>视觉设置</div>
<element-color-picker :type="elementType" :id="elementId" @color="handleChangeColor"></element-color-picker>
</el-collapse-item>
// 省略.....
handleChangeColor(stroke, fill, id, type) {
this.$emit('color', stroke, fill, id, type)
}
<MyPropertiesPanel :key="`penal-${reloadIndex}`"
:bpmn-modeler="modeler"
:prefix="controlForm.prefix"
:users="users"
:dictmaps="dictmaps"
:category="currentBpmn.category"
@color="handleChangeColor"
ref="sidePanel"
class="process-panel" />
// 省略.....
handleChangeColor(stroke, fill, id, type) {
const theme = {
stroke, fill}
let elements = []
if(type === 'Process') {
elements = this.modeler.get('elementRegistry').getAll();
}else {
elements = this.modeler.get('elementRegistry').get(id);
}
this.modeler.get('modeling').setColor(elements, theme);
}
效果

边栏推荐
- R语言诊断ARIMA模型:forecast包构建了一个ARIMA模型、使用checkresiduals函数诊断ARIMA模型、并进行结果解读(拟合较差的ARIMA模型具有的特点)
- Pytest电商项目实战(下)
- 新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
- Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
- 【无标题】
- 如何设计一个分布式 ID 发号器?
- R语言ggplot2可视化:使用ggpubr包的geom_exec函数执行geom_*函数(没有任何参数需要放置在aes中)
- 基于ArkUI eTS开发的坚果食谱(NutRecipes)
- Promise学习(三)Promise的几个关键性问题 -- 状态改变、执行顺序与机制、多任务串联、异常穿透、中断promise链
- 2022 Go ecosystem rpc framework Benchmark
猜你喜欢

轮询和长轮询的区别

冰冰学习笔记:gcc、gdb等工具的使用

2022 Go生态圈 rpc 框架 Benchmark

重庆市大力实施智能建造,推动建筑业数字化转型,助力“建造强市”

《MySQL核心知识》第6章:查询语句

爱可可AI前沿推介(8.1)

Sparse representation - study notes

STM32 CAN过滤器配置详解
![[Open class preview]: Research and application of super-resolution technology in the field of video quality enhancement](/img/fc/cd859efa69fa7b45f173de74c04858.png)
[Open class preview]: Research and application of super-resolution technology in the field of video quality enhancement

Flutter Widget 如何启用和屏蔽点击事件
随机推荐
shell--第九章练习
字体反爬之好租
C#/VB.NET 将PPT或PPTX转换为图像
How to get the address of WeChat video account (link address of WeChat public account)
利用正则表达式的回溯实现绕过
Transfer learning to freeze the network:
语音聊天app源码——语音聊天派对
.NET analyzes the LINQ framework in depth (three: the elegant prelude of LINQ)
如何获取微信视频号的地址(微信公众号的链接地址)
leetcode/子矩阵元素和
爱可可AI前沿推介(8.1)
activiti工作流的分页查询避坑
Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
深入理解 Istio —— 云原生服务网格进阶实战
博弈论(Depu)与孙子兵法(42/100)
What is MNIST (what does plist mean)
Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
R语言拟合ARIMA模型:使用forecast包中的auto.arima函数自动搜索最佳参数组合、模型阶数(p,d,q)、设置seasonal参数指定在模型中是否包含季节信息
【likeshop】回收租凭系统100%开源无加密 商城+回收+租赁
【云享新鲜】社区周刊·Vol.73- DTSE Tech Talk:1小时深度解读SaaS应用系统设计

