import * as React from 'react'; import { admin } from 'store/admin'; import { notification, Modal, Form, Input, Switch, Select, Tooltip, Radio } from 'antd'; import { IBrokersMetadata, IBrokersRegions, IExpand } from 'types/base-type'; import { searchProps } from 'constants/table'; import { expandPartition } from 'lib/api'; const layout = { labelCol: { span: 6 }, wrapperCol: { span: 15 }, }; interface IXFormProps { form: any; formData?: any; visible?: boolean; handleVisible?: any; clusterId?: number; } class CustomForm extends React.Component { public state = { checked: false, }; public onSwitchChange(checked: boolean) { this.setState({ checked }); this.props.form.validateFields((err: any, values: any) => { checked ? values.brokerIdList = [] : values.regionId = ''; }); } public handleExpandOk() { this.props.form.validateFields((err: any, values: any) => { if (!err) { this.props.handleVisible(false); const params = { topicName: values.topicName, clusterId: this.props.clusterId, partitionNum: values.partitionNum, } as IExpand; if (values.brokerIdList) { params.brokerIdList = values.brokerIdList; } else { params.regionId = values.regionId; } const valueParams = [] as IExpand[]; valueParams.push(params); expandPartition(valueParams).then(data => { notification.success({ message: '扩分成功' }); this.props.form.resetFields(); admin.getClusterTopics(this.props.clusterId); }); } }); } public handleExpandCancel() { this.props.handleVisible(false); this.props.form.resetFields(); } public componentDidMount() { admin.getBrokersMetadata(this.props.clusterId); admin.getBrokersRegions(this.props.clusterId); } public render() { const { formData = {} as any, visible } = this.props; const { getFieldDecorator } = this.props.form; let metadata = [] as IBrokersMetadata[]; metadata = admin.brokersMetadata ? admin.brokersMetadata : metadata; let regions = [] as IBrokersRegions[]; regions = admin.brokersRegions ? admin.brokersRegions : regions; return ( this.handleExpandOk()} onCancel={() => this.handleExpandCancel()} maskClosable={false} okText="确认" cancelText="取消" >
({})} > {getFieldDecorator('topicName', { initialValue: formData.topicName, rules: [{ required: true, message: '请输入Topic名称' }], })()} {/* 运维管控-topic信息-扩分区操作 */} {getFieldDecorator('regionNameList', { initialValue: admin.topicsBasic ? admin.topicsBasic.regionNameList : '', rules: [{ required: true, message: '请输入所属region' }], })()} {/* 运维管控-topic信息-扩分区操作 */} {getFieldDecorator('partitionNum', { rules: [{ required: true, message: '请输入分区数', }], })()} {/* */} {/* this.onSwitchChange(checked)} /> */} { this.onSwitchChange(e.target.value === 'region' ? true : false); }}> Region类型 Borker类型 {getFieldDecorator('brokerIdList', { initialValue: formData.brokerIdList, rules: [{ required: !this.state.checked, message: '请输入brokerIdList' }], })( , )} {getFieldDecorator('regionId', { initialValue: formData.regionId, rules: [{ required: this.state.checked, message: '请选择regionId' }], })( , )}
); } } export const ExpandPartitionFormWrapper = Form.create()(CustomForm);