dataSourceBox.jsx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. import React from 'react'
  2. import { Modal, Form, Row, Col, Input, 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/addDataSource' });
  20. }else if(operation == 'edit') {
  21. dispatch({ type: 'dataSource/modifyDataSource' });
  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. <Form size='small'>
  57. <FormItem label='数据源名称' {...formItemLayout}>
  58. <Input
  59. value={dataSource.newOne.name}
  60. onChange={(e) => { dispatch({ type: 'dataSource/setNewModelField', name: 'name', value: e.target.value }) }}>
  61. </Input>
  62. </FormItem>
  63. <Row>
  64. <Col span={19}>
  65. <FormItem label='数据库地址' {...{
  66. labelCol: { span: 5 },
  67. wrapperCol: { span: 19 }
  68. }}>
  69. <Input
  70. value={dataSource.newOne.address}
  71. onChange={(e) => {
  72. dispatch({ type: 'dataSource/setNewModelField', name: 'address', value: e.target.value });
  73. }}
  74. addonBefore={
  75. <Dropdown
  76. trigger={['click']}
  77. overlay={dataSourceLinkMenu}
  78. >
  79. <div style={{cursor: 'pointer'}}>导入<Icon type='down' /></div>
  80. </Dropdown>
  81. }
  82. />
  83. </FormItem>
  84. </Col>
  85. <Col span={5}>
  86. <FormItem label='端口' {...{
  87. labelCol: { span: 12 },
  88. wrapperCol: { span: 12 }
  89. }}>
  90. <Input
  91. value={dataSource.newOne.port}
  92. onChange={(e) => {
  93. dispatch({ type: 'dataSource/setNewModelField', name: 'port', value: e.target.value });
  94. }}
  95. />
  96. </FormItem>
  97. </Col>
  98. </Row>
  99. <FormItem label='数据库类型' {...formItemLayout}>
  100. <Select
  101. value={dataSource.newOne.type}
  102. labelInValue={true}
  103. onChange={(value) => {
  104. dispatch({ type: 'dataSource/setNewModelField', name: 'type', value: value} );
  105. }}
  106. >
  107. <SelectOption value='oracle'>
  108. ORACLE
  109. </SelectOption>
  110. <SelectOption value='mysql'>
  111. MYSQL
  112. </SelectOption>
  113. <SelectOption value='sqlserver'>
  114. SQLSERVER
  115. </SelectOption>
  116. <SelectOption value='sqlite'>
  117. SQLITE
  118. </SelectOption>
  119. </Select>
  120. </FormItem>
  121. <FormItem label='数据库名' {...formItemLayout}>
  122. <Input
  123. value={dataSource.newOne.dbName}
  124. onChange={(e) => {
  125. dispatch({ type: 'dataSource/setNewModelField', name: 'dbName', value: e.target.value });
  126. }}
  127. />
  128. </FormItem>
  129. <Row>
  130. <Col span={12}>
  131. <FormItem label='用户名' {...{
  132. labelCol: { span: 8 },
  133. wrapperCol: { span: 16 }
  134. }}>
  135. <Input
  136. value={dataSource.newOne.userName}
  137. onChange={(e) => {
  138. dispatch({ type: 'dataSource/setNewModelField', name: 'userName', value: e.target.value });
  139. }}
  140. />
  141. </FormItem>
  142. </Col>
  143. <Col span={12}>
  144. <FormItem label='密码' {...{
  145. labelCol: { span: 8 },
  146. wrapperCol: { span: 16 }
  147. }}>
  148. <Input
  149. type='password'
  150. value={dataSource.newOne.password}
  151. onChange={(e) => {
  152. dispatch({ type: 'dataSource/setNewModelField', name: 'password', value: e.target.value });
  153. }}
  154. />
  155. </FormItem>
  156. </Col>
  157. </Row>
  158. <FormItem className='textarea-target' label='加载对象' {...formItemLayout}>
  159. <Input.TextArea
  160. placeholder='输入表名或查询SQL'
  161. autosize={{ minRows: 3 }}
  162. />
  163. </FormItem>
  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: 2 }}
  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. </Modal>
  188. )
  189. }
  190. function mapStateToProps({ present: { dataSource } }) {
  191. return { dataSource: dataSource };
  192. }
  193. export default connect(mapStateToProps)(DataSourceBox)