# 业务关系图JS连线组件

https://gitee.com/flyer555_admin/startwe_line

#### 项目介绍
纯div+css3实现模拟画线条功能,用于前端业务关系图绘制的连线组件

#### 软件架构
软件架构说明
使用前端模板引擎 artTemplate,
jquery,
数学计算方程库algebra 
div+css3实现
轻量级的纯div连线组件

#### 安装教程
###
1、引入 css: third/shape/shape.css

2. 引入jquery:  third/jquery/jquery-2.1.4.min.js 

3、引入artTemplate: third/template/template_debug_3_0_0.js

4、引入 algebra 数学公式计算库:third/algebra/algebra-0.2.5.min.js

5、引入画线图形组件库:third/shape_min/shape.min.js

#### 使用说明
1. 承载线条和div层的容器样式代码参考
###
        .paper-area {
            background-color: #ffffff;
            z-index: 1;
            position: relative;
            margin: 30px auto;
            overflow: hidden;
            display: block;
            box-shadow: rgba(0, 0, 0, 0.31) 0 0 13px;
        }
        .paper-area .paper-area{
            background-color: transparent;
            margin: 0 auto;
            z-index: 0;
        }
###

2. div层代码参考
 
        .control-abs-component{
            background-color: rgba(255,255,255,.7);
            width: 140px;
            height: 42px;
            padding: 5px;
            font-size: 0;
            display: block;
            border: 1px solid transparent;
            position: absolute;
            left: 0;
            top: 0;
            z-index: 1;
            -webkit-user-select: none;
            -moz-user-select: none;
            -ms-user-select: none;
            user-select: none;
        }
###
3、线条自定义样式参考
 .ours-line-text .text-color{
     color: #ffffff;
 }
###
4、body内html代码 参考
####
<div class="page-abs paper-area A4 bg-center active" style="background-color: rgb(255, 255, 255); width: 210mm; height: 297mm;" ours-e-mousedown="down2selectPaperArea">
 
    <div id="ctrl_509534961758118874" targets-json="[{&quot;hasArrow&quot;:false,&quot;hasFromArrow&quot;:true,&quot;lineText&quot;:&quot;连线1&quot;}]" to-ids="ctrl_806025145230846776"  class="control-abs control-abs-component control-abs-oneLine" style="left: 125px; top: 86px; opacity: 1; width: 100px; height: 100px; border-radius: 30px; border-width: 1px; background-color: rgb(255, 255, 255); border-color: rgb(230, 230, 230); border-style: solid;" drag-status="down">

        <div class="control-label-abs" style="opacity: 1; font-size: 14px; background-color: rgb(255, 255, 255); vertical-align: middle; color: rgb(51, 51, 51); font-weight: normal; text-align: center; white-space: normal;">a</div>

    </div>


    <div id="ctrl_806025145230846776" targets-json="[{&quot;hasArrow&quot;:false,&quot;hasFromArrow&quot;:true,&quot;lineText&quot;:&quot;连线2&quot;}]" to-ids="ctrl_967062970548743280" class="control-abs control-abs-component control-abs-oneLine" style="left: 399px; top: 86px; opacity: 1; width: 100px; height: 100px; border-radius: 30px; border-width: 1px; background-color: rgb(255, 255, 255); border-color: rgb(230, 230, 230); border-style: solid;" drag-status="start">

        <div class="control-label-abs" style="left:px;top:px;opacity:1;font-size:14px;background-color:#ffffff;vertical-align:middle;color:#333333;font-weight:normal;text-align:center;white-space:normal">b</div>

    </div>


    <div id="ctrl_967062970548743280"  class="control-abs control-abs-component control-abs-oneLine" style="left: 251px; top: 269px; opacity: 1; width: 100px; height: 100px; border-radius: 30px; border-width: 1px; background-color: rgb(255, 255, 255); border-color: rgb(230, 230, 230); border-style: solid;" drag-status="down">

        <div class="control-label-abs" style="left:px;top:px;opacity:1;font-size:14px;background-color:#ffffff;vertical-align:middle;color:#333333;font-weight:normal;text-align:center;white-space:normal">c</div>

    </div>


    <div id="ctrl_681444790719644499"  class="control-abs control-abs-component control-abs-oneLine" style="left: 557px; top: 349px; opacity: 1; width: 100px; height: 100px; border-radius: 30px; border-width: 1px; background-color: rgb(255, 255, 255); border-color: rgb(230, 230, 230); border-style: solid;" drag-status="down">

        <div class="control-label-abs" style="left:px;top:px;opacity:1;font-size:14px;background-color:#ffffff;vertical-align:middle;color:#333333;font-weight:normal;text-align:center;white-space:normal">d</div>

    </div>

</div>

5、Js调用部分 
####

    var CurrEvents = {
        click:function(cfg){
            var fromShapeId = $(cfg.el).attr('from-shape-id');
            var toShapeId = $(cfg.el).attr('to-shape-id');
            alert('click--> fromId:'+fromShapeId+',toShapeId:'+toShapeId);
            console.log('click--> fromId:'+fromShapeId+',toShapeId:'+toShapeId);
        },
        click4text:function(cfg){
            var fromShapeId = $(cfg.el).attr('from-shape-id');
            var toShapeId = $(cfg.el).attr('to-shape-id');
            alert('clickText--> fromId:'+fromShapeId+',toShapeId:'+toShapeId);
            console.log('clickText--> fromId:'+fromShapeId+',toShapeId:'+toShapeId);
        },
        mouseenter4text:function(cfg){
            var fromShapeId = $(cfg.el).attr('from-shape-id');
            var toShapeId = $(cfg.el).attr('to-shape-id');
            console.log('mouseenter4text--> fromId:'+fromShapeId+',toShapeId:'+toShapeId);

        },
        mouseleave4text:function(cfg){

            var fromShapeId = $(cfg.el).attr('from-shape-id');
            var toShapeId = $(cfg.el).attr('to-shape-id');
            console.log('mouseleave4text--> fromId:'+fromShapeId+',toShapeId:'+toShapeId);
        }
    };


    /**
     * 绑定元素属性说明
     *
     * targets-json="[{&quot;hasArrow&quot;:false,&quot;hasFromArrow&quot;:true,&quot;lineText&quot;:&quot;连线1&quot;}]"
     * to-ids="ctrl_806025145230846776"
     *
     * targets-json为json数组[{
     * hasArrow, 是否在目标元素位置有箭头
     * hasFromArrow,//是否在出发元素位置有箭头
     * lineText //连线的文本内容
     * }]
     * to-ids为目标连线id列表
     * ****/
    ours.buildShapeLines('.control-abs',{
        container:'.page-abs', //指定 渲染容器
        cls:'',
        textCls:'text-color',//文本自定义样式
        color:'pink', //线条颜色
        lineHeight:2,//线条粗细,
        zIndex:1,
        click:'CurrEvents.click',//点击事件绑定函数
        click4text:'CurrEvents.click4text', //线条文本点击事件
        mouseenter4text:'CurrEvents.mouseenter4text',//线条文本鼠标移入事件
        mouseleave4text:'CurrEvents.mouseleave4text'//线条文本鼠标移除事件
    });
 
//参考代码 lib/third/shape_min/test-shape.html


 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐