| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import React from 'react'
- import { Modal, Table, Radio, Tag, message } from 'antd'
- import { connect } from 'dva'
- import '../../models/dataSource'
- import './chooseDataSourceBox.less'
- class ChooseDataSourceBox extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- selectedRecord: null
- }
- }
- changeSelected = (record) => {
- this.setState({
- selectedRecord: Object.assign({}, record)
- });
- }
- okHandler = (model) => {
- const { selectedRecord } = this.state;
- const { dispatch, hideBox } = this.props;
- if(selectedRecord) {
- dispatch({ type: 'chartDesigner/remoteQucikAdd', dataSource: selectedRecord });
- hideBox();
- }else {
- message.warning('未选中数据源');
- }
- }
- render() {
- const { selectedRecord } = this.state;
- const { dataSource, visibleBox, hideBox } = this.props
- const columns = [{
- title: '选择',
- key: 'selected',
- width: 50,
- render: (text, record) => {
- return <Radio checked={selectedRecord ? selectedRecord.code === record.code : false}/>
- }
- }, {
- title: '名称',
- dataIndex: 'name',
- key: 'name',
- width: 100,
- render: (text, record) => {
- return <div className='datasource-name'>
- <div className={`datasource-type type-${record.type.key}`}></div>
- <div>{text}</div>
- </div>
- }
- }, {
- title: '标签',
- dataIndex: 'tags',
- key: 'tag',
- width: 150,
- render: (text, record) => {
- text=text.join(',');
- let tags = text ? text.split(',').map((t, i) => {
- return <Tag className='datasource-tag' key={i}>{t}</Tag>
- }) : '';
- return (<div>
- {tags}
- </div>)
- }
- }, {
- title: '说明',
- dataIndex: 'description',
- key: 'description',
- width: 200
- }, {
- title: '图表',
- dataIndex: 'chartSum',
- key: 'chartSum',
- width: 80
- }];
- return (
- <Modal
- className='choosedatasource-box'
- title='选择数据源'
- visible={visibleBox}
- onOk={this.okHandler}
- onCancel={hideBox}
- maskClosable={false}
- destroyOnClose={true}
- >
- <Table
- className='choosedatasource-table'
- columns={columns}
- dataSource={dataSource.list}
- size='small'
- scroll={{x: false, y: 471}}
- pagination={false}
- showHeader={false}
- onRow={(record) => {
- return {
- onClick: () => {
- this.changeSelected(record);
- }
- };
- }}
- />
- </Modal>
- )
- }
- }
- function mapStateToProps({ present: { dataSource } }) {
- return { dataSource: dataSource };
- }
- export default connect(mapStateToProps)(ChooseDataSourceBox)
|