chartView.jsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React from 'react'
  2. import Echarts from 'echarts-for-react'
  3. import { connect } from 'dva'
  4. import { Table } from 'antd'
  5. import resolveChartOption from '../chart/resolveChartOption.js'
  6. import RichTextEditor from './richTextEditor'
  7. const ChartView = ({ item, chart, editMode, dispatch }) => {
  8. const { viewType, chartCode, content } = item;
  9. let children = <div className='chart-default mover'></div>;
  10. console.log(editMode);
  11. if(viewType === 'chart') { // 图表类型
  12. let targetChart = chart.list.filter(c => c.code === chartCode)[0];
  13. if(targetChart) {
  14. let option = resolveChartOption(targetChart ? targetChart.chartOption : {}, editMode);
  15. let type = ['bar', 'line', 'pie', 'scatter'].indexOf(targetChart.type) !== -1 ? 'echarts' :
  16. (['aggregateTable', 'dataView'].indexOf(targetChart.type) !== -1 ? 'table' : 'default');
  17. if(type === 'echarts') {
  18. children = <Echarts
  19. key={chartCode}
  20. option={option}
  21. className='rc-echarts mover'
  22. style={{height: '100%'}}
  23. />
  24. }else if(type === 'table') {
  25. const { columns, data } = option;
  26. children = <Table className='mover' columns={columns} dataSource={data} pagination={false} />
  27. }
  28. }
  29. }else if(viewType === 'richText') { // 富文本类型
  30. children = <RichTextEditor content={content} onContentChange={(content) => {
  31. dispatch({ type: 'dashboardDesigner/modifyItem', fields: { code: item.code, content } });
  32. }}/>
  33. }else {
  34. children = <div className='mover'>错误类型</div>
  35. }
  36. return (
  37. <div className='chartview-content' style={{ width: '100%', height: '100%' }}>
  38. {children}
  39. </div>
  40. );
  41. }
  42. export default connect(({ present: { chart } }) => ({ chart }))(ChartView);