headerCreate.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import React from 'react'
  2. import { Button, Popconfirm } from 'antd'
  3. import { connect } from 'dva'
  4. import './headerCreate.less'
  5. class DataSourceCreateHeader extends React.Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. visibleConfirm: false,
  10. }
  11. }
  12. handleVisibleChange = (visible) => {
  13. this.setState({ visibleConfirm: visible });
  14. }
  15. render() {
  16. const { dataSourceDetail, dispatch } = this.props;
  17. const { visibleConfirm } = this.state;
  18. return (
  19. <div className='header-datasource-create'>
  20. <div className='title'>
  21. <span>创建数据源</span>
  22. </div>
  23. <div>
  24. <Popconfirm
  25. placement="bottomLeft"
  26. title="确定不保存直接退出吗?"
  27. visible={visibleConfirm}
  28. onVisibleChange={this.handleVisibleChange}
  29. onConfirm={() => {
  30. dispatch({ type: 'main/redirect', path: '/workshop/datasource' });
  31. this.setState({
  32. visibleConfirm: false
  33. });
  34. }}
  35. onCancel={() => {
  36. this.setState({
  37. visibleConfirm: false
  38. });
  39. }}
  40. okText="确定"
  41. cancelText="取消"
  42. >
  43. <Button onClick={(e) => {
  44. if(!dataSourceDetail.dirty) {
  45. dispatch({ type: 'main/redirect', path: '/workshop/datasource' });
  46. }
  47. }}>
  48. 取消
  49. </Button>
  50. </Popconfirm>
  51. </div>
  52. </div>
  53. );
  54. }
  55. }
  56. export default connect(({ present: { dataSourceDetail } }) => ({ dataSourceDetail }))(DataSourceCreateHeader);