toolbar.jsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import React from 'react'
  2. import { Icon, Modal } from 'antd'
  3. import { connect } from 'dva'
  4. import DashboardDesigner from '../dashboardDesigner/layout'
  5. import CusIcon from '../common/cusIcon/index'
  6. import './toolbar.less'
  7. class Toolbar extends React.Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. visibleFullscreenBox: false,
  12. }
  13. }
  14. // 全屏展示
  15. fullscreen = () => {
  16. this.setState({
  17. visibleFullscreenBox: true,
  18. });
  19. }
  20. // 刷新
  21. refresh = () => {
  22. this.props.dispatch({ type: 'dashboardDesigner/refresh' });
  23. }
  24. // 收藏
  25. collect = () => {
  26. const { dispatch, home } = this.props;
  27. const { selectedTab } = home;
  28. dispatch({ type: 'home/collect', data: selectedTab });
  29. }
  30. // 取消收藏
  31. uncollect = () => {
  32. const { dispatch, home } = this.props;
  33. const { selectedTab } = home;
  34. dispatch({ type: 'home/uncollect', data: selectedTab });
  35. }
  36. onFixed = (code) => {
  37. const { dispatch, home } = this.props;
  38. const { selectedTab } = home;
  39. dispatch({ type: 'home/onFixedDashboard', tab: selectedTab });
  40. }
  41. onCancelFixed = (code) => {
  42. const { dispatch, home } = this.props;
  43. const { selectedTab } = home;
  44. dispatch({ type: 'home/onCancelFixedDashboard', tab: selectedTab });
  45. }
  46. afterRefresh = () => {
  47. const { dispatch, home } = this.props;
  48. dispatch({ type: 'home/saveCurrentTabDashboardConfig', code: home.selectedTab.code });
  49. }
  50. exportToExcel = () => {
  51. const { dispatch } = this.props;
  52. dispatch({ type: 'dashboardDesigner/exportToExcel' });
  53. }
  54. render() {
  55. const { home } = this.props;
  56. const { tabs, selectedTab, collectionDashboards, fixedDashboard } = home;
  57. let { config } = tabs.find(t => t.code === selectedTab.code);
  58. return <div className='dashboardview-toolbar'>
  59. <div className='toos'>
  60. <div className='tool'><span onClick={this.fullscreen}><Icon title="全屏" type="fullscreen" /></span></div>
  61. <div className='tool'><span onClick={this.refresh}><Icon title="刷新" type="sync" /></span></div>
  62. <div className='tool'>{
  63. collectionDashboards.findIndex(c => c.code === selectedTab.code) > -1 ?
  64. <span onClick={this.uncollect}><Icon title="取消收藏" type="star" theme="filled" /></span> :
  65. <span onClick={this.collect}><Icon title="收藏" type="star" /></span>
  66. }</div>
  67. <div className='tool'>{
  68. (!!fixedDashboard && fixedDashboard.code === selectedTab.code) ?
  69. <span onClick={this.onCancelFixed}><CusIcon title="取消固定到首页" type="bi-fixed" /></span> :
  70. <span onClick={this.onFixed}><CusIcon title="固定到首页" type="bi-no-fixed" /></span>
  71. }</div>
  72. <div className='tool'><span onClick={this.exportToExcel}><CusIcon title="导出Excel" type="bi-export-excel" /></span></div>
  73. </div>
  74. {/** 全屏展示modal */}
  75. {this.state.visibleFullscreenBox && <Modal
  76. className='modal-full'
  77. width='100%'
  78. height='100%'
  79. visible={this.state.visibleFullscreenBox}
  80. footer={null}
  81. onCancel={() => {
  82. this.setState({
  83. visibleFullscreenBox: false
  84. })
  85. }}
  86. >
  87. <DashboardDesigner
  88. dashboardDesigner={this.props.dashboardDesigner}
  89. code={selectedTab.code}
  90. isViewMode
  91. afterLoad={null}
  92. afterRefresh={this.afterRefresh}
  93. config={config}
  94. />
  95. </Modal>}
  96. </div>
  97. }
  98. }
  99. export default connect(({ present: { dashboardDesigner, home } }) => ({ dashboardDesigner, home }))(Toolbar)