header.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import React from 'react'
  2. import { Input, Icon, Button, Popconfirm } from 'antd'
  3. import { connect } from 'dva'
  4. import './header.less'
  5. class Header 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 { dashboardDesigner, dispatch, updateThumbnail } = this.props;
  17. return (
  18. <div className='dashboarddesigner-header'>
  19. <div className='header-item toolbar-back'>
  20. <Popconfirm
  21. placement="bottomLeft"
  22. title="离开前保存修改吗?"
  23. visible={this.state.visibleConfirm}
  24. onVisibleChange={this.handleVisibleChange}
  25. onConfirm={() => {
  26. this.setState({
  27. visibleConfirm: false
  28. });
  29. updateThumbnail()// 添加更新thumbnail
  30. dispatch({ type: 'dashboard/remoteModify' });
  31. dispatch({ type: 'main/redirect', path: '/dashboard' });
  32. }}
  33. onCancel={() => {
  34. this.setState({
  35. visibleConfirm: false
  36. });
  37. dispatch({ type: 'main/redirect', path: '/dashboard' });
  38. }}
  39. okText="保存"
  40. cancelText="不保存"
  41. >
  42. <Button onClick={() => {
  43. console.log(dashboardDesigner.dirty);
  44. if(!dashboardDesigner.dirty) {
  45. dispatch({ type: 'main/redirect', path: '/dashboard' });
  46. }
  47. }}>
  48. <Icon type='left' />返回
  49. </Button>
  50. </Popconfirm>
  51. <Button onClick={() => {
  52. if(dashboardDesigner.code && dashboardDesigner.code !== -1) {
  53. updateThumbnail()// 添加更新thumbnail
  54. dispatch({ type: 'dashboard/remoteModify' });
  55. }else {
  56. updateThumbnail()// 添加更新thumbnail
  57. dispatch({ type: 'dashboard/remoteAdd' });
  58. }
  59. }}><Icon type='save' />保存</Button>
  60. <Button onClick={updateThumbnail}
  61. ><Icon type='save' />保存Thumbnail(Debug用)</Button>
  62. </div>
  63. <div className='header-item toolbar-title'>
  64. <Input
  65. className='input-title'
  66. value={dashboardDesigner.title}
  67. addonAfter={<Icon type="edit"
  68. onClick={(e) => {
  69. const input = e.currentTarget.parentElement.parentElement.getElementsByTagName('input')[0];
  70. input && input.focus()
  71. }}
  72. />}
  73. onChange={(e) => {
  74. dispatch({ type: 'dashboardDesigner/setField', name: 'title', value: e.target.value });
  75. }}
  76. />
  77. </div>
  78. <div className='header-item toolbar-buttons'>
  79. </div>
  80. </div>
  81. );
  82. }
  83. }
  84. function mapStateToProps(state) {
  85. const dashboardDesigner = state.present.dashboardDesigner;
  86. return { dashboardDesigner }
  87. }
  88. export default connect(mapStateToProps)(Header);