import React from 'react'
import { Form, Input, Button, Select, Table, Checkbox, Icon, Tooltip, Row } from 'antd'
import { connect } from 'dva'
import COLUMN_TYPE from './columnType.json'
import { Resizable } from 'react-resizable'
import './columnConfig.less'
const FormItem = Form.Item
const SelectOption = Select.Option
const ResizeableTitle = (props) => {
const { onResize, width, ...restProps } = props;
if (!width) {
return
| ;
}
return (
|
);
};
class DataSourceColumnConfig extends React.Component {
constructor(props) {
super(props);
this.state = {
widths: [ 80, 300, 200, 100, 100 ],
visibleConfirm: false,
}
}
components = {
header: {
cell: ResizeableTitle,
},
};
handleVisibleChange = (visible) => {
const { columns } = this.props.dataSourceDetail;
this.setState({ visibleConfirm: visible && (columns && columns.length > 0) });
}
handleResize = index => (e, { size }) => {
this.setState(({ widths }) => {
const nextWidths = [...widths];
nextWidths[index] = size.width;
return { widths: nextWidths };
});
};
render() {
const { dataSourceDetail, dispatch, fetching } = this.props;
const { widths } = this.state;
const columns = [{
title: 0 ? 'inline-block' : 'none') : 'none'}}
indeterminate={dataSourceDetail.columns ? (dataSourceDetail.columns.filter(c => c.using).length > 0 && dataSourceDetail.columns.filter(c => c.using).length < dataSourceDetail.columns.length) : false}
checked={dataSourceDetail.columns ? (dataSourceDetail.columns.filter(c => c.using).length === dataSourceDetail.columns.length) : false}
onChange={(e) => {
let target = e.target;
let columns = dataSourceDetail.columns ? dataSourceDetail.columns.map(c => {
c.using = target.checked;
return c;
}) : [];
dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
}}
/>启用
,
dataIndex: 'using',
key: 'using',
width: widths[0],
render: (v, r) => {
let target = e.target;
let key = target.dataKey;
let columns = dataSourceDetail.columns.map(c => {
if(c.key === key) {
c.using = target.checked;
}
return c;
});
dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
}}
checked={v}
/>
}, {
title: '列名',
dataIndex: 'name',
key: 'name',
width: widths[1],
// }, {
// title: '备注',
// dataIndex: 'description',
// key: 'description',
// width: widths[2],
// }, {
// title: '数据类型',
// dataIndex: 'dataType',
// key: 'dataType',
// width: widths[3]
}, {
title: '分析类型',
dataIndex: 'columnType',
key: 'columnType',
width: widths[2],
render: (text, record) => {
return (
)
}
}, {
title: 0 ? 'inline-block' : 'none') : 'none'}}
indeterminate={dataSourceDetail.columns ? (dataSourceDetail.columns.filter(c => c.groupable).length > 0 && dataSourceDetail.columns.filter(c => c.groupable).length < dataSourceDetail.columns.length) : false}
checked={dataSourceDetail.columns ? (dataSourceDetail.columns.filter(c => c.groupable).length === dataSourceDetail.columns.length) : false}
onChange={(e) => {
let target = e.target;
let columns = dataSourceDetail.columns ? dataSourceDetail.columns.map(c => {
c.groupable = target.checked;
return c;
}) : [];
dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
}}
/>允许分组
,
dataIndex: 'groupable',
key: 'groupable',
width: widths[3],
render: (v, r) => {
let target = e.target;
let key = target.dataKey;
let columns = dataSourceDetail.columns.map(c => {
if(c.key === key) {
c.groupable = target.checked;
}
return c;
});
dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
}}
checked={v}
/>
}, {
title: 0 ? 'inline-block' : 'none') : 'none'}}
indeterminate={dataSourceDetail.columns ? (dataSourceDetail.columns.filter(c => c.filterable).length > 0 && dataSourceDetail.columns.filter(c => c.filterable).length < dataSourceDetail.columns.length) : false}
checked={dataSourceDetail.columns ? (dataSourceDetail.columns.filter(c => c.filterable).length === dataSourceDetail.columns.length) : false}
onChange={(e) => {
let target = e.target;
let columns = dataSourceDetail.columns ? dataSourceDetail.columns.map(c => {
c.filterable = target.checked;
return c;
}) : [];
dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
}}
/>允许过滤
,
dataIndex: 'filterable',
key: 'filterable',
width: widths[4],
render: (v, r) => {
let target = e.target;
let key = target.dataKey;
let columns = dataSourceDetail.columns.map(c => {
if(c.key === key) {
c.filterable = target.checked;
}
return c;
});
dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
}}
checked={v}
/>
// }, {
// title: '允许分组',
// dataIndex: 'groupable',
// key: 'groupable',
// width: 50,
// className: 'column-groupable',
// render: (value, record) => {
// let columns = dataSourceDetail.columns.map(c => {
// if(c.key === record.key) {
// c.groupable = checked;
// }
// return c;
// });
// dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
// }}/>
// }, {
// title: '允许分段',
// dataIndex: 'bucketizable',
// key: 'bucketizable',
// width: 50,
// className: 'column-bucketizable',
// render: (value, record) => {
// let columns = dataSourceDetail.columns.map(c => {
// if(c.key === record.key) {
// c.bucketizable = checked;
// }
// return c;
// });
// dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
// }}
// />
}, {
title: '别名',
dataIndex: 'alias',
key: 'alias',
// width: widths[5],
render: (text, record) => {
return(
{
const value = e.target.value;
let columns = dataSourceDetail.columns.map(c => {
if(c.key === record.key) {
c['alias'] = value;
}
return c;
});
dispatch({ type: 'dataSourceDetail/setField', name: 'columns', value: columns });
}}
>
)
}
// }, {
// title: '允许过滤',
// dataIndex: 'filterable',
// key: 'filterable',
// render: (value, record) =>
}].map((col, index) => ({
...col,
onHeaderCell: column => ({
width: column.width,
onResize: this.handleResize(index),
}),
}));
return (
{
dataSourceDetail.type==='database'?(
数据列
):null
}
);
}
}
function mapStateToProps({ present: { dataSourceDetail, loading } }) {
const fetching = loading.effects['dataSourceDetail/importColumns'];
return {
fetching,
dataSourceDetail
}
}
export default connect(mapStateToProps)(DataSourceColumnConfig);