chartView.jsx 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import React from 'react'
  2. import AggregateTableView from '../chartDesigner/charts/aggregateTableView'
  3. import TableView from '../chartDesigner/charts/tableView'
  4. import EchartsView from '../chartDesigner/charts/echartsView'
  5. import IndicatorView from '../chartDesigner/charts/indicatorView'
  6. import RichTextEditor from './richTextEditor'
  7. import { connect } from 'dva'
  8. import { hashcode } from '../../utils/baseUtils'
  9. import EmptyContent from '../common/emptyContent/index'
  10. import Loading from '../common/loading/index'
  11. class ChartView extends React.Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. tableScrollHeight: 0,
  16. layout: { ...props.item.layout },
  17. chartOption: {
  18. showLoading: true
  19. }, // 图表详细数据
  20. }
  21. }
  22. componentDidMount() {
  23. const { item, dispatch, reload, minLayoutHeight } = this.props;
  24. const { viewType, chartType, layout } = item;
  25. let page = 1;
  26. let pageSize = ~~((layout.h * minLayoutHeight + (layout.h - 1) * 12 - 20 - 40 - 24 - 8 * 2)/38) + 1;
  27. if(viewType === 'chart' && chartType !== 'dataView') {
  28. dispatch({ type: 'dashboardDesigner/fetchChartData', item, mandatory: reload, page, pageSize });
  29. }
  30. }
  31. render() {
  32. const { item, editMode, dispatch, readOnly, chartRef } = this.props;
  33. // const { tableScrollHeight } = this.state;
  34. const { chartCode, viewType, chartType, content, chartOption, styleConfig, fetching, layout } = item;
  35. let children = <EmptyContent/>;
  36. if(viewType === 'chart') { // 图表类型
  37. if(chartOption) {
  38. if(chartType === 'aggregateTable') {
  39. children = (<AggregateTableView chartOption={chartOption}/>);
  40. }else if(chartType === 'dataView') {
  41. children = (<TableView
  42. key={`${chartCode}-${layout.h}-${hashcode(chartOption.page)}`} // 这个KEY的变化才会正确引起页面的刷新
  43. chartOption={chartOption}
  44. viewRef={`${chartRef}-tableview`}
  45. columns={chartOption.columns}
  46. dataSource={chartOption.dataSource}
  47. styleConfig={(styleConfig || {}).dataView}
  48. pagination={{
  49. pageSize: chartOption.pageSize,
  50. total: chartOption.total,
  51. current: chartOption.page,
  52. showTotal: (total, range) => {
  53. return `第${range[0]}到第${range[1]}条数据,共${total}条数据`;
  54. },
  55. onChange: (page, pageSize) => {
  56. dispatch({ type: 'dashboardDesigner/fetchChartData', item, mandatory: true, page, pageSize });
  57. }
  58. }}
  59. onPageSizeChange={(page, pageSize) => {
  60. dispatch({ type: 'dashboardDesigner/fetchChartData', item, mandatory: true, page, pageSize });
  61. }}
  62. />);
  63. }else if(['line', 'bar', 'pie', 'scatter'].indexOf(chartType) > -1) {
  64. children = (<EchartsView key={`${chartCode}-${layout.w}-${layout.h}`} chartOption={chartOption}/>);
  65. }else if(chartType === 'indicator') {
  66. children = (<IndicatorView key={`${chartCode}-${layout.w}-${layout.h}`} chartOption={chartOption}/>);
  67. }
  68. }
  69. }else if(viewType === 'richText') { // 富文本类型
  70. children = <RichTextEditor readOnly={readOnly || !editMode} content={content} onContentChange={(content) => {
  71. !readOnly && dispatch({ type: 'dashboardDesigner/modifyItem', item: { ...item, content } });
  72. }}/>
  73. }else {
  74. children = <div className='mover'>错误类型</div>
  75. }
  76. return (
  77. <div ref={node => this[chartRef] = node } className='chartview-content'>
  78. { children }
  79. <Loading visible={fetching} style={{ top: 0, left: 0, width: '100%', height: '100%' }}/>
  80. </div>
  81. );
  82. }
  83. }
  84. export default connect()(ChartView);