orgChart实现竖向排列组织图(js实现组织机构图)

article/2025/10/6 23:39:35

一、前言

快过年了,博主这几天不算忙,又刚好用到orgChart来做组织机构图,写了这篇文章,欢迎大家指正。注意:我说的竖向是指文字竖着排列。

依赖库:jquery,jquery颜色选择器,orgChart组织框图

orgChart文档:orgChart

颜色选择器:jquery颜色选择器插件

demo预览地址:https://zekeup.com/openSource/OrgChart-Vertical/index.html

demo下载地址(rar压缩包):https://zekeup.com/package/OrgChart-Vertical.rar

话不多说,先整效果图给大家看看

图1

主要实现功能:横向竖向,还有背景颜色修改

二、思路:

如何把默认横排变成竖排?在orgChart初始化时,有一个createNode属性,他返回一个$node对象,这是很重要的,博主想到给想要显示成竖排的节点添加一个class,通过修改默认样式,实现竖向排列。

三、关键代码

js代码,依赖jquery

var oc=null;
$(function() {//本地session存储// if(sessionStorage.getItem('data_org')){//     data_org=JSON.parse(sessionStorage.getItem('data_org'));// }// sessionStorage.setItem('data_org',JSON.stringify(data_org));getModelChart();//颜色选择器$('.bgColor').colpick({layout:'hex',submit:0,colorScheme:'dark',onChange:function(hsb,hex,rgb,el,bySetColor) {//改变颜色let id=$(el).attr('data-id');$('.node_'+id+ ' .title').css({background: '#'+hex,});$(el).css('border-color','#'+hex);if(!bySetColor) $(el).val('#'+hex);},onBeforeShow:function(el){if(!isNull(this.value)){$(this).colpickSetColor(this.value.substring(1));}$(el).css({'z-index':'20000',});}}).keyup(function(){if(!isNull(this.value)){$(this).colpickSetColor(this.value.substring(1));}});
});getModelChart = function(){oc=$('#chart-container').orgchart({'data' : data_org,'depth': 20,'nodeTitle': 'name','direction': 't2b','exportButton': true,'exportFilename': '模型关系图','pan': true,'createNode': function($node, data) {$node.addClass('node_'+data.id);//背景颜色if(!isNull(data.bgColor)){$node.children('.title').css('background-color',data.bgColor);}else{//默认$node.children('.title').css('background-color','#0295ff');}//横排竖排 思路 给竖向的td上加上class tdpif(!isNull(data.style) && data.style=='V'){$node.addClass('hNode');}$("#addTop").css('display','none');if(isNull(data.name)){data.name="无";}if(isNull(data.orderNum)){data.orderNum="无";}if(isNull(data.remarks)){data.remarks="无";}if(isNull(data.bgColor)){data.bgColor="";}if(isNull(data.style)){data.style="";}strContent=data.id+"~~~"+data.name+"~~~"+data.remarks+"~~~"+data.orderNum+"~~~"+data.parentId+"~~~"+data.bgColor+"~~~"+data.style;//替换换行符data.name=data.name?data.name.replace(/<br\/>/g,''):'';var strTable="<table class='tab'>" +"<tr style='height: 50px;text-align:top;'>" +"<td  colspan='2' class='dd' >" +"<div class='bumenxinxi'><p>"+data.name+"</p></div>" +"<div><a href='javascript:void(0)' onclick='closeDlg()' class='guanb'>X</a></div>"+"</td>" +"</tr>"+"<tr class='neirong'>" +"<td class='xinxi-zuo'>排序:</td>" +"<td class='tdd'>"+data.orderNum+"</td>" +"</tr>"+"<tr class='neirong'>" +"<td class='xinxi-zuo'>备注:</td>" +"<td class='tdd'>"+data.remarks+"</td>" +"</tr>"+"<tr class='neirong'>" +"<td class='anliudahezi' colspan='2'>" +"<div class='anliuhezi'>" +"<div class='anliu'><a href='javascript:void(0)' onclick='del(\""+data.id+"\")'>刪除</a></div>" +"<div class='anliu'><a href='javascript:void(0)' onclick='editParent(\""+strContent+"\")'>编辑</a></div>" +"<div class='anliu'><a class='bgColor' data-id='"+data.id+"' href='javascript:void(0)'>改变颜色</a></div>" +"<div ><a class='anliu-tj' href='javascript:void(0)' onclick='addSub(\""+data.id+"\",\""+data.bgColor+"\",\""+data.style+"\")'>添加下级</a></div>" +"</td>" +"</tr></table>";var nodePrompt = $('<i>', {'class': 'fa fa-info-circle second-menu-icon','style': 'width:100%; height:100%;',click: function() {var flag=false;if($(this).siblings('.second-menu').css('display')=='block'){flag=true;}//打开弹出框 ,先关闭所有再打开$(".second-menu").css('display','none');if(flag){$(this).siblings('.second-menu').hide();}else{$(this).siblings('.second-menu').show();}}});var secondMenu = '<div class="second-menu t2b">'+strTable+'</div>';$node.append(nodePrompt).append(secondMenu);}});$(".orgchart").css('background','#fff');
}//判断是否为空
isNull=function(str) {if (typeof (str) == "undefined" || str == null || str == "" || str == "null")return true;elsereturn false;
};//关闭详细信息弹出框
closeDlg=function(){$(".second-menu").css('display','none');
};
//编辑
editParent=function(strContent){var arr=strContent.split("~~~");var formData={'id':arr[0],'name':arr[1],'remarks':arr[2],'orderNum':arr[3],'parentId':arr[4],'bgColor':arr[5],'style':arr[6],};$("#formData").form("load", formData);$('#bgColor').css('border-color',arr[5]);$('#dlg').dialog('open');
};//添加下级
addSub=function(parentId,bgColor,style){// $("#formData").form("clear");// formDataView("formData","edit");$("#parentId").val(parentId);$("#bgColor").val(bgColor);$('#bgColor').css('border-color',bgColor);$("#styleM").combobox('setValue',style);// $('#dlg').dialog('open');
};
//关闭弹出层
closeDialog=function(){// $('#dlg').dialog('close');
};
//关闭弹出层
mainCloseDialog=function(){$('#mainDlg').dialog('close');
};function del(id){// data_org.forEach(element => {// });
}function test(){if(oc){var hierarchy = oc.getHierarchy();console.log('结果在控制台打印',hierarchy);alert('结果在控制台打印'+hierarchy);}}

css代码。实现竖排效果

html,body{height: 100%;width: 100%;margin: 0;
}
.orgchart{height: 100%;width: 100%;overflow: auto;}*, *:before, *:after {-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;}#chart-container {overflow-x: auto;position: relative;height: 100%;text-align: center;}/* 菜单 */.orgchart .node .second-menu {display: none;position: absolute;top: 0;left: 100%;border-radius: 10px;box-shadow: 0 0 10px 1px #999;background-color: #FFF;z-index: 30;}.orgchart .node .second-menu .avatar {width: 60px;height: 60px;border-radius: 30px;}.l2r{transform:rotate(-90deg) translate(-40px,-40px) rotateY(180deg);}.r4l{transform: rotate(90deg) translate(40px,0px) rotateY(-90deg);}.dd{text-align:top;border-bottom: 1px solid #0295ff;}.bumenxinxi{text-align: left;margin-left: 10px;float: left;color:#0295ff; font-size: 20px; height: 30px; line-height: 40px;vertical-align:top;}.guanb{width: 40px;height: 40px;float: right; line-height: 40px;text-align:center;color: #0295FF; text-decoration: none;}.xinxi-zuo{width: 100px;text-align: right; color: darkslategray;font-size:18px;}.anliu{float: right; line-height: 30px;width: 70px; height: 30px;text-align: center;border: 1px solid gray;margin: 5px; border-radius:3px ; }.anliu>a,.anliu-tj{width: 80px;height: 30px;text-decoration: none; color: #4a4545;}.anliu-tj{background-color: #0295FF; float: right;color: white; line-height: 30px; text-align: center;margin: 5px; border-radius:3px ; }.anliuhezi{ width: auto;height: 40px;display: flex;}.anliudahezi{height:40px;vertical-align:bottom;}.tdd{padding-left: 10px;font-size:18px;}.neirong{line-height:40px;}.orgchart .node .title .symbol{float: left;height:100%;margin-top:0;line-height: inherit;}.orgchart .node .title{text-align: center;font-size: 14px;font-weight: 700;height: 40px;line-height: 40px;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;background-color: #0295ff;color: #fff;border-radius: 4px;}.orgchart .second-menu-icon {transition: opacity .5s;opacity: 0;right: 0;top: 0;text-align:right;padding:3px 3px 0 0;z-index: 2;font-size: 14px;position: absolute;color: #fff;}.orgchart .node:hover .second-menu-icon {opacity: 1;}/*竖向文字  思路 给竖向的加上class hNode */.orgchart .hNode .title .symbol{display:none;float: left;margin-left:0;margin-top:0;width:100%;text-align: center;height:20px;}.orgchart .hNode{width:50px;padding:0;margin:0 10px;}.orgchart .hNode .title{font-size: 14px;padding: 20px 15px;font-weight: 700;height: auto;line-height: 18px;overflow: hidden;text-overflow: inherit;white-space: normal;color: #fff;border-radius: 4px;width: 100%;word-break: break-word;/*强制换行*/}/* 字符省略 */.orgchart .ellipsis-icon{left: 0;bottom: 0px;padding-bottom:4px;width:100%;text-align: center;z-index: 1;color: #fff;font-size: 14px;position: absolute;}

html代码

<div id="chart-container" style="width:100%;height: 100%"></div>

 


http://chatgpt.dhexx.cn/article/IWpWDeWP.shtml

相关文章

武汉python自动化测试招聘,python自动化测试工程师招聘_Python-自动化测试面试

1、以你做过的项目&#xff0c;举例来说一下你的自动化测试是怎么做的&#xff1f; 参考答案&#xff1a;就拿简历上的ecshop项目来说吧&#xff0c;在编写脚本前&#xff0c;我们会对系统进行评估&#xff0c;确认这个系统可不可以实现UI自动化&#xff0c;如果可以的话&#…

测试ai模糊软件,AE/PR人工智能自动人脸检测马赛克模糊插件

Blace – AI Face Detection是一款作用在AE以及PR软件中的AI插件&#xff0c;能够自动识别检测人脸并智能添加马赛克边框&#xff0c;易于使用且基于AI的检测&#xff0c;控制检测区域并排除检测&#xff0c;有需要的用户不要错过了&#xff0c;赶快来下载吧&#xff01; 兼容性…

自动化面试题

自动化面试题 自动化&#xff1a;将人工测试转换成自动化脚本/工具去运行 优势&#xff1a;节省时间&#xff08;20% - 30%&#xff09;&#xff0c;提高工作效率 Python selenium/appium/airtest/requests unittest Jenkins WEB自动化 1. 什么样的项目适合做自动化&…

Python&OpenCV自动人脸打马赛克&调色系统[源码&UI操作界面&部署教程]

1.视频演示&#xff1a; [项目分享]Python&#xff06;OpenCV自动人脸打马赛克&#xff06;调色系统[源码&#xff06;UI操作界面&#xff06;部署教程] 2.图片演示&#xff1a; 3.图像颜色检索&#xff06;替换&#xff1a; 4.马赛克分类&#xff1a; 使用opencv库中的haar…

Python opencv:人眼/人脸识别并实时打码处理

利用Pythonopencv实现从摄像头捕获图像&#xff0c;识别其中的人眼/人脸&#xff0c;并打上马赛克。 系统环境&#xff1a;Windows 7 Python 3.6.3 opencv 3.4.2 一、系统、资源准备 要想达成该目标&#xff0c;需要满足一下几个条件&#xff1a; 找一台带有摄像头的电脑…

seleniumxpath打码平台

selenium使用 一 bs4搜索文档树二 css选择器三 selenium基本使用四 无界面浏览器五 selenium其它用法5.1 登录百度5.2 获取位置属性大小&#xff0c;文本5.3 元素操作5.4 执行js代码5.5 切换选项卡5.6 浏览器前进后退5.7 异常处理 六 selenium登录cnblogs获取cookie七 抽屉半自…

第十一章 自动编码器

简介&#xff1a;自动编码器是一种可以进行无监督学习的神经网络模型。一般而言&#xff0c;一个完整的自动编码器主要由两部分组成&#xff0c;分别是用于核心特征提取的编码部分和可以实现数据重构的解码部分。 1.自动编码器入门 在自动编码器中负责编码的部分也叫做编码器&a…

Python 题库自动化面试题

1、自动化代码中,用到了哪些设计模式? 单例设计模式 工厂模式 PO设计模式 数据驱动模式 面向接口编程设计模式 2、什么是断言( Assert) ? 断言 Assert 用于在代码中验证实际结果是不是符合预期结果&#xff0c; 如果测试用例执行失败会抛出异常并提供断言日志 3、什么…

Python实现对视频自动打码

我们在观看视频的时候&#xff0c;有时候会出现一些奇怪的马赛克&#xff0c;影响我们的观影体验&#xff0c;那么这些马赛克是如何精确的加上去的呢&#xff1f; 本次我们就来用Python实现对视频自动打码&#xff01; 准备工作 环境咱们还是使用 Python3.8 和 pycharm2021 即…

Python——超级鹰打码平台实现selenium对b站的自动化登陆

目录 一 、Chrome&#xff08;谷歌&#xff09;驱动器的下载 &#xff08;一&#xff09;驱动器版本选择 &#xff08;二&#xff09;下载Chrome驱动器 二、需要安装的库 &#xff08;一&#xff09;安装命令 &#xff08;二&#xff09;指定selenium版本原因 三、实现步…

selenium 自动化测试

Selenium 是一个用于Web应用程序测试的工具&#xff0c;支持多平台、多浏览器、多语言去实现自动化测试。目前在Web自动化领域应用越来越广泛。 selenium 介绍 Selenium的特点如下&#xff1a; 开源、免费多浏览器支持&#xff1a;Firefox、Chrome、IE、Opera、Edge多平台支…

深度学习中的自动编码器:TensorFlow示例

什么是自动编码器? 自动编码器是重建输入的绝佳工具。简单来说,机器就是一个图像,可以生成一个密切相关的图片。这种神经网络中的输入是未标记的,这意味着网络能够在没有监督的情况下进行学习。更准确地说,输入由网络编码,仅关注最关键的特征。这是自动编码器因降维而流行…

博客论坛自动采集器 - 蓝天采集器源码

介绍&#xff1a; 博客论坛自动采集器 做一个自动采集文章的网站&#xff0c;在你网站根目录创建一个目录随便我这边是caiji&#xff0c;然后把采集器的源码上传到caiji里面去。 安装:你的域名/caiji访问配置好数据库什么的安装就行。数据前缀不要和原来博客的相同。 安装完成…

Pytorch基础-07-自动编码器

自动编码器&#xff08;AutoEncoder&#xff09;是一种可以进行无监督学习的神经网络模型。一般而言&#xff0c;一个完整的自动编码器主要由两部分组成&#xff0c;分别是用于核心特征提取的编码部分和可以实现数据重构的解码部分。 1 自动编码器入门 在自动编码器中负责编码…

python手工打码_python云打码

广告关闭 腾讯云11.11云上盛惠 &#xff0c;精选热门产品助力上云&#xff0c;云服务器首年88元起&#xff0c;买的越多返的越多&#xff0c;最高返5000元&#xff01; 为什么需要了解打码平台的使用现在很多网站都会使用验证码来进行反爬&#xff0c;所以为了能够更好的获取…

python你实现视频自动打码,了解妨碍你观看精彩的马赛克是怎么精准形成的

前言 嗨喽&#xff01;大家好呀&#xff0c;这里是魔王呐~ 我们在观看视频的时候&#xff0c;总有一些精准得马赛克挡住我们想看得地方&#xff0c;严重影响我们的观影体验&#xff01;&#xff01; 那么这些马赛克是如何精确的加上去的呢&#xff1f; 本次我们就来用Python…

易语言php验证码识别,易语言自动打码验证码服务端带案例

易语言通用验证码识别服务端,用来做接口还是可以的! 将127.0.0.1改成自己的服务器IP,或者域名 php案例: $rel = file_get_contents(http://www.zhuangjiba.com/d/file/help/2018/08/cfdefaddb3f47d78f8c66a7de28720aa.png); $code = _upload($rel); echo 验证码:.$code; f…

自动打码神器是什么

自动打码神器是什么 提到自动打码神器&#xff0c;可能很多网友会想到答题吧自动打码平台、远程答题器等&#xff0c;除了这一些软件之外&#xff0c;还有不少我们都不知道的软件正在等待大家的发掘。今天&#xff0c;小编就给大家先介绍一款专门批量识别验证码的平台——答题吧…

如何用 ISO 镜像制作 U 盘安装盘(通用方法、无需 WinPE)

文章目录 ★扫盲若干【基本概念】★啥是【通用】制作方法&#xff1f;★为啥选择这几款工具&#xff1f;★rufus 的玩法&#xff08;Windows 平台&#xff09;★UNetbootin 的玩法&#xff08;跨平台&#xff09;★dd 的玩法&#xff08;跨平台&#xff09;★优缺点对比★读者…

利用UltraISO刻录光盘启动盘

1 介绍 虽说现在越来越倾向于使用U盘作为启动盘&#xff0c;但本文还是要讲一讲怎样使用UltraISO制作光盘启动盘—作为系统安装的一种方法。我不知道未来光盘会不会消失&#xff0c;但本文确实能起到保护历史文化遗产的作用。但我希望不要消失&#xff0c;就好像大家都在说纸质…