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. 面向对象之属性与方法

    一、属性(field) 语法格式:修饰符 数据类型 属性名 = 初始化值   修饰符:常用的权限修饰符有:pr […]...

  2. 【Netty】使用解码器Decoder解决TCP粘包和拆包问题

    解码器Decoder和ChannelHandler的关系 netty的解码器通常是继承自ByteToMessa […]...

  3. SpringBoot连接Redis服务出现DENIED Redis is running in protected mode because protected mode is enabled

      修改redis.conf,yes 改为 no...

  4. 基于laravel5.5和vue2开发的个人博客

    本项目使用 PHP 框架 Laravel 5.5 进行开发。系统后台使用了Vuejs + Element-UI […]...

  5. js制作浮动广告

    ———————— […]...

  6. 华为mate40和苹果12promax哪个好 有什么区别?看了这篇再决定

    众所周知,iphone12promax和华为mate40pro这两款手机都是比较热门的新机型,很多用户朋友们已 […]...

  7. 不停机图片升级迁移

    在我看来,凡是真实环境需要不停机迁移,其实都是有的复杂的,需要考虑的事情有很多,也可以从重思考到很多,以及以后 […]...

  8. 音频文件基本处理流程 Python中的音频和数字信号处理(DSP)

    声音信号的数字化 数字信号基础知识:https://wenku.baidu.com/view/be544303 […]...

展开目录

目录导航