|
|
@@ -2,26 +2,57 @@ import React from 'react'
|
|
|
import { Form, Input, Button, Select, Table, Checkbox, Switch, Divider, Icon, Popconfirm } from 'antd'
|
|
|
import { connect } from 'dva'
|
|
|
import COLUMN_TYPE from './columnType.json'
|
|
|
+import { Resizable } from 'react-resizable';
|
|
|
const FormItem = Form.Item
|
|
|
const SelectOption = Select.Option
|
|
|
|
|
|
+const ResizeableTitle = (props) => {
|
|
|
+ const { onResize, width, ...restProps } = props;
|
|
|
+
|
|
|
+ if (!width) {
|
|
|
+ return <th {...restProps} />;
|
|
|
+ }
|
|
|
+
|
|
|
+ return (
|
|
|
+ <Resizable width={width} height={0} onResize={onResize}>
|
|
|
+ <th {...restProps} />
|
|
|
+ </Resizable>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
class DataSourceColumnConfig extends React.Component {
|
|
|
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
this.state = {
|
|
|
+ widths: [ 50, 80, 150, 80, 80, 150 ],
|
|
|
visibleConfirm: false
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ components = {
|
|
|
+ header: {
|
|
|
+ cell: ResizeableTitle,
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
handleVisibleChange = (visible) => {
|
|
|
const { columns } = this.props.dataSource.newOne;
|
|
|
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 { dataSource, dispatch, loading } = this.props;
|
|
|
+ const { widths } = this.state;
|
|
|
|
|
|
const columns = [{
|
|
|
title: <div><Checkbox
|
|
|
@@ -40,7 +71,7 @@ class DataSourceColumnConfig extends React.Component {
|
|
|
/>启用</div>,
|
|
|
dataIndex: 'using',
|
|
|
key: 'using',
|
|
|
- width: 50,
|
|
|
+ width: widths[0],
|
|
|
render: (v, r) => <Checkbox
|
|
|
dataKey={r.key}
|
|
|
onChange={(e) => {
|
|
|
@@ -61,12 +92,12 @@ class DataSourceColumnConfig extends React.Component {
|
|
|
title: '列名',
|
|
|
dataIndex: 'name',
|
|
|
key: 'name',
|
|
|
- width: 80
|
|
|
+ width: widths[1],
|
|
|
}, {
|
|
|
title: '备注',
|
|
|
dataIndex: 'description',
|
|
|
key: 'description',
|
|
|
- width: 150,
|
|
|
+ width: widths[2],
|
|
|
render: (text, record) => {
|
|
|
return <Input
|
|
|
value={text}
|
|
|
@@ -87,12 +118,12 @@ class DataSourceColumnConfig extends React.Component {
|
|
|
title: '数据类型',
|
|
|
dataIndex: 'dataType',
|
|
|
key: 'dataType',
|
|
|
- width: 80
|
|
|
+ width: widths[3]
|
|
|
}, {
|
|
|
title: '分析类型',
|
|
|
dataIndex: 'columnType',
|
|
|
key: 'columnType',
|
|
|
- width: 80,
|
|
|
+ width: widths[4],
|
|
|
render: (text, record) => {
|
|
|
return (
|
|
|
<Select
|
|
|
@@ -124,46 +155,46 @@ class DataSourceColumnConfig extends React.Component {
|
|
|
</Select>
|
|
|
)
|
|
|
}
|
|
|
- }, {
|
|
|
- title: '允许分组',
|
|
|
- dataIndex: 'groupable',
|
|
|
- key: 'groupable',
|
|
|
- width: 50,
|
|
|
- className: 'column-groupable',
|
|
|
- render: (value, record) => <Switch disabled={record.columnType!=='categorical'} checked={value} onChange={(checked) => {
|
|
|
- let columns = dataSource.newOne.columns.map(c => {
|
|
|
- if(c.key === record.key) {
|
|
|
- c.groupable = checked;
|
|
|
- }
|
|
|
- return c;
|
|
|
- });
|
|
|
- dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
|
|
|
- }}/>
|
|
|
- }, {
|
|
|
- title: '允许分段',
|
|
|
- dataIndex: 'bucketizable',
|
|
|
- key: 'bucketizable',
|
|
|
- width: 50,
|
|
|
- className: 'column-bucketizable',
|
|
|
- render: (value, record) => <Switch
|
|
|
- disabled={['time', 'scale', 'ordinal'].indexOf(record.columnType)===-1}
|
|
|
- checked={value}
|
|
|
- defaultChecked={true}
|
|
|
- onChange={(checked) => {
|
|
|
- let columns = dataSource.newOne.columns.map(c => {
|
|
|
- if(c.key === record.key) {
|
|
|
- c.bucketizable = checked;
|
|
|
- }
|
|
|
- return c;
|
|
|
- });
|
|
|
- dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
|
|
|
- }}
|
|
|
- />
|
|
|
+ // }, {
|
|
|
+ // title: '允许分组',
|
|
|
+ // dataIndex: 'groupable',
|
|
|
+ // key: 'groupable',
|
|
|
+ // width: 50,
|
|
|
+ // className: 'column-groupable',
|
|
|
+ // render: (value, record) => <Switch disabled={record.columnType!=='categorical'} checked={value} onChange={(checked) => {
|
|
|
+ // let columns = dataSource.newOne.columns.map(c => {
|
|
|
+ // if(c.key === record.key) {
|
|
|
+ // c.groupable = checked;
|
|
|
+ // }
|
|
|
+ // return c;
|
|
|
+ // });
|
|
|
+ // dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
|
|
|
+ // }}/>
|
|
|
+ // }, {
|
|
|
+ // title: '允许分段',
|
|
|
+ // dataIndex: 'bucketizable',
|
|
|
+ // key: 'bucketizable',
|
|
|
+ // width: 50,
|
|
|
+ // className: 'column-bucketizable',
|
|
|
+ // render: (value, record) => <Switch
|
|
|
+ // disabled={['time', 'scale', 'ordinal'].indexOf(record.columnType)===-1}
|
|
|
+ // checked={value}
|
|
|
+ // defaultChecked={true}
|
|
|
+ // onChange={(checked) => {
|
|
|
+ // let columns = dataSource.newOne.columns.map(c => {
|
|
|
+ // if(c.key === record.key) {
|
|
|
+ // c.bucketizable = checked;
|
|
|
+ // }
|
|
|
+ // return c;
|
|
|
+ // });
|
|
|
+ // dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
|
|
|
+ // }}
|
|
|
+ // />
|
|
|
}, {
|
|
|
title: '别名',
|
|
|
dataIndex: 'alias',
|
|
|
key: 'alias',
|
|
|
- width: 150,
|
|
|
+ width: widths[5],
|
|
|
render: (text, record) => {
|
|
|
return(
|
|
|
<Input
|
|
|
@@ -183,7 +214,13 @@ class DataSourceColumnConfig extends React.Component {
|
|
|
</Input>
|
|
|
)
|
|
|
}
|
|
|
- }];
|
|
|
+ }].map((col, index) => ({
|
|
|
+ ...col,
|
|
|
+ onHeaderCell: column => ({
|
|
|
+ width: column.width,
|
|
|
+ onResize: this.handleResize(index),
|
|
|
+ }),
|
|
|
+ }));
|
|
|
|
|
|
return (
|
|
|
<div>
|
|
|
@@ -243,6 +280,8 @@ class DataSourceColumnConfig extends React.Component {
|
|
|
}
|
|
|
<Table
|
|
|
className='table-columnconfig'
|
|
|
+ bordered
|
|
|
+ components={this.components}
|
|
|
dataSource={dataSource.newOne.columns}
|
|
|
columns={columns}
|
|
|
locale={{
|