columnConfig.jsx 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import React from 'react'
  2. import { Modal, Form, Row, Col, Input, Button, Select, Icon, Menu, Dropdown, Table, Checkbox, Switch, Divider } 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 dataSource from '../../models/dataSource'
  12. class DataSourceColumnConfig extends React.Component {
  13. constructor(props) {
  14. super(props);
  15. this.state = {
  16. }
  17. }
  18. onCheckAllChange() {
  19. }
  20. render() {
  21. const { dataSource, dispatch } = this.props;
  22. const columns = [{
  23. title: <div><Checkbox
  24. style={{ margin: '0 8px 0 0', display: dataSource.newOne.columns ? (dataSource.newOne.columns.length > 0 ? 'inline-block' : 'none') : 'none'}}
  25. 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}
  26. checked={dataSource.newOne.columns ? (dataSource.newOne.columns.filter(c => c.using).length == dataSource.newOne.columns.length) : false}
  27. onChange={(e) => {
  28. let target = e.target;
  29. let columns = dataSource.newOne.columns ? dataSource.newOne.columns.map(c => {
  30. c.using = target.checked;
  31. return c;
  32. }) : [];
  33. dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
  34. }}
  35. />启用</div>,
  36. dataIndex: 'using',
  37. key: 'using',
  38. width: 50,
  39. render: (v, r) => <Checkbox
  40. dataKey={r.key}
  41. onChange={(e) => {
  42. let target = e.target;
  43. let key = target.dataKey;
  44. let columns = dataSource.newOne.columns.map(c => {
  45. if(c.key == key) {
  46. c.using = target.checked;
  47. }
  48. return c;
  49. });
  50. dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
  51. }}
  52. checked={v}
  53. />
  54. }, {
  55. title: '列名',
  56. dataIndex: 'name',
  57. key: 'name',
  58. width: 80
  59. }, {
  60. title: '别名',
  61. dataIndex: 'alias',
  62. key: 'alias',
  63. width: 100,
  64. render: (text, record) => {
  65. return(
  66. <Input
  67. value={text}
  68. onChange={(e) => {
  69. const value = e.target.value;
  70. let columns = dataSource.newOne.columns.map(c => {
  71. if(c.key == record.key) {
  72. c['alias'] = value;
  73. }
  74. return c;
  75. });
  76. dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
  77. }}
  78. >
  79. </Input>
  80. )
  81. }
  82. }, {
  83. title: '数据类型',
  84. dataIndex: 'dataType',
  85. key: 'dataType',
  86. width: 80
  87. }, {
  88. title: '分析类型',
  89. dataIndex: 'columnType',
  90. key: 'columnType',
  91. width: 80,
  92. render: (text, record) => {
  93. return (
  94. <Select
  95. style={{ width: '100%' }}
  96. value={text}
  97. onChange={(value) => {
  98. let columns = dataSource.newOne.columns.map(c => {
  99. if(c.key == record.key) {
  100. c.columnType = value;
  101. c.groupable = c.columnType == 'categorical';
  102. c.bucketizable = ['time', 'scale', 'ordinal'].indexOf(record.columnType) != -1;
  103. }
  104. return c;
  105. });
  106. dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
  107. }}
  108. >
  109. {
  110. [
  111. <SelectOption value='index' key='index'>索引</SelectOption>,
  112. <SelectOption value='time' key='time'>时间</SelectOption>,
  113. <SelectOption value='categorical' key='categorical'>类别</SelectOption>,
  114. <SelectOption value='scale' key='scale'>标量</SelectOption>,
  115. <SelectOption value='ordinal' key='ordinal'>序值</SelectOption>,
  116. <SelectOption value='string' key='string'>字符串</SelectOption>
  117. ].map((s, i) => {
  118. if(record.dataType=='VARCHAR2' && [0,2,5].indexOf(i) != -1) {
  119. return s;
  120. }else if(record.dataType=='DATE' && [1].indexOf(i) != -1) {
  121. return s;
  122. }else if(record.dataType=='NUMBER' && [0,2,3,4,5].indexOf(i) != -1) {
  123. return s;
  124. }else {
  125. return null
  126. }
  127. }).filter((s)=>s!=null)
  128. }
  129. </Select>
  130. )
  131. }
  132. }, {
  133. title: '允许分组',
  134. dataIndex: 'groupable',
  135. key: 'groupable',
  136. width: 50,
  137. className: 'column-groupable',
  138. render: (value, record) => <Switch disabled={record.columnType!='categorical'} checked={value} onChange={(checked) => {
  139. let columns = dataSource.newOne.columns.map(c => {
  140. if(c.key == record.key) {
  141. c.groupable = checked;
  142. }
  143. return c;
  144. });
  145. dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
  146. }}/>
  147. }, {
  148. title: '允许分段',
  149. dataIndex: 'bucketizable',
  150. key: 'bucketizable',
  151. width: 50,
  152. className: 'column-bucketizable',
  153. render: (value, record) => <Switch
  154. disabled={['time', 'scale', 'ordinal'].indexOf(record.columnType)==-1}
  155. checked={value}
  156. defaultChecked={true}
  157. onChange={(checked) => {
  158. let columns = dataSource.newOne.columns.map(c => {
  159. if(c.key == record.key) {
  160. c.bucketizable = checked;
  161. }
  162. return c;
  163. });
  164. dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
  165. }}
  166. />
  167. }, {
  168. title: '备注',
  169. dataIndex: 'description',
  170. key: 'description',
  171. width: 200,
  172. render: (text, record) => {
  173. return <Input
  174. value={text}
  175. onChange={(e) => {
  176. let columns = dataSource.newOne.columns.map(c => {
  177. if(c.key == record.key) {
  178. c['description'] = e.target.value;
  179. }
  180. return c;
  181. });
  182. dispatch({ type: 'dataSource/setNewModelField', name: 'columns', value: columns });
  183. }}
  184. >
  185. </Input>
  186. }
  187. }];
  188. console.log(dataSource.newOne.type);
  189. return (
  190. <div>
  191. {
  192. dataSource.newOne.type=='database'?(
  193. <div>
  194. <Form size='small'>
  195. <Divider orientation="left">数据对象</Divider>
  196. <FormItem className='textarea-target'>
  197. <Input.TextArea
  198. placeholder='输入表名或查询SQL'
  199. autosize={{ minRows: 3 }}
  200. value={dataSource.newOne.target}
  201. onChange={(e) => {
  202. dispatch({ type: 'dataSource/setNewModelField', name: 'target', value: e.target.value });
  203. }}
  204. />
  205. </FormItem>
  206. <div className='buttons'>
  207. <Button onClick={() => {
  208. dispatch({ type: 'dataSource/importNewModelColumns' })
  209. }}>刷新</Button>
  210. </div>
  211. </Form>
  212. <Divider orientation="left">数据列</Divider>
  213. </div>
  214. ):null
  215. }
  216. <Table
  217. className='table-columnconfig'
  218. dataSource={dataSource.newOne.columns}
  219. columns={columns}
  220. locale={{
  221. emptyText: '未连接到数据对象'
  222. }}
  223. />
  224. </div>
  225. );
  226. }
  227. }
  228. function mapStateToProps({ present: { dataSource } }) {
  229. return { dataSource }
  230. }
  231. export default connect(mapStateToProps)(DataSourceColumnConfig);