React实现组织架构图

React实现组织架构图

1.安装 @twp0217/react-org-chart
组件代码

import React from 'react';
import OrgChart, { OrgChartNodeDataType } from '@twp0217/react-org-chart';
 
export default () => {
  const data: OrgChartNodeDataType = require('./data.json');
 
  return <OrgChart data={data} expandable />;

2.数据代码 data.json

{
  "key": 0,
  "label": "科技有限公司",
  "children": [
    {
      "key": 1,
      "label": "研发部",
      "children": [
        { "key": 11, "label": "开发-前端" },
        { "key": 12, "label": "开发-后端" },
        { "key": 13, "label": "UI设计" },
        { "key": 14, "label": "产品经理" }
      ]
    },
    {
      "key": 2,
      "label": "销售部",
      "children": [
        { "key": 21, "label": "销售一部" },
        { "key": 22, "label": "销售二部" }
      ]
    },
    { "key": 3, "label": "财务部" },
    { "key": 4, "label": "人事部" }
  ]
}

效果展示
React实现组织架构图_第1张图片

你可能感兴趣的:(react.js,前端,javascript)