baseConfig.jsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import React from 'react'
  2. import { Button, Table, Form, Row, Col, Input, InputNumber, Select, Icon, Menu, Dropdown, Divider, Upload, message } 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. const UploadDragger = Upload.Dragger
  11. import { connect } from 'dva'
  12. import DataConnectConfig from './dataConnectConfig'
  13. import '../../models/dataSource'
  14. import '../../models/dataConnect'
  15. const DataSourceBaseConfig = ({ dataSource, dataConnect, dispatch, mode }) => {
  16. const formItemLayout = {
  17. labelCol: { span: 4 },
  18. wrapperCol: { span: 20 },
  19. };
  20. const dataConnectColumns = [{
  21. title: '名称',
  22. dataIndex: 'name',
  23. key: 'name',
  24. width: 100,
  25. render: (text, record) => {
  26. return <div className='datasource-name'>
  27. <div className={`datasource-type type-${record.type}`}></div>
  28. <div>{text}</div>
  29. </div>
  30. }
  31. }, {
  32. title: '说明',
  33. dataIndex: 'description',
  34. key: 'description',
  35. width: 100
  36. }, {
  37. title: '操作',
  38. key: 'action',
  39. width: 300,
  40. render: (text, record) => (
  41. <div className='action-col'>
  42. <div className='operation' onClick={() => {
  43. let selectedModel = dataConnect.list.find((i) => { return i.code == record.code });
  44. dispatch({ type: 'dataConnect/setNewModel', model: selectedModel });
  45. this.showDataConnectBox('modify')
  46. }}><Icon type="info-circle-o"/>属性</div>
  47. <div className='operation'><Divider type="vertical" /></div>
  48. <div className='operation' onClick={() => {
  49. dispatch({ type: 'dataConnect/remoteDelete', code: record.code });
  50. }}><Icon type="delete"/>删除</div>
  51. </div>
  52. ),
  53. width: 80
  54. }];
  55. return (
  56. <Form className='form-base' size='small'>
  57. <Divider orientation="left">基本配置</Divider>
  58. <FormItem label='数据源名称' {...formItemLayout}>
  59. <Input
  60. value={dataSource.newOne.name}
  61. onChange={(e) => { dispatch({ type: 'dataSource/setNewModelField', name: 'name', value: e.target.value }) }}>
  62. </Input>
  63. </FormItem>
  64. {
  65. dataSource.newOne.type=='file'?(
  66. <div>
  67. <Divider orientation="left">文件</Divider>
  68. <div>此处显示文件名</div>
  69. </div>
  70. ):(
  71. <div>
  72. <Divider orientation="left">连接配置</Divider>
  73. <FormItem label='数据库类型' {...formItemLayout}>
  74. <Select
  75. value={dataSource.newOne.dbType}
  76. onChange={(value) => {
  77. dispatch({ type: 'dataSource/setNewModelField', name: 'dbType', value: value} );
  78. }}
  79. >
  80. <SelectOption value='oracle'>
  81. ORACLE
  82. </SelectOption>
  83. <SelectOption value='mysql'>
  84. MYSQL
  85. </SelectOption>
  86. <SelectOption value='sqlserver'>
  87. SQLSERVER
  88. </SelectOption>
  89. <SelectOption value='sqlite'>
  90. SQLITE
  91. </SelectOption>
  92. </Select>
  93. </FormItem>
  94. <Row>
  95. <Col span={19}>
  96. <FormItem label='数据库地址' {...{
  97. labelCol: { span: 5 },
  98. wrapperCol: { span: 19 }
  99. }}>
  100. <Input
  101. value={dataSource.newOne.address}
  102. onChange={(e) => {
  103. dispatch({ type: 'dataSource/setNewModelField', name: 'address', value: e.target.value });
  104. }}
  105. />
  106. </FormItem>
  107. </Col>
  108. <Col span={5}>
  109. <FormItem className='input-port' label='端口' {...{
  110. labelCol: { span: 12 },
  111. wrapperCol: { span: 12 }
  112. }}>
  113. <InputNumber
  114. value={dataSource.newOne.port}
  115. onChange={(value) => {
  116. dispatch({ type: 'dataSource/setNewModelField', name: 'port', value: value });
  117. }}
  118. />
  119. </FormItem>
  120. </Col>
  121. </Row>
  122. <FormItem label='数据库名' {...formItemLayout}>
  123. <Input
  124. value={dataSource.newOne.dbName}
  125. onChange={(e) => {
  126. dispatch({ type: 'dataSource/setNewModelField', name: 'dbName', value: e.target.value });
  127. }}
  128. />
  129. </FormItem>
  130. <Row>
  131. <Col span={12}>
  132. <FormItem label='用户名' {...{
  133. labelCol: { span: 8 },
  134. wrapperCol: { span: 16 }
  135. }}>
  136. <Input
  137. value={dataSource.newOne.userName}
  138. onChange={(e) => {
  139. dispatch({ type: 'dataSource/setNewModelField', name: 'userName', value: e.target.value });
  140. }}
  141. />
  142. </FormItem>
  143. </Col>
  144. <Col span={12}>
  145. <FormItem label='密码' {...{
  146. labelCol: { span: 8 },
  147. wrapperCol: { span: 16 }
  148. }}>
  149. <Input
  150. value={dataSource.newOne.password}
  151. onChange={(e) => {
  152. let value = e.target.value;
  153. dispatch({ type: 'dataSource/setNewModelField', name: 'password', value: value });
  154. e.target.removeAttribute('value')
  155. }}
  156. />
  157. </FormItem>
  158. </Col>
  159. </Row>
  160. </div>
  161. )
  162. }
  163. <Divider orientation="left">其他配置</Divider>
  164. <FormItem label='标签' {...formItemLayout}>
  165. <Select
  166. mode="tags"
  167. placeholder='多个标签使用逗号或空格分隔'
  168. tokenSeparators={[',', ' ']}
  169. value={dataSource.newOne.tags}
  170. dropdownStyle={{display: 'none'}}
  171. onChange={(value) => {
  172. dispatch({ type: 'dataSource/setNewModelField', name: 'tags', value: value });
  173. }}
  174. >
  175. </Select>
  176. </FormItem>
  177. <FormItem className='textarea-desc' label='说明' {...formItemLayout}>
  178. <Input.TextArea
  179. autosize={{ minRows: 2, maxRows: 5 }}
  180. value={dataSource.newOne.description}
  181. onChange={(e) => {
  182. dispatch({ type: 'dataSource/setNewModelField', name: 'description', value: e.target.value });
  183. }}
  184. />
  185. </FormItem>
  186. </Form>
  187. );
  188. }
  189. function mapStateToProps({ present: {dataSource, dataConnect} }) {
  190. return { dataSource, dataConnect }
  191. }
  192. export default connect(mapStateToProps)(DataSourceBaseConfig);