chooseDataSourceBox.jsx 3.9 KB

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