项目中用代码生成组织架构图  有新增,编辑,删除的功能
 
    
 
 
生成树形图的组件git-hub地址: https://github.com/tower1229/Vue-Tree-Chart  这个插件还是很不错的
建议把整个安装包下载下来,写成组件使用.这样方便定制自己的业务需求
 
初始代码:
<template>
<table v-if="treeData.name">
<tr>
<td :colspan="treeData.children ? treeData.children.length * 2 : 1" :class="{parentLevel: treeData.children, extend: treeData.children && treeData.extend}">
<div :class="{node: true, hasMate: treeData.mate}">
<div class="person" @click="$emit('click-node', treeData)">
<div class="avat">
<img :src="treeData.image_url" />
</div>
<div class="name">{{treeData.name}}</div>
</div>
<div class="person" v-if="treeData.mate" @click="$emit('click-node', treeData.mate)">
<div class="avat">
<img :src="treeData.mate.image_url" />
</div>
<div class="name">{{treeData.mate.name}}</div>
</div>
</div>
<div class="extend_handle" v-if="treeData.children" @click="toggleExtend(treeData)"></div>
</td>
</tr>
<tr v-if="treeData.children && treeData.extend">
<td v-for="(children, index) in treeData.children" :key="index" colspan="2" class="childLevel">
<TreeChart :json="children" @click-node="$emit('click-node', $event)"/>
</td>
</tr>
</table>
</template>
增加编辑功能,可以与element-ui的el-popover弹出框组件一起使用
<el-popover
placement="top"
width="180"
trigger="hover">
<div style="margin: 0">
<el-button size="mini" type="primary" @click="addStock(0)" >新增</el-button>
<el-button type="primary" size="mini" @click="addStock(1)">编辑</el-button>
<el-button type="primary" size="mini" @click="dialogVisible2 = true" >删除</el-button>
</div>
<div class="avat" slot="reference">
{{treeData.name}}
</div>
</el-popover>

在网上找了好几个插件,感觉这个还是比较好用的

补充: 作者的树形图默认方向是由上向下,还提供了了切换为竖行的方法.但是我自己的项目是需要树形样式,由上之上的效果,如下图: 所以在原作者的代码上修改了下,主要是样式调整,有需要的可以看一下

<template>
<table v-if="treeData.name">
<tr v-if="treeData.children">
<td v-for="(children, index) in treeData.children" :key="index" colspan="2" class="childLevel">
<TreeChartOrder :json="children" @click-node="$emit('click-node', $event)"/>
</td>
</tr>
<tr>
<td :colspan="treeData.children ? treeData.children.length * 2 : 1" :class="{parentNode: treeData.children}">
<div class="node">
<div class="name">{{treeData.name}}</div>
</div>
</td>
</tr>
</table>
</template> <script>
export default {
name: "TreeChartOrder",
props: ["json"],
data() {
return {
treeData: {
name: 'root',
image_url: "https://static.refined-x.com/avat.jpg",
children: [
{
name: 'children1',
image_url: "https://static.refined-x.com/avat1.jpg"
},
{
name: 'children2',
image_url: "https://static.refined-x.com/avat2.jpg",
mate: {
name: 'mate',
image_url: "https://static.refined-x.com/avat3.jpg"
},
children: [
{
name: 'grandchild',
image_url: "https://static.refined-x.com/avat.jpg"
},
{
name: 'grandchild2',
image_url: "https://static.refined-x.com/avat1.jpg"
},
{
name: 'grandchild3',
image_url: "https://static.refined-x.com/avat2.jpg"
}
]
},
{
name: 'children3',
image_url: "https://static.refined-x.com/avat.jpg"
}
]
}
}
},
watch: {
json: {
handler: function(Props){
let extendKey = function(jsonData){
jsonData.extend = (jsonData.extend===void 0 ? true: !!jsonData.extend);
if(Array.isArray(jsonData.children)){
jsonData.children.forEach(c => {
extendKey(c)
})
}
return jsonData;
}
if(Props){
this.treeData = extendKey(Props);
}
},
immediate: true
}
},
methods: {
toggleExtend: function(treeData){
treeData.extend = !treeData.extend;
this.$forceUpdate();
}
}
}
</script> <style scoped>
table{border-collapse: separate!important;border-spacing: 0!important;}
td{position: relative; vertical-align: bottom;padding:0 0 40px 0;text-align: center; } .parentNode::after {content: "";position: absolute;left:49.9%;top:-56px;height:30px;border-left:2px solid #ccc;}
.childLevel::before{content: "";position: absolute;left:50%;bottom:57px;height:15px;border-left:2px solid #ccc;transform: translate3d(-1px,0,0)}
.childLevel::after{content: "";position: absolute;left:0;right:0;bottom:55px;border-top:2px solid #ccc;}
.childLevel:first-child:before, .childLevel:last-child:before{display: none;}
.childLevel:first-child:after{left:50%;height:15px; border:2px solid;border-color:transparent transparent #ccc #ccc;border-radius: 6px 0 0 0;transform: translate3d(1px,0,0)}
.childLevel:last-child:after{right:50%;height:15px; border:2px solid;border-color:transparent #ccc #ccc transparent;border-radius: 0 6px 0 0;transform: translate3d(-1px,0,0)}
.childLevel:first-child.childLevel:last-child::after{left:auto;border-radius: 0;border-color:transparent #ccc transparent transparent;transform: translate3d(1px,0,0)} .node{position: relative; display: inline-block;width: 13em;box-sizing: border-box; text-align: center;}
.node .person{position: relative; display: inline-block;z-index: 2;width:6em; overflow: hidden;}
.node .avat{display: block;width:4em;height: 4em;margin:auto;overflow:hidden; background:#fff;border:1px solid #ccc;box-sizing: border-box;}
.node .avat img{width:100%;height: 100%;}
.node .name{height:2em;line-height: 2em;overflow: hidden;width:95%; background:#eee;border:1px solid #ccc;box-sizing: border-box;border-radius: 5px;} </style>

git-hup地址: https://github.com/shengbid/my-element  这个文件是平时练习的项目,里面还有一些我写的其他博客的源码,有需要可以下载看看

vue-tree 组织架构图/树形图自动生成(含添加、删除、修改)的更多相关文章

  1. Android一个炫酷的树状图组织架构图开源控件实现过程

    Android一个炫酷的树状图组织架构图开源控件 文章目录 [1 简介] [2 效果展示] [3 使用步骤] [4 实现基本布局流程] [5 实现自由放缩及拖动] [6 实现添加删除及节点动画] [7 ...

  2. 使用jOrgChart插件实现组织架构图的展示

    项目要做组织架构图,要把它做成自上而下的树形结构. 一.说明 (1)通过后台查询数据库,生成树形数组结构,返回到前台. (2)需要引入的js插件和css文件: ①jquery.jOrgChart.cs ...

  3. js前端使用jOrgChart插件实现组织架构图的展示

    项目要做组织架构图,要把它做成自上而下的树形结构. 需要购买阿里云产品的,可以点击此链接购买,有红包优惠哦: https://promotion.aliyun.com/ntms/yunparter/i ...

  4. 公司人员组织架构图用思维导图软件MindManager怎么做

    有朋友一直不太明白组织架构图怎么做,其实组织架构图就是组织结构图.小编今天就在这里以一个公司为例,来给大家演示一番人员组织结构图怎么做. 老规矩,先说一下小编使用的软件跟电脑系统,这里用的是MindM ...

  5. Vue组织架构图组件

    vue-tree-chart   :deciduous_tree: Vue2树形图组件 安装 npm i vue-tree-chart --save 使用 in template: <TreeC ...

  6. python生成组织架构图(网络拓扑图、graph.editor拓扑图编辑器)

    Graph.Editor是一款基于HTML5技术的拓补图编辑器,采用jquery插件的形式,是Qunee图形组件的扩展项目,旨在提供可供扩展的拓扑图编辑工具, 拓扑图展示.编辑.导出.保存等功能,此外 ...

  7. vue 辅助开发工具(利用node自动生成相关文件,自动注册路由)

    vue 辅助开发工具 前言 有没有因为新建view,component,store的繁琐操作而苦恼,需要新建文件件,新建vue文件,新建js文件,注册路由...等一系列无价值操作浪费时间,为了解决这个 ...

  8. (六十五)c#Winform自定义控件-思维导图/组织架构图(工业)

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  9. 设计数据库 ER 图太麻烦?不妨试试这两款工具,自动生成数据库 ER 图!!!

    忙,真忙 点赞再看,养成习惯,微信搜索『程序通事』,关注就完事了! 点击查看更多精彩的文章 这两个星期真是巨忙,年前有个项目因为各种莫名原因,一直拖到这个月才开始真正测试.然后上周又接到新需求,马不停 ...

随机推荐

  1. 给初学者的总结:jquery选择器

    刚学jquery的时候是又渣又蠢的小白,而且把js和jquery混淆在一起. 把jquery的全部选择器总结在一起,才发现和css选择器好一部分都很像,并且有些选择器还很少用过. 我学习前端的路程是先 ...

  2. Typora的图片根目录设置,

    需求:使Typora的图片,设置到指定的文件里. 方便上传与转移. 步骤: 1 位置: 编辑 ->图片工具->设置图片根目录. 2 .Preference -> Editor -&g ...

  3. UVa 12099 The Bookcase (DP)

    题意:有 n 本书,每本书有一个高度和宽度,然后让你制作一个3层的书架,可以放下所有的书,并且要高*宽尽量小. 析:先把所有的书按高度进行排序,然后dp[i][j][k] 表示 前 i 本书,第二 层 ...

  4. Prolific PL2303 usb 转串口Win8 Win8.1驱动

    买了根USB转RS232串口的线,Pl2303芯片的.卖家和官方都称不支持Win8,但鄙人不信在Win7上能用在Win8/8.1就用不起来. 官方最新版的v1.9.0的驱动描述说不支持Win 8/8. ...

  5. 探索式软件测试—Exploratory Software Testing

    最近找到去年上半年看过一本关于测试方面书籍的总结笔记,一直放在我的个人U盘里,当时是用Xmind记录的,现在重新整理下分享给大家了! James A.Whittaker [美] 詹姆斯·惠特克(软件测 ...

  6. ssh关于含有外键的传值中无法识别正确的action的原因和解决办法

    在含有外键的表中,要保存一个值到这个外键时:逻辑思路:需要先将jsp页面的值传到相应的action中,在这个action中需要引入这个外键的实体层和DAO层(DAO层只需set方法),在执行函数中对于 ...

  7. C99一些特性

    __FILE__   对应代码文件名__LINE__   对应代码行号__DATE____TIME____FUNC__ __FUNCTION__ 在Visual Studio 2005中,默认情况下, ...

  8. 关于Qt官方下载页的最新变动

    时间过得很快,现在Qt已经迎来了5.10版本,但是当我们去下载页下载对应安装包的时候,已经找不到之前的offline安装包了.你能够看到的只有在线安装包,并且我自己有做过测试,国内的网络基本上没有机会 ...

  9. TSQL--约束基础和Demo

    --============================================================ SQL SERVER 中使用constraint和role来对数据进行限制 ...

  10. Python 单元测试 增强系统健壮性

    问题背景交代 注意,JulyNovel只爬取免费小说,所有vip章节全部导航至起点网站,遵循robots协议,所有数据仅供学习用途,侵删 通过编写单元测试,提高JulyNovel系统可靠性 首先我们知 ...