layout.jsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react'
  2. import { connect } from 'dva'
  3. import { Icon, Layout, Spin } from 'antd'
  4. import './layout.less'
  5. import html2canvas from 'html2canvas'
  6. import jsPDF from 'jspdf'
  7. import DashboardDesignerHeader from './header'
  8. import DashboardDesignerContent from './content'
  9. const { Header, Content } = Layout
  10. class DashboardDesigner extends React.Component {
  11. componentDidMount() {
  12. const { dispatch } = this.props;
  13. const { code } = this.props.match.params;
  14. dispatch({ type: 'dashboardDesigner/reset' });
  15. dispatch({ type: 'chart/fetchList' });
  16. if(code !== 'create') {
  17. dispatch({ type: 'dashboard/remoteDetail', code: code });
  18. }
  19. }
  20. saveToPNG = (element) => {
  21. html2canvas(element).then(function(canvas) {
  22. var pageData = canvas.toDataURL('image/png', 1.0);
  23. //方向默认竖直,尺寸ponits,格式a4[595.28,841.89]
  24. var pdf = new jsPDF('', 'pt', 'a4');
  25. //addImage后两个参数控制添加图片的尺寸,此处将页面高度按照a4纸宽高比列进行压缩
  26. pdf.addImage(pageData, 'PNG', 0, 0, 595.28, 592.28/canvas.width * canvas.height );
  27. pdf.save('stone.pdf');
  28. });
  29. }
  30. render() {
  31. const { loading } = this.props;
  32. return <Layout className='dashboarddesigner-layout'>
  33. <Header>
  34. <DashboardDesignerHeader />
  35. </Header>
  36. <Content style={{ height: 0 }}>
  37. <DashboardDesignerContent />
  38. </Content>
  39. <div style={{ display: loading ? 'block' : 'none', position: 'absolute', height: '100%', width: '100%', zIndex: '4', background: 'rgba(51,51,51,.1)' }}>
  40. <Spin style={{ display: 'inline-block', position: 'absolute', top: '50%', left: '50%', margin: '-10px' }} indicator={<Icon type="loading" style={{ fontSize: 24 }} spin />}/>
  41. </div>
  42. </Layout>
  43. }
  44. }
  45. export default connect()(DashboardDesigner)