首页 > 其他分享 >关于在vue2中使用LogicFlow自定义节点

关于在vue2中使用LogicFlow自定义节点

时间:2024-07-17 12:56:21浏览次数:7  
标签:lf style 自定义 height width vue2 import LogicFlow

主要参考LogicFlow官方文档

在基础流程图搭建起来后,我们想要构建自己的需求风格,例如:

那么该如何对节点进行自定义设定呢?

文档当中有着详细的解释,本文以实际需求为例大体介绍:

import { RectNode, RectNodeModel, h } from "@logicflow/core";

class CustomNodeView extends RectNode {
  getShape() {
    // 获取XxxNodeModel中定义的形状属性
    const { model } = this.props;
    const { x, y, width, height, radius } = model;
    // 获取XxxNodeModel中定义的样式属性
    const style = model.getNodeStyle();

    return h('g', {}, [
        h('rect', {
            ...style,
            x: x - width / 2,
            y: y - height / 2,
            width,
            height,
            rx: radius,
            ry: radius,
        }),
        h('svg', {
            x: x - width / 2 + 5,
            y: y - height / 2 + 5,
            width: 35,
            height: 35,
            viewBox: "0 0 1028 1024",
        }, [
            h('path', {
                fill: '#fff',
                d: ''//节点的svg数据-可以在iconfont上自行查找喜欢的图标
                })
            ])
        
        ]);
    }
}


class CustomNodeModel extends RectNodeModel {
    getNodeStyle() {
        const style = super.getNodeStyle();
        style.stroke = '#8e8e8e';
        style.fill = '#cd4050';
        return style;
      }
      initNodeData(data) {
        super.initNodeData(data);
        this.width = 200;
        this.height = 50;
        this.radius = 10;
      }            
}

export default {
    type: "PdfNode",
    view: CustomNodeView,
    model: CustomNodeModel,
}

这样,我们一个自定义的节点就配置好了,接下来就是要将他注册到我们的左侧工具栏中:

<template>
    <div class="box" ref="box"></div>
</template>

<script>

import {LogicFlow, RectNode, RectNodeModel } from '@logicflow/core';
import { DndPanel, SelectionSelect, Control, NodeResize, Menu, InsertNodeInPolyline  } from '@logicflow/extension';
import '@logicflow/extension/lib/style/index.css';
import '@logicflow/core/dist/style/index.css';
import CustomNode from "./node-red/node/CustomNode";
import FlowNode from "./node-red/node/FlowNode";
import PdfNode from "./node-red/node/PdfNode";

NodeResize.step = 4;
LogicFlow.use(Control);
LogicFlow.use(NodeResize);
LogicFlow.use(DndPanel);
LogicFlow.use(SelectionSelect);
LogicFlow.use(Menu);
LogicFlow.use(InsertNodeInPolyline);


export default {
        props:["flowData",'ruleList'],
        data(){
            return{
                //编辑器内容数据
                editData: null,
                // LogicFlow对象
                lf: '',
                // 左侧工具栏数据
                patternItems: [
                    {
                      type: 'CustomNode',
                      text: '开始',
                      label: '开始节点',
                      icon: require('@/assets/images/flowStart.png'),
                    },
                    {
                      type: 'CustomNode',
                      text: '结束',
                      label: '结束节点',
                      icon: require('@/assets/images/flowStart.png'),
                    },
                    {
                      type: 'PdfNode',//刚刚自定义的节点内容
                      label: '生成pdf',
                      text: '生成pdf',
                      icon: require('@/assets/images/flowPdf.png'),
                    },
                ]
          }
        },

methods:{
            initEdit(){
                this.editData = this.flowData
                this.ruleList.forEach(item=>{
                  this.patternItems.push({
                      type: 'FlowNode',
                      label: item.name,
                      text: item.name,
                      icon: require('@/assets/images/flowFunction.png'),
                  })
                })
                this.lf = new LogicFlow({
                   container: this.$refs.box,
                    grid: true,
                    // 工具配置
                    textEdit: true,
                    isSilentMode: false,
                    edgeType: 'polyline',
                    snapline: true,
                    keyboard: {
                        enabled: true
                    },
                    style: {
                        outline: {
                            stroke: '#000000',
                            strokeWidth: 1,
                            strokeDasharray: '3,3',
                        },
                        controlPoint: {
                            width: 15,
                            height: 7,
                            fill: '#FFFFFF',
                            stroke: '#000000',
                        },
                    },
                });
                this.lf.setTheme({
                nodeText: { // 节点文本样式
                  fontSize: 18,
                  color: '#000'
                },
              });
            },
             renderEdit(){
                this.lf.extension.dndPanel.setPatternItems(this.patternItems);
                this.lf.register(CustomNode);
                this.lf.register(FlowNode);
                this.lf.register(PdfNode);
                this.lf.render(this.editData);
            }
        },
        mounted(){
            this.initEdit()
            this.renderEdit()
        },

记得给你的box,以及菜单栏一个样式

<style lang="scss" scoped>
.box{
    width: 100%;
    height: 80vh;
    overflow: auto;
}

::v-deep .lf-dndpanel{
  width: 11vw;
  height: 33vw;
  margin-top: 5vh;
  overflow-y: auto;
}
::v-deep .lf-dnd-item{
    margin-top: 10px;
}
::v-deep .lf-dnd-shape{
  width: 10vw;
  height: 2vw;
  background-size: 50%;
}
</style>

目录结构:

我也是参考了官方文档,以及两位老师的博客来解决的,有需要可以查看

【教程】LogicFlow流程图界的神器-CSDN博客

LogicFlow自定义业务节点_logicflow自定义节点-CSDN博客

标签:lf,style,自定义,height,width,vue2,import,LogicFlow
From: https://blog.csdn.net/I_Allen_Liu/article/details/140491743

相关文章

  • Hive自定义函数编写方法(含源代码解读,超详细,易理解)
    一、Hive自定义函数介绍        1.内置函数        Hive自带了一些函数。比如:max/min等,但是数量有限,自己可以通过自定义UDF来方便的扩展。2.自定义函数        当Hive提供的内置函数无法满足你的业务处理需要时,此时就可以考虑使用用户自定义函数(UD......
  • 三分钟了解自定义表单自定义工作流的多个优势
    降本、提高效率、解决信息孤岛是很多企业亟需要解决的问题。什么样的软件平台可以实现这一目标?可以随时来了解低代码技术平台。它当中的自定义表单自定义工作流拥有多个优势特点,可以为企业降低技术门槛、提高工作效率,可视化操作界面的便利性更让职场朋友们深知是实现流程化办公的......
  • Nuxt.js头部魔法:轻松自定义页面元信息,提升用户体验
    扫描二维码关注或者微信搜一搜:编程智域前端至全栈交流与成长useHead 函数概述useHead是一个用于在Nuxt应用中自定义页面头部属性的函数。它由Unhead库提供支持,允许开发者以编程和响应式的方式设置每个页面的头部信息。useHead 函数类型useHead(meta:MaybeComputedRef<......
  • C++自定义双向迭代器
    #include<cassert>#include<memory>#include<vector>#include<iostream>classRange{public:usingIndex=uint64_t;usingSignedIndex=int64_t;usingOffset=int64_t;usingSize=uint64_t;Range()=d......
  • 自定义localStorage监听事件
    一、问题在项目开发过程中,发现有很多时候进行localStorage.setItem()操作设置本地存储后,页面必须刷新才能够获取到存储数据,而有些时候本地缓存更新后,页面无法通过再次刷新以获取本地缓存,这就导致依赖本地缓存的数据无法进行更新。为了解决这个问题,就必须要用到自定义localStorage......
  • vue2 简洁的行政区划选择组件封装
     vue2简洁的行政区划选择组件封装//判断变量是否为null或undefinedexportfunctionisNullOrEmpty(value){ returnvalue===null||value===undefined||value===''}//判断变量是否为null或undefinedexportfunctionisNullOrUndefined(value){ ret......
  • Vue2的计算属性
    计算属性概念:基于现有的数据进行计算出新的数据。依赖的数据变化,自动重新计算。语法:声明在computed配置项中,一个计算属性对应的是一个函数使用起来跟普通属性一样{{计算属性名}} <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><meta......
  • 组态软件之万维组态介绍(web组态、html组态、vue2/vue3组态、组态软件、组态编辑器)
     一、什么是组态软件组态软件是一种用于创建、配置和管理监控和控制系统的软件工具。组态是指不需要编写计算机程序、通过配置的方式完成工业应用开发的系统。它们通常用于工业自动化领域,用于实时监视和控制工业过程。组态软件提供了丰富的功能和工具,使用户能够创建用户界......
  • elementui的el-cascader-panel在jsx里如何自定义label和props属性
    render(){return(<el-cascader-panelonChange={(val)=>{this.handleFormatChange(val,'format','dataColumns',indexInMap)}}props={{renderLabel:(params)=>{......
  • ollama 模型国内加速下载,制作自定义Modelfile模型文件
    参考:https://www.zhihu.com/question/640579563/answer/3562899008https://github.com/ollama/ollama/blob/main/docs/modelfile.mdgguf格式介绍:https://www.datalearner.com/blog/10517057188355861、ollama模型国内加速下载ollama主要的模型文件格式是gguf,可以在mo......