ingenious-flow-designer
Version:
[演示地址](http://antd-vben5-pro.madong.tech/)
89 lines (83 loc) • 2.48 kB
text/typescript
// Custom.ts
import { h } from "@logicflow/core";
import { h, type GraphModel } from "@logicflow/core";
import { RectResize } from "@logicflow/extension";
import customSvgStr from '../assets/images/custom.svg?raw'
import { parseSvg } from '../tool'
import { ColorEnum, NodeSizeEnum, NodeStateEnum } from "../types/enums";
const paths = parseSvg(customSvgStr)
class CustomModel extends RectResize.model {
constructor(data: any, graphModel: GraphModel) {
super(data, graphModel)
if (data.properties) {
this.width = (data.properties.width ? data.properties.width : NodeSizeEnum.width) as number
this.height = (data.properties.height ? data.properties.height :NodeSizeEnum.height) as number
}
}
setAttributes(): void {
if((this.text && this.text.value == "") || !this.text) {
this.text.value = "自定义任务";
}
}
getNodeStyle() {
const theme = this.graphModel.props.theme;
const style = super.getNodeStyle();
if(this.properties.state == NodeStateEnum.history) {
style.stroke = theme.historyColor || ColorEnum.historyColor;
} else if(this.properties.state == NodeStateEnum.active) {
style.stroke = theme.activeColor || ColorEnum.activeColor;
} else {
style.stroke = theme.primaryColor || ColorEnum.primaryColor;
}
// style.strokeDasharray = "3 3";
return style;
}
}
class CustomView extends RectResize.view {
private getLabelShape() {
const { model } = this.props;
const { x, y, width, height } = model;
const style = model.getNodeStyle();
return h(
"svg",
{
x: x - width / 2 + 5,
y: y - height / 2 + 5,
width: 25,
height: 25,
viewBox: "0 0 1274 1024"
},
...paths.map(d=>{
return h("path", {
fill: style.stroke,
d
})
}),
);
}
/**
* 完全自定义节点外观方法
*/
getResizeShape() {
const { model } = this.props;
const { x, y, width, height, radius } = model;
const style = model.getNodeStyle();
return h("g", {}, [
h("rect", {
...style,
x: x - width / 2,
y: y - height / 2,
rx: radius,
ry: radius,
width,
height
}),
this.getLabelShape()
]);
}
}
export default {
type: "custom",
view: CustomView,
model: CustomModel,
};