dataSourceBox.jsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 DataSourceBox = ({operation, dispatch, dataSource, visibleBox, hideBox, form}) => {
  13. const formItemLayout = {
  14. labelCol: { span: 4 },
  15. wrapperCol: { span: 20 },
  16. };
  17. const okHandler = () => {
  18. if(operation == 'create') {
  19. dispatch({ type: 'dataSource/add' });
  20. }else if(operation == 'edit') {
  21. dispatch({ type: 'dataSource/modify' });
  22. }
  23. hideBox();
  24. }
  25. const dataSourceLinkMenu = (
  26. <Menu
  27. className='menu-datasource-link'
  28. onClick={() => {
  29. dispatch({ type: 'dataSource/setNewModelField', name: 'address', value: '1111adddd' });
  30. dispatch({ type: 'dataSource/setNewModelField', name: 'port', value: '1234' });
  31. dispatch({ type: 'dataSource/setNewModelField', name: 'type', value: {
  32. key: 'oracle',
  33. label: 'ORACLE'
  34. } });
  35. dispatch({ type: 'dataSource/setNewModelField', name: 'dbName', value: 'orcl' });
  36. dispatch({ type: 'dataSource/setNewModelField', name: 'userName', value: 'UAS' });
  37. dispatch({ type: 'dataSource/setNewModelField', name: 'password', value: 'select!#%*(' });
  38. }}
  39. >
  40. <MenuItem>1111</MenuItem>
  41. <MenuItem>2222</MenuItem>
  42. <MenuItem>33333</MenuItem>
  43. <MenuItem>44</MenuItem>
  44. </Menu>
  45. );
  46. return (
  47. <Modal
  48. className='newdatasource-box'
  49. title={`${operation=='create'?'新增':'修改'}数据源配置`}
  50. visible={visibleBox}
  51. onOk={() => {okHandler()}}
  52. onCancel={hideBox}
  53. maskClosable={false}
  54. destroyOnClose={true}
  55. >
  56. <Row>
  57. <Col span={12}>
  58. <Form size='small'>
  59. <FormItem label='数据源名称' {...formItemLayout}>
  60. <Input
  61. value={dataSource.newOne.name}
  62. onChange={(e) => { dispatch({ type: 'dataSource/setNewModelField', name: 'name', value: e.target.value }) }}>
  63. </Input>
  64. </FormItem>
  65. <Row>
  66. <Col span={19}>
  67. <FormItem label='数据库地址' {...{
  68. labelCol: { span: 5 },
  69. wrapperCol: { span: 19 }
  70. }}>
  71. <Input
  72. value={dataSource.newOne.address}
  73. onChange={(e) => {
  74. dispatch({ type: 'dataSource/setNewModelField', name: 'address', value: e.target.value });
  75. }}
  76. prefix={
  77. <Dropdown
  78. trigger={['click']}
  79. overlay={dataSourceLinkMenu}
  80. >
  81. <div style={{cursor: 'pointer'}}><Icon type='down' /></div>
  82. </Dropdown>
  83. }
  84. />
  85. </FormItem>
  86. </Col>
  87. <Col span={5}>
  88. <FormItem className='input-port' label='端口' {...{
  89. labelCol: { span: 12 },
  90. wrapperCol: { span: 12 }
  91. }}>
  92. <InputNumber
  93. value={dataSource.newOne.port}
  94. onChange={(value) => {
  95. dispatch({ type: 'dataSource/setNewModelField', name: 'port', value: value });
  96. }}
  97. />
  98. </FormItem>
  99. </Col>
  100. </Row>
  101. <FormItem label='数据库类型' {...formItemLayout}>
  102. <Select
  103. value={dataSource.newOne.type}
  104. labelInValue={true}
  105. onChange={(value) => {
  106. dispatch({ type: 'dataSource/setNewModelField', name: 'type', value: value} );
  107. }}
  108. >
  109. <SelectOption value='oracle'>
  110. ORACLE
  111. </SelectOption>
  112. <SelectOption value='mysql'>
  113. MYSQL
  114. </SelectOption>
  115. <SelectOption value='sqlserver'>
  116. SQLSERVER
  117. </SelectOption>
  118. <SelectOption value='sqlite'>
  119. SQLITE
  120. </SelectOption>
  121. </Select>
  122. </FormItem>
  123. <FormItem label='数据库名' {...formItemLayout}>
  124. <Input
  125. value={dataSource.newOne.dbName}
  126. onChange={(e) => {
  127. dispatch({ type: 'dataSource/setNewModelField', name: 'dbName', value: e.target.value });
  128. }}
  129. />
  130. </FormItem>
  131. <Row>
  132. <Col span={12}>
  133. <FormItem label='用户名' {...{
  134. labelCol: { span: 8 },
  135. wrapperCol: { span: 16 }
  136. }}>
  137. <Input
  138. value={dataSource.newOne.userName}
  139. onChange={(e) => {
  140. dispatch({ type: 'dataSource/setNewModelField', name: 'userName', value: e.target.value });
  141. }}
  142. />
  143. </FormItem>
  144. </Col>
  145. <Col span={12}>
  146. <FormItem label='密码' {...{
  147. labelCol: { span: 8 },
  148. wrapperCol: { span: 16 }
  149. }}>
  150. <Input
  151. type='password'
  152. value={dataSource.newOne.password}
  153. onChange={(e) => {
  154. dispatch({ type: 'dataSource/setNewModelField', name: 'password', value: e.target.value });
  155. }}
  156. />
  157. </FormItem>
  158. </Col>
  159. </Row>
  160. <FormItem className='textarea-target' label='加载对象' {...formItemLayout}>
  161. <Input.TextArea
  162. placeholder='输入表名或查询SQL'
  163. autosize={{ minRows: 3 }}
  164. />
  165. </FormItem>
  166. <FormItem label='自定义标签' {...formItemLayout}>
  167. <Select
  168. mode="tags"
  169. placeholder='多个标签使用逗号或空格分隔'
  170. tokenSeparators={[',', ' ']}
  171. value={dataSource.newOne.tags}
  172. dropdownStyle={{display: 'none'}}
  173. onChange={(value) => {
  174. dispatch({ type: 'dataSource/setNewModelField', name: 'tags', value: value });
  175. }}
  176. >
  177. </Select>
  178. </FormItem>
  179. <FormItem className='textarea-desc' label='说明' {...formItemLayout}>
  180. <Input.TextArea
  181. autosize={{ minRows: 2, maxRows: 2 }}
  182. value={dataSource.newOne.description}
  183. onChange={(e) => {
  184. dispatch({ type: 'dataSource/setNewModelField', name: 'description', value: e.target.value });
  185. }}
  186. />
  187. </FormItem>
  188. </Form>
  189. </Col>
  190. <Col span={12}>
  191. </Col>
  192. </Row>
  193. </Modal>
  194. )
  195. }
  196. function mapStateToProps({ present: { dataSource } }) {
  197. return { dataSource: dataSource };
  198. }
  199. export default connect(mapStateToProps)(DataSourceBox)