dataConnectBox.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import React from 'react'
  2. import { Modal, Form, Row, Col, Input, InputNumber, Select, Button, Icon } from 'antd'
  3. import { connect } from 'dva'
  4. import './dataConnectBox.less'
  5. const FormItem = Form.Item
  6. const SelectOption = Select.Option
  7. class DataConnectBox extends React.Component {
  8. hideBox() {
  9. const { dispatch } = this.props;
  10. dispatch({ type: 'dataConnect/setNewModelField', name: 'visibleBox', value: false });
  11. }
  12. okHandler() {
  13. const { dispatch, dataConnect} = this.props;
  14. const operation = dataConnect.newOne.boxOperation;
  15. if(operation === 'create') {
  16. dispatch({ type: 'dataConnect/remoteAdd' }).then((success) => {
  17. success && this.hideBox()
  18. });
  19. }else if(operation === 'modify') {
  20. dispatch({ type: 'dataConnect/remoteModify', code: dataConnect.newOne.code }).then((success) => {
  21. success && this.hideBox();
  22. });
  23. }
  24. }
  25. render() {
  26. const { dispatch, dataConnect } = this.props;
  27. const operation = dataConnect.newOne.boxOperation;
  28. const disabled = operation === 'view';
  29. const formItemLayout = {
  30. labelCol: { span: 4 },
  31. wrapperCol: { span: 20 },
  32. };
  33. return (
  34. <Modal
  35. className='dataconnect-box'
  36. title={<Row type='flex' justify='space-between'><Col>{`${operation === 'create'?'新建':(operation === 'modify' ? '修改' : '查看')}数据库连接`}</Col><Col style={{ marginRight: '35px', fontSize: '14px', cursor: 'pointer', color: 'red' }} onClick={() => {
  37. // 密码input特殊处理
  38. document.getElementsByClassName('password')[0].value = '';
  39. dispatch({ type:'dataConnect/resetNewModel'})
  40. }}>
  41. {/* <Icon type='delete' />清空 */}
  42. </Col></Row>}
  43. visible={dataConnect.newOne.visibleBox}
  44. onCancel={() => { this.hideBox() }}
  45. maskClosable={false}
  46. destroyOnClose={true}
  47. footer={
  48. operation === 'view' ? null : (
  49. <Row>
  50. <Col className='validatemessage' span={12}>
  51. {/* {dataConnect.newOne.invalid !== undefined ? (dataConnect.newOne.invalid ? <span style={{ color: '#F5222D' }}>{dataConnect.newOne.invalidText}</span> : <span style={{ color: '#52C41A' }}>测试通过</span>) : ''} */}
  52. </Col>
  53. <Col span={12}>
  54. <Button disabled={dataConnect.newOne.validating || dataConnect.newOne.saving} onClick={() => dispatch({ type:'dataConnect/remoteValidate'})}>
  55. {dataConnect.newOne.validating ? (<Icon type='loading' />) : ''}{dataConnect.newOne.validating ? '测试中' : '测试'}
  56. </Button>
  57. <Button disabled={dataConnect.newOne.validating || dataConnect.newOne.saving} onClick={() => dispatch({ type:'dataConnect/resetNewModel'})}>清空</Button>
  58. {/* <Button onClick={() => {this.hideBox()}}>取 消</Button> */}
  59. <Button className={dataConnect.newOne.validating ? 'ant-btn-loading' : ''} type="primary" disabled={dataConnect.newOne.validating || dataConnect.newOne.saving} onClick={() => {this.okHandler()}}>
  60. {dataConnect.newOne.saving ? (<Icon type='loading' />) : ''}
  61. {dataConnect.newOne.saving ? '校验中' : '保存'}
  62. </Button>
  63. </Col>
  64. </Row>
  65. )
  66. }
  67. >
  68. <Form size='small'>
  69. <FormItem
  70. label='连接名'
  71. {...formItemLayout}
  72. validateStatus={dataConnect.validInfo.name ? dataConnect.validInfo.name.validateStatus : ''}
  73. help={dataConnect.validInfo.name ? dataConnect.validInfo.name.help : ''}
  74. >
  75. <Input
  76. disabled={disabled}
  77. placeholder="输入数据库连接名称"
  78. value={dataConnect.newOne.name}
  79. onChange={(e) => { dispatch({ type: 'dataConnect/setNewModelField', name: 'name', value: e.target.value }) }}
  80. >
  81. </Input>
  82. </FormItem>
  83. <FormItem label='数据库类型' {...formItemLayout}>
  84. <Select
  85. disabled={true}
  86. placeholder="选择数据库类型"
  87. defaultValue='oracle'
  88. value={dataConnect.newOne.dbType}
  89. onChange={(value) => {
  90. dispatch({ type: 'dataConnect/setNewModelField', name: 'dbType', value: value} );
  91. }}
  92. >
  93. <SelectOption value='oracle'>
  94. ORACLE
  95. </SelectOption>
  96. <SelectOption value='mysql'>
  97. MYSQL
  98. </SelectOption>
  99. <SelectOption value='sqlserver'>
  100. SQLSERVER
  101. </SelectOption>
  102. <SelectOption value='sqlite'>
  103. SQLITE
  104. </SelectOption>
  105. </Select>
  106. </FormItem>
  107. <Row>
  108. <Col span={19}>
  109. <FormItem label='数据库地址' {...{
  110. labelCol: { span: 5 },
  111. wrapperCol: { span: 19 }
  112. }}>
  113. <Input
  114. disabled={disabled}
  115. placeholder="格式:192.168.1.1"
  116. value={dataConnect.newOne.address}
  117. onChange={(e) => {
  118. dispatch({ type: 'dataConnect/setNewModelField', name: 'address', value: e.target.value });
  119. }}
  120. />
  121. </FormItem>
  122. </Col>
  123. <Col span={5}>
  124. <FormItem className='input-port' label='端口' {...{
  125. labelCol: { span: 12 },
  126. wrapperCol: { span: 12 }
  127. }}>
  128. <InputNumber
  129. disabled={disabled}
  130. value={dataConnect.newOne.port}
  131. onChange={(value) => {
  132. dispatch({ type: 'dataConnect/setNewModelField', name: 'port', value: value });
  133. }}
  134. />
  135. </FormItem>
  136. </Col>
  137. </Row>
  138. <FormItem label='数据库名(SID)' {...formItemLayout}>
  139. <Input
  140. disabled={disabled}
  141. value={dataConnect.newOne.dbName}
  142. onChange={(e) => {
  143. dispatch({ type: 'dataConnect/setNewModelField', name: 'dbName', value: e.target.value });
  144. }}
  145. />
  146. </FormItem>
  147. <Row>
  148. <Col span={12}>
  149. <FormItem label='用户名' {...{
  150. labelCol: { span: 8 },
  151. wrapperCol: { span: 16 }
  152. }}>
  153. <Input
  154. disabled={disabled}
  155. value={dataConnect.newOne.userName}
  156. onChange={(e) => {
  157. dispatch({ type: 'dataConnect/setNewModelField', name: 'userName', value: e.target.value });
  158. }}
  159. />
  160. </FormItem>
  161. </Col>
  162. <Col span={12}>
  163. <FormItem label='密码' {...{
  164. labelCol: { span: 8 },
  165. wrapperCol: { span: 16 }
  166. }}>
  167. <Input
  168. disabled={disabled}
  169. className='password'
  170. type='password'
  171. // value={dataConnect.newOne.password}
  172. onChange={(e) => {
  173. dispatch({ type: 'dataConnect/setNewModelField', name: 'password', value: e.target.value });
  174. }}
  175. />
  176. </FormItem>
  177. </Col>
  178. </Row>
  179. <FormItem className='textarea-desc' label='说明' {...formItemLayout}>
  180. <Input.TextArea
  181. disabled={disabled}
  182. autosize={{ minRows: 2 }}
  183. value={dataConnect.newOne.description}
  184. onChange={(e) => {
  185. dispatch({ type: 'dataConnect/setNewModelField', name: 'description', value: e.target.value });
  186. }}
  187. />
  188. </FormItem>
  189. </Form>
  190. </Modal>
  191. )
  192. }
  193. }
  194. function mapStateToProps(state) {
  195. const dataConnect = state.present.dataConnect;
  196. return { dataConnect };
  197. }
  198. export default connect(mapStateToProps)(DataConnectBox)