connectConfig.jsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import React from 'react'
  2. import { Modal, Form, Row, Col, Input, InputNumber, Select, Icon, Menu, Dropdown } 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. const DataSourceConnectConfig = ({ dataSource, dispatch }) => {
  13. const formItemLayout = {
  14. labelCol: { span: 4 },
  15. wrapperCol: { span: 20 },
  16. };
  17. const dataSourceLinkMenu = (
  18. <Menu
  19. className='menu-datasource-link'
  20. onClick={() => {
  21. dispatch({ type: 'dataSource/setNewModelField', name: 'address', value: '1111adddd' });
  22. dispatch({ type: 'dataSource/setNewModelField', name: 'port', value: '1234' });
  23. dispatch({ type: 'dataSource/setNewModelField', name: 'type', value: {
  24. key: 'oracle',
  25. label: 'ORACLE'
  26. } });
  27. dispatch({ type: 'dataSource/setNewModelField', name: 'dbName', value: 'orcl' });
  28. dispatch({ type: 'dataSource/setNewModelField', name: 'userName', value: 'UAS' });
  29. dispatch({ type: 'dataSource/setNewModelField', name: 'password', value: 'select!#%*(' });
  30. }}
  31. >
  32. <MenuItem>1111</MenuItem>
  33. <MenuItem>2222</MenuItem>
  34. <MenuItem>33333</MenuItem>
  35. <MenuItem>44</MenuItem>
  36. </Menu>
  37. );
  38. return (
  39. <Form size='small'>
  40. <Row>
  41. <Col span={19}>
  42. <FormItem label='数据库地址' {...{
  43. labelCol: { span: 5 },
  44. wrapperCol: { span: 19 }
  45. }}>
  46. <Input
  47. value={dataSource.newOne.address}
  48. onChange={(e) => {
  49. dispatch({ type: 'dataSource/setNewModelField', name: 'address', value: e.target.value });
  50. }}
  51. prefix={
  52. <Dropdown
  53. trigger={['click']}
  54. overlay={dataSourceLinkMenu}
  55. >
  56. <div style={{cursor: 'pointer'}}><Icon type='down' /></div>
  57. </Dropdown>
  58. }
  59. />
  60. </FormItem>
  61. </Col>
  62. <Col span={5}>
  63. <FormItem className='input-port' label='端口' {...{
  64. labelCol: { span: 12 },
  65. wrapperCol: { span: 12 }
  66. }}>
  67. <InputNumber
  68. value={dataSource.newOne.port}
  69. onChange={(value) => {
  70. dispatch({ type: 'dataSource/setNewModelField', name: 'port', value: value });
  71. }}
  72. />
  73. </FormItem>
  74. </Col>
  75. </Row>
  76. <FormItem label='数据库类型' {...formItemLayout}>
  77. <Select
  78. value={dataSource.newOne.type}
  79. labelInValue={true}
  80. onChange={(value) => {
  81. dispatch({ type: 'dataSource/setNewModelField', name: 'type', value: value} );
  82. }}
  83. >
  84. <SelectOption value='oracle'>
  85. ORACLE
  86. </SelectOption>
  87. <SelectOption value='mysql'>
  88. MYSQL
  89. </SelectOption>
  90. <SelectOption value='sqlserver'>
  91. SQLSERVER
  92. </SelectOption>
  93. <SelectOption value='sqlite'>
  94. SQLITE
  95. </SelectOption>
  96. </Select>
  97. </FormItem>
  98. <FormItem label='数据库名' {...formItemLayout}>
  99. <Input
  100. value={dataSource.newOne.dbName}
  101. onChange={(e) => {
  102. dispatch({ type: 'dataSource/setNewModelField', name: 'dbName', value: e.target.value });
  103. }}
  104. />
  105. </FormItem>
  106. <Row>
  107. <Col span={12}>
  108. <FormItem label='用户名' {...{
  109. labelCol: { span: 8 },
  110. wrapperCol: { span: 16 }
  111. }}>
  112. <Input
  113. value={dataSource.newOne.userName}
  114. onChange={(e) => {
  115. dispatch({ type: 'dataSource/setNewModelField', name: 'userName', value: e.target.value });
  116. }}
  117. />
  118. </FormItem>
  119. </Col>
  120. <Col span={12}>
  121. <FormItem label='密码' {...{
  122. labelCol: { span: 8 },
  123. wrapperCol: { span: 16 }
  124. }}>
  125. <Input
  126. type='password'
  127. value={dataSource.newOne.password}
  128. onChange={(e) => {
  129. dispatch({ type: 'dataSource/setNewModelField', name: 'password', value: e.target.value });
  130. }}
  131. />
  132. </FormItem>
  133. </Col>
  134. </Row>
  135. </Form>
  136. );
  137. }
  138. function mapStateToProps({ present: {dataSource} }) {
  139. return { dataSource }
  140. }
  141. export default connect(mapStateToProps)(DataSourceConnectConfig);