import * as React from 'react'; import { Modal, Form, Row, Input, Select, InputNumber, notification } from 'component/antd'; import { modal } from 'store/modal'; import { cluster } from 'store/cluster'; import { createTopic } from 'lib/api'; import { ITopic } from 'types/base-type'; import { operation } from 'store/operation'; import urlQuery from 'store/url-query'; import { getCookie } from 'lib/utils'; const topicFormItemLayout = { labelCol: { span: 7, }, wrapperCol: { span: 11, }, }; const bussDesc = `概要描述Topic的数据源, Topic数据的生产者/消费者, Topic的申请原因及备注信息等。`; class Topic extends React.Component { public state = { loading: false, }; public getDisabled = () => !!modal.topicData; public handleSubmit = () => { if (this.getDisabled()) return modal.close(); this.props.form.validateFields((err: Error, values: any) => { if (err) return; const { principalList, retentionTime } = values; values.principalList = principalList.split(','); values.retentionTime = retentionTime; this.setState({ loading: true }); createTopic(values).then(data => { notification.success({ message: '申请Topic成功' }); window.setTimeout(() => location.assign('/user/my_order'), 500); modal.close(); }, (err) => { this.setState({ loading: false }); }); }); } public render() { const { getFieldDecorator } = this.props.form; const disabled = this.getDisabled(); const { loading } = this.state; const initialData = modal.topicData || {} as ITopic; return (
{getFieldDecorator('clusterId', { rules: [{ required: true, message: '请选择集群' }], initialValue: +urlQuery.clusterId || initialData.clusterId || (cluster.data[1] && cluster.data[1].clusterId), })( , )} {getFieldDecorator('topicName', { rules: [{ required: true, message: '请输入Topic 名称' }, { pattern: /^[a-zA-Z0-9_-]{1,64}$/, message: '格式不正确' }], initialValue: initialData.topicName, })( , )} {getFieldDecorator('principalList', { rules: [{ required: true, message: '请输入负责人' }], initialValue: disabled ? initialData.principals || ' ' : getCookie('username'), })( , )} {getFieldDecorator('retentionTime', { rules: [{ required: true, message: '请输入保存时间' }], initialValue: (initialData.retentionTime / 3600000) || 24, })( , )} 小时 {getFieldDecorator('peakBytesIn', { rules: [{ required: true, message: '请输入限流值' }], initialValue: initialData.peakBytesIn || 1, })( , )} MB/s {getFieldDecorator('description', { rules: [{ required: true, message: '请输入业务说明' }], initialValue: initialData.description || '', })( , )}
); } } export default Form.create({ name: 'topic' })(Topic);