deleteBox.jsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react'
  2. import { Modal } from 'antd'
  3. /**
  4. * @class DeleteBox
  5. * @extends {React.Component}
  6. *
  7. */
  8. class DeleteBox extends React.Component {
  9. componentDidMount() {
  10. window.addEventListener('keydown', this.keydown);
  11. }
  12. componentWillUnmount() {
  13. window.removeEventListener('keydown', this.keydown);
  14. }
  15. keydown = (e) => {
  16. if(e.keyCode === 13) { // 按下回车
  17. this.onOk();
  18. }
  19. }
  20. onOk = () => {
  21. const { okHandler, hideBox } = this.props;
  22. typeof okHandler === 'function' && okHandler();
  23. typeof hideBox === 'function' && hideBox();
  24. }
  25. render() {
  26. const { visibleBox, hideBox, title, text } = this.props
  27. return (
  28. <Modal
  29. title={title || '删除确认'}
  30. visible={visibleBox}
  31. onCancel={hideBox}
  32. onOk={this.onOk}
  33. destroyOnClose={true}
  34. >
  35. <span>{text || '确定要删除该对象吗?'}</span>
  36. </Modal>
  37. )
  38. }
  39. }
  40. export default DeleteBox