import React, { Component } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; import TreeNode from './org_tree'; import './org_tree.less'; import StandardNode from './standard_node'; import SimpleNode from './simple_node'; //组件 class OrgTree extends Component { constructor(props) { super(props); this.handleExpand = this.handleExpand.bind(this); this.collapse = this.collapse.bind(this); this.toggleExpand = this.toggleExpand.bind(this); } componentDidMount() { const { expandAll, data } = this.props; if(expandAll) this.toggleExpand(data, true); } componentDidUpdate(prevProps, prevState) { if (prevProps.data !== this.props.data) { const { expandAll, data } = this.props; if(expandAll) this.toggleExpand(data, true); } } componentWillUnmount() { } handleExpand(e, nodeData) { if ('expand' in nodeData) { nodeData.expand = !nodeData.expand; if (!nodeData.expand && nodeData.children) { this.collapse(nodeData.children); } this.forceUpdate(); }else { nodeData.expand = true; this.forceUpdate(); } } collapse(list) { let _this = this; list.forEach(function(child) { if (child.expand) { child.expand = false; } child.children && _this.collapse(child.children); }); } toggleExpand(data, val) { let _this = this; if (Array.isArray(data)) { data.forEach(function(item) { item.expand = val; if (item.children) { _this.toggleExpand(item.children, val); } }); } else { data.expand = val; if (data.children) { _this.toggleExpand(data.children, val); } } this.forceUpdate(); } render() { const { horizontal, node, data, onClick } = this.props; return