baseConfig.jsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. import React from 'react'
  2. import { Form, Row, Col, Input, InputNumber, Select, Divider, Cascader } from 'antd'
  3. import { connect } from 'dva'
  4. const FormItem = Form.Item
  5. const SelectOption = Select.Option
  6. class DataSourceBaseConfig extends React.Component {
  7. generateOptions () {
  8. const { dataConnect } = this.props;
  9. const { list } = dataConnect;
  10. return list.map((l) => {
  11. return <SelectOption value={l.code} key={l.code}>
  12. { l.name }
  13. </SelectOption>
  14. });
  15. }
  16. componentDidMount() {
  17. const { dispatch } = this.props;
  18. dispatch({ type: 'dataSource/remoteGroupList' });
  19. dispatch({ type: 'dataConnect/fetchList' });
  20. }
  21. render() {
  22. const { dataConnect, dataSource, dataSourceDetail, dispatch } = this.props;
  23. const formItemLayout = {
  24. labelCol: { span: 4 },
  25. wrapperCol: { span: 20 },
  26. };
  27. let getGroup = () => {
  28. const { groupList } = dataSource;
  29. const { group } = dataSourceDetail;
  30. let g1 = groupList.filter(g => g.code+'' === group+'')[0];
  31. if(!g1) {
  32. return ['-1']
  33. }
  34. if(g1.pcode === '-1') {
  35. return [g1.code]
  36. }else {
  37. let g2 = groupList.filter(g => g.code+'' === g1.pcode+'')[0];
  38. return [g2.code, g1.code]
  39. }
  40. }
  41. return (
  42. <Form className='form-base' size='small'>
  43. <Divider orientation="left">基本配置</Divider>
  44. <FormItem label='数据源名称' {...formItemLayout}>
  45. <Input
  46. value={dataSourceDetail.name}
  47. onBlur={(e) => {
  48. // dispatch({ type: 'dataSourceDetail/setField', name: 'name', value: e.target.value });
  49. // dispatch({ type: 'dataSource/remoteModify' });
  50. }}
  51. onChange={(e) => {
  52. dispatch({ type: 'dataSourceDetail/setField', name: 'name', value: e.target.value });
  53. }}>
  54. </Input>
  55. </FormItem>
  56. {
  57. dataSourceDetail.type==='file'?(
  58. <div>
  59. <Divider orientation="left">文件</Divider>
  60. <div>此处显示文件名</div>
  61. </div>
  62. ):(
  63. <div>
  64. <Divider orientation="left">连接配置</Divider>
  65. <div style={{ textAlign: 'end', color: '#F5222D' }}>*若只修改数据连接,请确认不同数据库取数逻辑一致</div>
  66. <FormItem label='数据连接' {...formItemLayout}>
  67. <Select
  68. value={dataSourceDetail.connectCode}
  69. onChange={(value) => {
  70. let selectedDataConnect = dataConnect.list.filter((l) => l.code === value)[0];
  71. dispatch({ type: 'dataSourceDetail/setFields', fields: [
  72. { name: 'connectCode', value: selectedDataConnect.code },
  73. { name: 'dbType', value: selectedDataConnect.dbType },
  74. { name: 'address', value: selectedDataConnect.address },
  75. { name: 'port', value: selectedDataConnect.port },
  76. { name: 'dbName', value: selectedDataConnect.dbName },
  77. { name: 'userName', value: selectedDataConnect.userName },
  78. ] } );
  79. }}
  80. >
  81. { this.generateOptions() }
  82. </Select>
  83. </FormItem>
  84. <FormItem label='数据库类型' {...formItemLayout}>
  85. <Select
  86. disabled={true}
  87. value={dataSourceDetail.dbType}
  88. onChange={(value) => {
  89. dispatch({ type: 'dataSourceDetail/setField', name: 'dbType', value: value} );
  90. }}
  91. >
  92. <SelectOption value='oracle'>
  93. ORACLE
  94. </SelectOption>
  95. <SelectOption value='mysql'>
  96. MYSQL
  97. </SelectOption>
  98. <SelectOption value='sqlserver'>
  99. SQLSERVER
  100. </SelectOption>
  101. <SelectOption value='sqlite'>
  102. SQLITE
  103. </SelectOption>
  104. </Select>
  105. </FormItem>
  106. <Row>
  107. <Col span={19}>
  108. <FormItem label='数据库地址' {...{
  109. labelCol: { span: 5 },
  110. wrapperCol: { span: 19 }
  111. }}>
  112. <Input
  113. disabled={true}
  114. value={dataSourceDetail.address}
  115. onChange={(e) => {
  116. dispatch({ type: 'dataSourceDetail/setField', name: 'address', value: e.target.value });
  117. }}
  118. />
  119. </FormItem>
  120. </Col>
  121. <Col span={5}>
  122. <FormItem className='input-port' label='端口' {...{
  123. labelCol: { span: 12 },
  124. wrapperCol: { span: 12 }
  125. }}>
  126. <InputNumber
  127. disabled={true}
  128. value={dataSourceDetail.port}
  129. onChange={(value) => {
  130. dispatch({ type: 'dataSourceDetail/setField', name: 'port', value: value });
  131. }}
  132. />
  133. </FormItem>
  134. </Col>
  135. </Row>
  136. <FormItem label='数据库名' {...formItemLayout}>
  137. <Input
  138. disabled={true}
  139. value={dataSourceDetail.dbName}
  140. onChange={(e) => {
  141. dispatch({ type: 'dataSourceDetail/setField', name: 'dbName', value: e.target.value });
  142. }}
  143. />
  144. </FormItem>
  145. <Row>
  146. <Col span={12}>
  147. <FormItem label='用户名' {...{
  148. labelCol: { span: 8 },
  149. wrapperCol: { span: 16 }
  150. }}>
  151. <Input
  152. disabled={true}
  153. value={dataSourceDetail.userName}
  154. onChange={(e) => {
  155. dispatch({ type: 'dataSourceDetail/setField', name: 'userName', value: e.target.value });
  156. }}
  157. />
  158. </FormItem>
  159. </Col>
  160. <Col span={12}>
  161. <FormItem label='密码' {...{
  162. labelCol: { span: 8 },
  163. wrapperCol: { span: 16 }
  164. }}>
  165. <Input
  166. disabled={true}
  167. // value={dataSourceDetail.password}
  168. onChange={(e) => {
  169. let value = e.target.value;
  170. dispatch({ type: 'dataSourceDetail/setField', name: 'password', value: value });
  171. e.target.removeAttribute('value')
  172. }}
  173. />
  174. </FormItem>
  175. </Col>
  176. </Row>
  177. </div>
  178. )
  179. }
  180. <Divider orientation="left">其他配置</Divider>
  181. <FormItem label='所属分组' {...formItemLayout}>
  182. <Cascader
  183. value={getGroup()}
  184. allowClear={true}
  185. changeOnSelect={true}
  186. expandTrigger='hover'
  187. placeholder='未分组'
  188. options={[{pcode: '-1', code: '-1', label: '未分组'}].concat(dataSource.groupList).filter(g => g.pcode === '-1').map((p, i)=>{
  189. return {
  190. key: p.code,
  191. value: p.code,
  192. label: p.label,
  193. children: dataSource.groupList.filter(g => g.pcode === p.code && p.code !== '-1').map(c => {
  194. return {
  195. key: c.code,
  196. value: c.code,
  197. label: c.label
  198. }
  199. })
  200. }
  201. })}
  202. onChange={(value, items) => {
  203. let v = value[1] !== undefined ? value[1] : value[0];
  204. dispatch({ type: 'dataSourceDetail/setField', name: 'group', value: v });
  205. }}
  206. >
  207. </Cascader>
  208. </FormItem>
  209. <FormItem className='textarea-desc' label='说明' {...formItemLayout}>
  210. <Input.TextArea
  211. autosize={{ minRows: 2, maxRows: 5 }}
  212. value={dataSourceDetail.description}
  213. onChange={(e) => {
  214. dispatch({ type: 'dataSourceDetail/setField', name: 'description', value: e.target.value });
  215. }}
  216. onBlur={(e) => {
  217. // dispatch({ type: 'dataSource/remoteModify' });
  218. }}
  219. />
  220. </FormItem>
  221. </Form>
  222. );
  223. }
  224. }
  225. export default connect(({ present: { dataConnect, dataSource, dataSourceDetail } }) => ({ dataConnect, dataSource, dataSourceDetail }))(DataSourceBaseConfig);