chartView.jsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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, contentSize } = 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. columns={chartOption.columns}
  45. dataSource={chartOption.dataSource}
  46. themeConfig={chartOption.themeConfig}
  47. styleConfig={(styleConfig || {}).dataView}
  48. pagination={{
  49. key: `${chartCode}-${layout.w}-${layout.h}-${hashcode(chartOption.page)}`,
  50. simple: contentSize.width * (layout.w/12) < 500,
  51. pageSize: chartOption.pageSize,
  52. total: chartOption.total,
  53. current: chartOption.page,
  54. showTotal: (total, range) => {
  55. return `第${range[0]}到第${range[1]}条数据,共${total}条数据`;
  56. },
  57. onChange: (page, pageSize) => {
  58. dispatch({ type: 'dashboardDesigner/fetchChartData', item, mandatory: true, page, pageSize });
  59. }
  60. }}
  61. onPageSizeChange={(page, pageSize) => {
  62. dispatch({ type: 'dashboardDesigner/fetchChartData', item, mandatory: true, page, pageSize });
  63. }}
  64. />);
  65. }else if(['line', 'bar', 'pie', 'scatter'].indexOf(chartType) > -1) {
  66. children = (<EchartsView item={item} inDashBoard={true} key={`${chartCode}-${layout.w}-${layout.h}`} chartOption={chartOption}/>);
  67. }else if(chartType === 'indicator') {
  68. children = (<IndicatorView key={`${chartCode}-${hashcode(chartOption)}-${layout.w}-${layout.h}`} chartOption={chartOption}/>);
  69. }
  70. }
  71. }else if(viewType === 'richText') { // 富文本类型
  72. children = <RichTextEditor readOnly={readOnly || !editMode} content={content} onContentChange={(content) => {
  73. !readOnly && dispatch({ type: 'dashboardDesigner/modifyItem', item: { ...item, content } });
  74. }}/>
  75. }else {
  76. children = <div className='mover'>错误类型</div>
  77. }
  78. return (
  79. <div className='chartview-content'>
  80. { children }
  81. <Loading visible={fetching} style={{ top: 0, left: 0, width: '100%', height: '100%' }}/>
  82. </div>
  83. );
  84. }
  85. }
  86. export default connect()(ChartView);