react中使用orgchart组织结构插件
<p>一、使用前的准备</p><p>$ npm install jquery</p>
<p>$ npm install expose-loader</p>
<p> </p>
<p>$ npm install orgchart</p>
<p><span class="hljs-variable">$ npm install font-awesome</span></p>
<p> </p>
<p>二、对应js页面demo</p>
<div class="cnblogs_code">
<pre>import React, { Component } from 'react'<span style="color: rgba(0, 0, 0, 1)">;
import PageHeaderWrapper from </span>'@/components/PageHeaderWrapper'<span style="color: rgba(0, 0, 0, 1)">;
import $ from </span>'jquery'<span style="color: rgba(0, 0, 0, 1)">;
import </span>'orgchart'<span style="color: rgba(0, 0, 0, 1)">;
import </span>'orgchart/dist/css/jquery.orgchart.css'<span style="color: rgba(0, 0, 0, 1)">;
import </span>'font-awesome/css/font-awesome.css'<span style="color: rgba(0, 0, 0, 1)">;
const datascource </span>=<span style="color: rgba(0, 0, 0, 1)"> {
name: </span>'老板'<span style="color: rgba(0, 0, 0, 1)">,
title: </span>'老板'<span style="color: rgba(0, 0, 0, 1)">,
id: </span>'1'<span style="color: rgba(0, 0, 0, 1)">,
key: </span>'1'<span style="color: rgba(0, 0, 0, 1)">,
children: [
{
name: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
title: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
id: </span>'2'<span style="color: rgba(0, 0, 0, 1)">,
key: </span>'2'<span style="color: rgba(0, 0, 0, 1)">,
children: [],
},
{
name: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
title: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
id: </span>'3'<span style="color: rgba(0, 0, 0, 1)">,
key: </span>'3'<span style="color: rgba(0, 0, 0, 1)">,
children: [
{
name: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
title: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
id: </span>'5'<span style="color: rgba(0, 0, 0, 1)">,
key: </span>'5'<span style="color: rgba(0, 0, 0, 1)">,
children: [],
},
{
name: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
title: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
id: </span>'6'<span style="color: rgba(0, 0, 0, 1)">,
key: </span>'6'<span style="color: rgba(0, 0, 0, 1)">,
children: [],
},
{
name: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
title: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
id: </span>'7'<span style="color: rgba(0, 0, 0, 1)">,
key: </span>'7'<span style="color: rgba(0, 0, 0, 1)">,
children: [],
},
],
},
{
name: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
title: </span>'员工'<span style="color: rgba(0, 0, 0, 1)">,
id: </span>'4'<span style="color: rgba(0, 0, 0, 1)">,
key: </span>'4'<span style="color: rgba(0, 0, 0, 1)">,
children: [],
},
],
};
class wnChart extends Component {
componentDidMount() {
const options </span>=<span style="color: rgba(0, 0, 0, 1)"> {
data: datascource, </span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 数据源</span>
depth: 20<span style="color: rgba(0, 0, 0, 1)">,
nodeContent: </span>'title'<span style="color: rgba(0, 0, 0, 1)">,
createNode: </span><span style="color: rgba(0, 0, 255, 1)">this</span>.addClick, <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 当渲染节点时添加点击事件</span>
toggleSiblingsResp: <span style="color: rgba(0, 0, 255, 1)">true</span>, <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 允许用户收缩展开兄弟节点</span>
visibleLevel: 3, <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 默认展开两级</span>
<span style="color: rgba(0, 0, 0, 1)"> };
$(</span><span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.orgTree).orgchart(options);
}
addClick </span>= ($node, data) =><span style="color: rgba(0, 0, 0, 1)"> {
$($node).click(() </span>=> <span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">.handleClick(data));
};
handleClick </span>= data =><span style="color: rgba(0, 0, 0, 1)"> {
console.log(data);
};
render() {
</span><span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> (
</span><PageHeaderWrapper title="组织架构">
<div ref={ref => (<span style="color: rgba(0, 0, 255, 1)">this</span>.orgTree = ref)} />
</PageHeaderWrapper>
<span style="color: rgba(0, 0, 0, 1)"> );
}
}
export </span><span style="color: rgba(0, 0, 255, 1)">default</span> wnChart;</pre>
</div>
<p>三、补充</p>
<p>data【json or String】:数据</p>
<p>pan 【boolean 默:flase】:通过鼠标拖放来控制OrgChart</p>
<p>zoom【boolean 默:false】:通过鼠标滚轮放大或缩放OrgChart</p>
<p>zoominLimit【number 默:7】:设置放大限制</p>
<p>zoomoutLimit【number 默:0.5】:设置缩放限制</p>
<p>direction【String 默:t2b】:T2B:"从上到下",B2T:"从底到上",L2R:"左到右",R2L:"向左到右"</p>
<p>verticalLevel【integer(>=2)】:</p>
<p>toggleSiblingsResp【boolean 默:false】:通过单击左/右箭头分别显示/隐藏左/右兄弟节点</p>
<p>ajaxURL【json】:不同的优先级提供了发送不同节点的Ajax请求的URL</p>
<p>visibleLevel【number】:默认展开几级</p>
<p>nodeId【String 默:id】:将数据源的一个属性设置为每个OrgChart节点的唯一标识符。</p>
<p>nodeTitle【String 默:name】:将数据源的一个属性设置为OrgChart节点标题段的文本内容</p>
<p>nodeContent【String】:将数据源的一个属性设置为OrgChart节点的内容部分的文本内容。</p>
<p>nodeTemplate【function】:它是一个模板生成函数,用于定制任何复杂的节点内部结构</p>
<p>createNode【function】:它是用于自定义每个OrgCad节点的回调函数</p>
<p>parentNodeSymbol【String 默:fa-users】:使用图标暗示该节点有子节点</p>
<p>exportButton【boolean 默:false】:是否启用OrgChar的导出按钮</p>
<p>exportFilename【String 默:OrgChart】:当输出当前的OrgChart作为图片时,它是文件名。</p>
<p>exportFileextension【String 默:png】:可用的值是PNG和PDF。</p>
<p>chartClass【String】:当你想在一个页面上实例化多个orgcharts 时,你应该添加不同的类名来区分它们。</p>
<p>draggable【boolean 默:false】:用户可以拖动和删除OrgChart节点</p>
<p>dropCriteria【function】:用户可以构造自己的标准来限制拖动节点和删除区域之间的关系</p>
<p>initCompleted【function】:经常知道您的表何时已经完全初始化、数据加载和呈现,尤其是当使用Ajax数据源时<br>--------------------- <br>参数来自:van久 【https://blog.csdn.net/qq_40594137/article/details/80910040】</p><br><br>
来源:https://www.cnblogs.com/nangras/p/10930479.html
頁:
[1]