当前位置:网站首页>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);
}
效果
边栏推荐
- Several methods of appending elements are commonly used in js: append, appendTo, after, before, insertAfter, insertBefore, appendChild
- How to successfully pass the CKA exam?
- ddl and dml in sql (the difference between database table and view)
- 【无标题】
- 图解MySQL内连接、外连接、左连接、右连接、全连接......太多了
- Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器
- 如何利用DevExpress控件绘制流程图?看完这篇文章就懂了!
- LeakCanary如何监听Service、Root View销毁时机?
- [Community Star Selection] Issue 24 August Update Plan | Keep writing, refuse to lie down!More original incentive packages, as well as Huawei WATCH FIT watches!
- SCHEMA solves the puzzle
猜你喜欢
随机推荐
大众碰到点评的一个字体反爬,落地技术也是绝了
xss-labs靶场挑战
2022 Go ecosystem rpc framework Benchmark
ddl and dml in sql (the difference between database table and view)
How to successfully pass the CKA exam?
How do programmers solve online problems gracefully?
C language implementation!20000 in 4 seconds
监视网络连接的ss命令
Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化密度图、使用stat_central_tendency函数在密度中添加均值竖线并自定义线条类型
华硕和微星多款产品将升级英特尔Arc A380和A310显卡
Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
小程序插件如何帮助开发者受益?
数字化转型实践:世界级2B数字化营销的方法框架
Jenkins安装插件遇到的问题
千万级乘客排队系统重构&压测方案——总结篇
音视频技术开发周刊 | 256
用户体验 | 如何度量用户体验 ?
【公开课预告】:超分辨率技术在视频画质增强领域的研究与应用
【面试高频题】难度 1.5/5,二分经典运用题