layout.jsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React from 'react'
  2. import { connect } from 'dva'
  3. import { Icon, Layout, Spin } from 'antd'
  4. import './layout.less'
  5. import DashboardDesignerHeader from './header'
  6. import DashboardDesignerContent from './content'
  7. const { Header, Content } = Layout
  8. class DashboardDesigner extends React.Component {
  9. constructor(props) {
  10. super(props);
  11. props.dispatch({ type: 'dashboardDesigner/reset' });
  12. }
  13. componentDidMount() {
  14. const { code, dispatch, isShareView, isShareKeyView, afterLoad, config } = this.props;
  15. let url;
  16. if (code !== 'create') {
  17. url = isShareView ? 'dashboard/remoteShareDetail' : ( isShareKeyView ? 'dashboard/remoteShareKeyDetail' : 'dashboard/remoteDetail');
  18. }
  19. if(config) { // 首页打开的报表会保存报表配置,不需要后台再请求
  20. let fields = [];
  21. for(let key in config) {
  22. fields.push({
  23. name: key,
  24. value: config[key]
  25. })
  26. }
  27. dispatch({ type: 'dashboardDesigner/silentSetFields', fields: fields });
  28. }else {
  29. dispatch({ type: url, code: code }).then((data) => {
  30. if(afterLoad && typeof afterLoad === 'function') {
  31. afterLoad(data)
  32. }
  33. });
  34. }
  35. }
  36. isOwner = () => {
  37. const { dashboardDesigner, main } = this.props;
  38. const { creatorCode } = dashboardDesigner;
  39. const { currentUser } = main;
  40. return currentUser.code === creatorCode;
  41. }
  42. render() {
  43. const { dashboardDesigner, isShareView, isShareKeyView, isViewMode, afterRefresh } = this.props;
  44. const { loading } = dashboardDesigner;
  45. return <Layout className='dashboarddesigner-layout'>
  46. {!isShareView && !isShareKeyView && !isViewMode && <Header>
  47. <DashboardDesignerHeader updateThumbnail={this.updateThumbnail} />
  48. </Header>}
  49. <Content>
  50. <DashboardDesignerContent isOwner={this.isOwner()} isShareView={isShareView} isShareKeyView={isShareKeyView} isViewMode={isViewMode} afterRefresh={afterRefresh}/>
  51. </Content>
  52. <div style={{ display: loading ? 'block' : 'none', position: 'absolute', height: '100%', width: '100%', zIndex: '4', background: 'rgba(51,51,51,.1)' }}>
  53. <Spin style={{ display: 'inline-block', position: 'absolute', top: '50%', left: '50%', margin: '-10px' }} indicator={<Icon type="loading" style={{ fontSize: 24 }} spin />} />
  54. </div>
  55. </Layout>
  56. }
  57. }
  58. function mapStateToProps(state) {
  59. const { main } = state.present;
  60. return { main }
  61. }
  62. export default connect(mapStateToProps)(DashboardDesigner)