CatalogueModal.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 { Modal, Form, Button, Input, Spin, Select, Radio } from 'antd'
  22. import { FormComponentProps } from 'antd/lib/form'
  23. import { ICatalogue, IViewBase } from '../types'
  24. import RadioGroup from 'antd/es/radio/group'
  25. const FormItem = Form.Item
  26. interface ICopyModalProps extends FormComponentProps<ICatalogue> {
  27. catalogues: ICatalogue[],
  28. selectedCatalogueKeys: string[],
  29. visible: boolean,
  30. loading: boolean,
  31. fromView: ICatalogue,
  32. onCheckUniqueName: (
  33. viewName: string,
  34. resolve: () => void,
  35. reject: (err: string) => void
  36. ) => void,
  37. onSave: (view: ICatalogue) => void,
  38. onCancel: () => void,
  39. }
  40. export class CatalogueModal extends React.PureComponent<ICopyModalProps> {
  41. private formItemStyle = {
  42. labelCol: { span: 6 },
  43. wrapperCol: { span: 18 }
  44. }
  45. private save = () => {
  46. const { form, fromView, onSave } = this.props
  47. form.validateFieldsAndScroll((err, fieldsValue) => {
  48. if (err) {
  49. return
  50. }
  51. const copyView = { ...fieldsValue, id: fromView?.id }
  52. onSave(copyView)
  53. })
  54. }
  55. private checkName = (_, value, callback) => {
  56. const { onCheckUniqueName } = this.props
  57. onCheckUniqueName(
  58. value,
  59. () => {
  60. callback()
  61. },
  62. (err) => {
  63. callback(err)
  64. }
  65. )
  66. }
  67. private clearFieldsValue = () => {
  68. this.props.form.resetFields()
  69. }
  70. public render() {
  71. const { form, visible, loading, fromView, catalogues, selectedCatalogueKeys, onCancel } = this.props
  72. const { getFieldDecorator } = form
  73. const modalButtons = [
  74. <Button key='back' size='large' onClick={onCancel}>
  75. 取 消
  76. </Button>,
  77. <Button
  78. disabled={loading}
  79. key='submit'
  80. size='large'
  81. type='primary'
  82. onClick={this.save}
  83. >
  84. 保 存
  85. </Button>
  86. ]
  87. return (
  88. <Modal
  89. title={fromView ? '编辑' : '新增'}
  90. wrapClassName='ant-modal-small'
  91. confirmLoading={loading}
  92. visible={visible}
  93. footer={modalButtons}
  94. onCancel={onCancel}
  95. afterClose={this.clearFieldsValue}
  96. >
  97. <Spin spinning={loading}>
  98. <Form>
  99. {!fromView && catalogues?.find((c) => selectedCatalogueKeys.includes(`${c?.id}`)) &&
  100. <FormItem label='目录' {...this.formItemStyle}>
  101. {getFieldDecorator<ICatalogue>('parentId', {
  102. validateFirst: true,
  103. rules: [{ required: true, message: '不能为空' }],
  104. initialValue: selectedCatalogueKeys.join()
  105. })(
  106. <RadioGroup>
  107. <Radio value={selectedCatalogueKeys.join()}>子目录</Radio>
  108. <Radio value={'-1'}>一级目录</Radio>
  109. </RadioGroup>
  110. )}
  111. </FormItem>}
  112. <FormItem label="资源名称" {...this.formItemStyle}>
  113. {getFieldDecorator<ICatalogue>('name', {
  114. validateFirst: true,
  115. rules: [
  116. { required: true, message: '不能为空' }
  117. // { validator: this.checkName }
  118. ],
  119. initialValue: fromView?.name
  120. })(<Input autoComplete={'off'} />)}
  121. </FormItem>
  122. <FormItem label='行业分类' {...this.formItemStyle}>
  123. {getFieldDecorator<ICatalogue>('industry', {
  124. initialValue: fromView?.industry
  125. })(<Input />)}
  126. </FormItem>
  127. <FormItem label='来源部门' {...this.formItemStyle}>
  128. {getFieldDecorator<ICatalogue>('originDept', {
  129. initialValue: fromView?.originDept
  130. })(<Input />)}
  131. </FormItem>
  132. <FormItem label='来源系统' {...this.formItemStyle}>
  133. {getFieldDecorator<ICatalogue>('originSystem', {
  134. initialValue: fromView?.originSystem
  135. })(<Input />)}
  136. </FormItem>
  137. <FormItem label='扩展json' {...this.formItemStyle}>
  138. {getFieldDecorator<ICatalogue>('extConfig', {
  139. initialValue: fromView?.extConfig
  140. })(<Input />)}
  141. </FormItem>
  142. <FormItem label='描述' {...this.formItemStyle}>
  143. {getFieldDecorator<ICatalogue>('description', {
  144. initialValue: fromView?.description
  145. })(<Input />)}
  146. </FormItem>
  147. </Form>
  148. </Spin>
  149. </Modal>
  150. )
  151. }
  152. }
  153. export default Form.create<ICopyModalProps>()(CatalogueModal)