forked from nsjcy/frontEnd/nsjcy

1
liuwh
2020-05-26 aba05ff402b2b6a7ed9e3eedee43addc1b7eee44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
import { Layout } from 'antd';
 
import TreeMenu from '../view/TreeMenu';
const { Sider } = Layout;
import Fetch from '../fetch';
export default class Menu extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      collapsed: false,
      data: [],
      path: ''
    }
  }
  componentDidMount() {
    document.title = '业务所有材料';
    const { busId, attachmentId } = this.props.match.params;
    Fetch.getAttachmentTree(busId, attachmentId)
      .then(({ data, item }) => {
        this.setState({ data });
        this.openImage(item);
      });
  }
 
  onCollapse = collapsed => {
    this.setState({ collapsed });
  }
 
  openImage({ path, type, name }) {
    const { busId } = this.props.match.params;
    const index = path.lastIndexOf('/');
    this.props.history.replace({
      pathname: `/bus/attachment/${busId}${path.substr(index)}`,
      state: {
        path, type, name
      }
    });
    this.setState({ path });
  }
 
  onClick = ({ type, path }) => {
    this.openImage({ path, type });
  }
 
  render() {
    const { collapsed, data, path } = this.state;
    return (
      <Sider key={this.props.match.params.busId} onCollapse={this.onCollapse}
        collapsed={collapsed}
        className="sider-light"
        breakpoint="lg"
        collapsible>
        {
          data.length > 0 && <TreeMenu onClick={this.onClick} data={data} defaultOpenKeys={data.map(e => e.name)}
            defaultSelectedKeys={[path]}
          />
        }
      </Sider>
    )
  }
}