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>
|
)
|
}
|
}
|