RoleForm.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import React from 'react'
  21. import classnames from 'classnames'
  22. import { connect } from 'react-redux'
  23. import { Form, Row, Col, Input, Radio, Steps, Transfer } from 'antd'
  24. import { FormComponentProps } from 'antd/lib/form/Form'
  25. const FormItem = Form.Item
  26. const RadioGroup = Radio.Group
  27. const Step = Steps.Step
  28. // import { checkNameAction } from '../App/actions'
  29. const utilStyles = require('assets/less/util.less')
  30. interface IRoleFormProps {
  31. type: string
  32. groupSource?: any[]
  33. groupTarget?: any[]
  34. onGroupChange?: (targets) => any
  35. organizationMembers?: any[]
  36. onCheckName?: (
  37. id: number,
  38. name: string,
  39. type: string,
  40. param?: any,
  41. resolve?: (res: any) => void,
  42. reject?: (err: any) => void
  43. ) => any
  44. }
  45. export class RoleForm extends React.PureComponent<IRoleFormProps & FormComponentProps, {}> {
  46. public render () {
  47. const {
  48. form,
  49. type
  50. } = this.props
  51. const { getFieldDecorator } = form
  52. const commonFormItemStyle = {
  53. labelCol: { span: 6 },
  54. wrapperCol: { span: 15 }
  55. }
  56. return (
  57. <Form>
  58. <Row>
  59. <Col span={24}>
  60. {type !== 'add' && (
  61. <FormItem className={utilStyles.hide}>
  62. {getFieldDecorator('id', {})(
  63. <Input />
  64. )}
  65. </FormItem>
  66. )}
  67. </Col>
  68. <Col span={24}>
  69. <FormItem label="名称" {...commonFormItemStyle}>
  70. {getFieldDecorator('name', {
  71. initialValue: '',
  72. rules: [{
  73. required: true,
  74. message: '名称 不能为空'
  75. }]
  76. })(
  77. <Input placeholder="名称" />
  78. )}
  79. </FormItem>
  80. </Col>
  81. <Col span={24}>
  82. <FormItem label="描述" {...commonFormItemStyle}>
  83. {getFieldDecorator('description', {
  84. initialValue: ''
  85. })(
  86. <Input.TextArea placeholder="描述" />
  87. )}
  88. </FormItem>
  89. </Col>
  90. </Row>
  91. </Form>
  92. )
  93. }
  94. }
  95. export default Form.create<IRoleFormProps & FormComponentProps>()(RoleForm)