11.删除组件--从零起步实现基于Html5的WEB设计器Jquery插件(含源码)

coolalam 2021-11-28 原文


11.删除组件–从零起步实现基于Html5的WEB设计器Jquery插件(含源码)

本节论述如何进行组件的删除,如下图。

 

其操作过程肯定是先要选定要删除的组件,并显示出删除按钮,当然取消选择的时候要隐藏按钮,点击删除组件后,除了组件本身被删除,与之相连的连线也要删除,

理清楚这个过程,我们就可以设计一个删除按钮的指示器

    function RemoveIndicator(component){
        this.component=component;
        var me=this;
        var bclose = new paper.PointText({
            point: [component.properties.x+component.properties.width+3, component.properties.y-3],
            content: \'\u00D7\',
            fillColor: "red",
            fontWeight:"Bold",
            fontFamily: "arial",
            fontSize: 16,
            justification: \'right\',
            opacity: 0.75
        });
        this.group=new paper.Group();
        this.group.addChild(bclose);
        bclose.onMouseEnter = function() {
            this.set({opacity: 1});
            document.body.style.cursor = \'pointer\';
        }
        bclose.onMouseLeave = function() {
            this.set({opacity: 0.5});
            document.body.style.cursor = \'default\';
        }
        this.group.visible=false;
        bclose.onClick = function(event) {
            if (event.event.button == 0) {
                    me.component.designer.removeComponent(me.component);
            }
        }
        return this;
    }
    RemoveIndicator.prototype = {
        show: function () {
            this.group.visible=true; 
            return this;
        },
        hide:function(){
            this.group.remove();
            return this;
        }
    };

注意此处就不需要扩展Component组件了,直接定义它的原型,但是每一个指示器定义了一个this.component表示它归属的组件。它出现的位置是组件右上角,所以坐标从x+width+3,y-3,分别偏移3个像素,

注意上图中高亮的代码,调用设计器视图的removeComponent方法:

    VisualDesigner.prototype.removeComponent = function (component) {
        var me=this;

        $.each(me.lineManager.getLines(component),function(index,val){
            //遍历组件相连的每一条线
            val.destroy();//删除线
            delete me.lines[val.properties.id]
        })
        component.unselect(); //取消选择,删除组件的连接点,大小调整锚点
        component.destroy(); //删除组件
        delete me.nodes[component.properties.id]

        $.each(this.lines, function (idx, item) {
            if (item.properties.id==component.properties.id)
            {
                //如果要删除是连线
                item.unselect();
                item.destroy();
                delete me.lines[item.properties.id]
            }
        })
    }

同时在Component的select 和unselect分别调用它的show/hide显示和隐藏。

    Component.prototype.select = function () {
        if (!this.designer.lining){
            this.group.children[0].selected = true;
            this.resizer=new Resizer(this).render();
            if (this.removeIndicator)
                this.removeIndicator.show();
            else
                this.removeIndicator=new RemoveIndicator(this).show();
        }
    }
    Component.prototype.unselect = function () {
        this.group.children[0].selected = false;
        if (this.resizer){
            this.resizer.destroy();
            this.resizer=null;
            document.body.style.cursor="default"
        }
        if (this.removeIndicator){
            this.removeIndicator.hide();
            this.removeIndicator=null;
        }

    }

 

源代码:sample.1.9.rar

直接运行查看

(本文为原创,在引用代码和文字时请注明出处)


关键字
:设计器源代码,Web设计器,工作流设计器,jQuery插件,组态设计器,SCADA系统设计器,流程图设计,表单设计建模,报表设计,可视化,设计时,运行时,轻量级开放平台。

发表于
2018-09-29 11:41 
撸码不掇 
阅读(432
评论(0
编辑 
收藏 
举报

 

版权声明:本文为coolalam原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/coolalam/p/9722901.html

11.删除组件--从零起步实现基于Html5的WEB设计器Jquery插件(含源码)的更多相关文章

  1. 8.图片组件和动画效果–从零起步实现基于Html5的WEB设计器Jquery插件(含源码)

    8.图片组件和动画效果–从零起步实现基于Html5的WEB设计器Jquery插件(含源码) 前面示 […]...

  2. 13.美化界面–从零起步实现基于Html5的WEB设计器Jquery插件(含源码)

    13.美化界面–从零起步实现基于Html5的WEB设计器Jquery插件(含源码)  今天花了一个 […]...

随机推荐

  1. AxureRP8实战手册(基础1-10)

    基础操作篇 本篇包含56种常见的基础操作,初学者应在掌握本篇内容后再进行实战案例篇的学习,以免产生学习障碍。同 […]...

  2. 017 PCIe总线的事务层(一)

    017 PCIe总线的事务层(一) 一、PCIe总线的事务层 事务层是PCIe总线层次结构的最高层,该层次将接 […]...

  3. IO流(字节流,字符流,缓冲流)

    一:IO流的分类(组织架构) 根据处理数据类型的不同分为:字符流和字节流 根据数据流向不同分为:输入流和输出流 […]...

  4. STL中erase()的陷阱

    最近在刷stl源码剖析这本书时,对于vector的erase()函数引起了我的注意 在删除单个元素时是这样定义 […]...

  5. oracle11g中SQL优化(SQL TUNING)新特性之SQL Plan Management(SPM)

    1.   简介 Oracle Database11gR1引进了SQL PlanManagement(简称SPM […]...

  6. Linux(Centos7)下redis5集群搭建和使用

      1、简要说明   2018年十月 Redis 发布了稳定版本的 5.0 版本,推出了各种新特性,其中一点是 […]...

  7. 开放API接口 USDT快捷接入充提教程

      API,全称Application Programming Interface,中文翻译为应用程序编程接口 […]...

  8. 循序渐进VUE+Element 前端应用开发(10)— 基于vue-echarts处理各种图表展示 – 伍华聪

    循序渐进VUE+Element 前端应用开发(10)— 基于vue-echarts处理各种图表展示 […]...

展开目录

目录导航