PortalForm.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 { Form, Row, Col, Input, Radio, Tabs, Tree, Checkbox } from 'antd'
  22. import { FormComponentProps } from 'antd/lib/form/Form'
  23. const TreeNode = Tree.TreeNode
  24. const FormItem = Form.Item
  25. const TextArea = Input.TextArea
  26. const RadioGroup = Radio.Group
  27. const TabPane = Tabs.TabPane
  28. const utilStyles = require('assets/less/util.less')
  29. const styles = require('../Viz.less')
  30. import { IExludeRoles} from './PortalList'
  31. interface IProtalListProps {
  32. projectId: number
  33. type: string
  34. params?: any
  35. exludeRoles?: IExludeRoles[]
  36. onChangePermission: (scope: object, e: any) => any
  37. onCheckUniqueName?: (pathname: string, data: any, resolve: () => any, reject: (error: string) => any) => any
  38. }
  39. export class PortalForm extends React.PureComponent<IProtalListProps & FormComponentProps, {}> {
  40. private checkNameUnique = (rule, value = '', callback) => {
  41. const { onCheckUniqueName, type, form, projectId } = this.props
  42. const { id } = form.getFieldsValue()
  43. const data = {
  44. projectId,
  45. id: type === 'add' ? '' : id,
  46. name: value
  47. }
  48. if (!value) {
  49. callback()
  50. }
  51. onCheckUniqueName('dashboardPortal', data,
  52. () => {
  53. callback()
  54. }, (err) => {
  55. callback(err)
  56. })
  57. }
  58. public render () {
  59. const {
  60. type,
  61. exludeRoles
  62. } = this.props
  63. const { getFieldDecorator } = this.props.form
  64. const authControl = exludeRoles && exludeRoles.length ? exludeRoles.map((role) => (
  65. <div className={styles.excludeList} key={`${role.name}key`}>
  66. <Checkbox checked={role.permission} onChange={this.props.onChangePermission.bind(this, role)}/>
  67. <b>{role.name}</b>
  68. </div>
  69. )) : []
  70. const commonFormItemStyle = {
  71. labelCol: { span: 6 },
  72. wrapperCol: { span: 16 }
  73. }
  74. return (
  75. <Form>
  76. <Row gutter={8}>
  77. <Col span={24}>
  78. {type !== 'add' && (
  79. <FormItem className={utilStyles.hide}>
  80. {getFieldDecorator('id', {})(
  81. <Input />
  82. )}
  83. </FormItem>
  84. )}
  85. <FormItem className={utilStyles.hide}>
  86. {getFieldDecorator('avatar', {})(
  87. <Input />
  88. )}
  89. </FormItem>
  90. <Tabs defaultActiveKey="infomation">
  91. <TabPane tab="基本信息" key="infomation">
  92. <Col span={24}>
  93. <FormItem label="名称" {...commonFormItemStyle} hasFeedback>
  94. {getFieldDecorator('name', {
  95. rules: [{
  96. required: true,
  97. message: '名称 不能为空'
  98. }, {
  99. validator: this.checkNameUnique
  100. }]
  101. })(
  102. <Input placeholder="名称" />
  103. )}
  104. </FormItem>
  105. </Col>
  106. <Col span={24}>
  107. <FormItem label="描述" {...commonFormItemStyle}>
  108. {getFieldDecorator('description', {
  109. initialValue: ''
  110. })(
  111. <TextArea
  112. placeholder="描述"
  113. autosize={{minRows: 2, maxRows: 6}}
  114. />
  115. )}
  116. </FormItem>
  117. </Col>
  118. <Col span={24}>
  119. <FormItem label="是否发布" {...commonFormItemStyle}>
  120. {getFieldDecorator('publish', {
  121. initialValue: true
  122. })(
  123. <RadioGroup>
  124. <Radio value>发布</Radio>
  125. <Radio value={false}>编辑</Radio>
  126. </RadioGroup>
  127. )}
  128. </FormItem>
  129. </Col>
  130. </TabPane>
  131. <TabPane tab="权限管理" key="control" className={styles.controlTab}>
  132. {
  133. authControl
  134. }
  135. </TabPane>
  136. </Tabs>
  137. </Col>
  138. </Row>
  139. </Form>
  140. )
  141. }
  142. }
  143. export default Form.create<IProtalListProps & FormComponentProps>()(PortalForm)