chooseDataSourceBox.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React from 'react'
  2. import { Modal, Table, Radio, Tag, message } from 'antd'
  3. import { connect } from 'dva'
  4. import '../../models/dataSource'
  5. import './chooseDataSourceBox.less'
  6. class ChooseDataSourceBox extends React.Component {
  7. constructor(props) {
  8. super(props);
  9. this.state = {
  10. selectedRecord: null
  11. }
  12. }
  13. changeSelected = (record) => {
  14. this.setState({
  15. selectedRecord: Object.assign({}, record)
  16. });
  17. }
  18. okHandler = (model) => {
  19. const { selectedRecord } = this.state;
  20. const { dispatch, hideBox } = this.props;
  21. if(selectedRecord) {
  22. dispatch({ type: 'chartDesigner/remoteQucikAdd', dataSource: selectedRecord });
  23. hideBox();
  24. }else {
  25. message.warning('未选中数据源');
  26. }
  27. }
  28. render() {
  29. const { selectedRecord } = this.state;
  30. const { dataSource, visibleBox, hideBox } = this.props
  31. const columns = [{
  32. title: '选择',
  33. key: 'selected',
  34. width: 50,
  35. render: (text, record) => {
  36. return <Radio checked={selectedRecord ? selectedRecord.code === record.code : false}/>
  37. }
  38. }, {
  39. title: '名称',
  40. dataIndex: 'name',
  41. key: 'name',
  42. width: 100,
  43. render: (text, record) => {
  44. return <div className='datasource-name'>
  45. <div className={`datasource-type type-${record.type.key}`}></div>
  46. <div>{text}</div>
  47. </div>
  48. }
  49. }, {
  50. title: '标签',
  51. dataIndex: 'tags',
  52. key: 'tag',
  53. width: 150,
  54. render: (text, record) => {
  55. text=text.join(',');
  56. let tags = text ? text.split(',').map((t, i) => {
  57. return <Tag className='datasource-tag' key={i}>{t}</Tag>
  58. }) : '';
  59. return (<div>
  60. {tags}
  61. </div>)
  62. }
  63. }, {
  64. title: '说明',
  65. dataIndex: 'description',
  66. key: 'description',
  67. width: 200
  68. }, {
  69. title: '图表',
  70. dataIndex: 'chartSum',
  71. key: 'chartSum',
  72. width: 80
  73. }];
  74. return (
  75. <Modal
  76. className='choosedatasource-box'
  77. title='选择数据源'
  78. visible={visibleBox}
  79. onOk={this.okHandler}
  80. onCancel={hideBox}
  81. maskClosable={false}
  82. destroyOnClose={true}
  83. >
  84. <Table
  85. className='choosedatasource-table'
  86. columns={columns}
  87. dataSource={dataSource.list}
  88. size='small'
  89. scroll={{x: false, y: 471}}
  90. pagination={false}
  91. showHeader={false}
  92. onRow={(record) => {
  93. return {
  94. onClick: () => {
  95. this.changeSelected(record);
  96. }
  97. };
  98. }}
  99. />
  100. </Modal>
  101. )
  102. }
  103. }
  104. function mapStateToProps({ present: { dataSource } }) {
  105. return { dataSource: dataSource };
  106. }
  107. export default connect(mapStateToProps)(ChooseDataSourceBox)