| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- import React from 'react'
- import { Form, Input, Button, Select, Table, Checkbox, Switch, Divider } from 'antd'
- const FormItem = Form.Item
- const SelectOption = Select.Option
- import { connect } from 'dva'
- import '../../models/dataSource'
- import COLUMN_TYPE from './columnType.json'
- class DataSourceColumnConfig extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
-
- }
- }
- onCheckAllChange() {
- }
- render() {
- const { dataSource, dispatch } = this.props;
- const columns = [{
- title: <div><Checkbox
- style={{ margin: '0 8px 0 0', display: dataSource.newOne.columns ? (dataSource.newOne.columns.length > 0 ? 'inline-block' : 'none') : 'none'}}
- indeterminate={dataSource.newOne.columns ? (dataSource.newOne.columns.filter(c => c.using).length > 0 && dataSource.newOne.columns.filter(c => c.using).length < dataSource.newOne.columns.length) : false}
- checked={dataSource.newOne.columns ? (dataSource.newOne.columns.filter(c => c.using).length == dataSource.newOne.columns.length) : false}
- onChange={(e) => {
- let target = e.target;
- let columns = dataSource.newOne.columns ? dataSource.newOne.columns.map(c => {
- c.using = target.checked;
- return c;
- }) : [];
- dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
- }}
- />启用</div>,
- dataIndex: 'using',
- key: 'using',
- width: 50,
- render: (v, r) => <Checkbox
- dataKey={r.key}
- onChange={(e) => {
- let target = e.target;
- let key = target.dataKey;
- let columns = dataSource.newOne.columns.map(c => {
- if(c.key == key) {
- c.using = target.checked;
- }
- return c;
- });
- dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
- }}
- checked={v}
- />
- }, {
- title: '列名',
- dataIndex: 'name',
- key: 'name',
- width: 80
- }, {
- title: '别名',
- dataIndex: 'alias',
- key: 'alias',
- width: 100,
- render: (text, record) => {
- return(
- <Input
- value={text}
- onChange={(e) => {
- const value = e.target.value;
- let columns = dataSource.newOne.columns.map(c => {
- if(c.key == record.key) {
- c['alias'] = value;
- }
- return c;
- });
-
- dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
- }}
- >
- </Input>
- )
- }
- }, {
- title: '数据类型',
- dataIndex: 'dataType',
- key: 'dataType',
- width: 80
- }, {
- title: '分析类型',
- dataIndex: 'columnType',
- key: 'columnType',
- width: 80,
- render: (text, record) => {
- return (
- <Select
- style={{ width: '100%' }}
- value={text}
- onChange={(value) => {
- let columns = dataSource.newOne.columns.map(c => {
- if(c.key == record.key) {
- c.columnType = value;
- c.groupable = c.columnType == 'categorical';
- c.bucketizable = ['time', 'scale', 'ordinal'].indexOf(record.columnType) != -1;
- }
- return c;
- });
- dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
- }}
- >
- {
- COLUMN_TYPE.map( c => {
- let dataType = record.dataType;
- if(c.dataType.indexOf(dataType) != -1) {
- return <SelectOption value={c.columnType} key={c.columnType}>{c.label}</SelectOption>
- }else {
- return null
- }
-
- }).filter((s)=>s!=null)
- }
- </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: 'description',
- key: 'description',
- width: 200,
- render: (text, record) => {
- return <Input
- value={text}
- onChange={(e) => {
- let columns = dataSource.newOne.columns.map(c => {
- if(c.key == record.key) {
- c['description'] = e.target.value;
- }
- return c;
- });
-
- dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
- }}
- >
- </Input>
- }
- }];
- console.log(dataSource.newOne.type);
- return (
- <div>
- {
- dataSource.newOne.type=='database'?(
- <div>
- <Form size='small'>
- <Divider orientation="left">数据对象</Divider>
- <FormItem className='textarea-target'>
- <Input.TextArea
- placeholder='输入表名或查询SQL'
- autosize={{ minRows: 3 }}
- value={dataSource.newOne.target}
- onChange={(e) => {
- dispatch({ type: 'dataSource/setNewModelField', name: 'target', value: e.target.value });
- }}
- />
- </FormItem>
- <div className='buttons'>
- <Button onClick={() => {
- dispatch({ type: 'dataSource/importNewModelColumns' })
- }}>刷新</Button>
- </div>
- </Form>
- <Divider orientation="left">数据列</Divider>
- </div>
- ):null
- }
- <Table
- className='table-columnconfig'
- dataSource={dataSource.newOne.columns}
- columns={columns}
- locale={{
- emptyText: '未连接到数据对象'
- }}
- />
- </div>
- );
- }
- }
- function mapStateToProps({ present: { dataSource } }) {
- return { dataSource }
- }
- export default connect(mapStateToProps)(DataSourceColumnConfig);
|