org-chart-frant/src/components/timeline/index.jsx

110 lines
2.7 KiB
React
Raw Normal View History

2023-06-25 18:30:37 +08:00
/*
* @Author: Chengliang 1546584672@qq.com
* @Date: 2023-06-25 16:33:21
* @LastEditors: Chengliang 1546584672@qq.com
2023-09-14 18:23:08 +08:00
* @LastEditTime: 2023-09-14 17:48:39
2023-06-25 18:30:37 +08:00
* @FilePath: /org-chart-frant/src/components/timeline/index.jsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import React from 'react';
2023-09-14 18:23:08 +08:00
import { Timeline, Drawer } from 'antd';
2023-06-25 18:30:37 +08:00
import styles from './index.less';
2023-09-14 18:23:08 +08:00
import leftTreeShow from './img/leftTree-show.png';
import leftHide from './img/leftTree-hide.png';
2023-06-25 18:30:37 +08:00
export default class TimeLine extends React.Component {
constructor(props) {
super(props);
this.state = {
timelineList: [],
2023-09-14 18:23:08 +08:00
open: true,
2023-06-25 18:30:37 +08:00
};
}
2023-06-27 14:12:42 +08:00
handleLineClick(data) {
let newList = this.state.timelineList.map((item) => {
item.color = 'grey';
if (item.key == data.key) {
item.color = 'blue';
}
return item;
});
this.setState({
timelineList: newList,
});
this.props.onClick(data);
2023-06-25 18:30:37 +08:00
}
componentDidMount() {
2023-06-30 16:39:00 +08:00
this.searchTimeLines(this.props.url);
}
searchTimeLines(url) {
fetch(url)
.then((res) => res.json())
.then((data) => {
this.setState({
timelineList: data.timelineList,
});
});
2023-06-25 18:30:37 +08:00
}
2023-09-14 18:23:08 +08:00
setOpen = () => {
this.setState({
open: !this.state.open,
});
};
2023-06-25 18:30:37 +08:00
render() {
2023-09-14 18:23:08 +08:00
let showStyle = {};
let positionStyle = {};
if (this.state.open) {
showStyle = {
display: 'block',
};
positionStyle = {
left: '219px',
background: `url(${leftTreeShow}) no-repeat -2px 0`,
};
} else {
showStyle = {
display: 'none',
};
positionStyle = {
left: '0',
background: `url(${leftHide}) no-repeat -2px 0`,
};
}
2023-06-25 18:30:37 +08:00
return (
2023-09-14 18:23:08 +08:00
<>
<div
className={styles.leftRightLayoutBtn}
style={positionStyle}
onClick={this.setOpen}
></div>
<div className={styles.lineWrapper} style={showStyle}>
<Timeline>
{this.state.timelineList.map((item) => {
return (
<Timeline.Item
key={item.key}
onClick={this.handleLineClick.bind(this, item)}
className={styles.timeline}
color={item.color}
style={{
color: item.color == 'blue' ? '#1890ff' : 'dimgray',
}}
>
<div>{item.title}</div>
<div className={styles.time}>{item.time}</div>
</Timeline.Item>
);
})}
</Timeline>
</div>
</>
2023-06-25 18:30:37 +08:00
);
}
}