mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-27 10:43:45 +00:00
148 lines
3.5 KiB
JavaScript
148 lines
3.5 KiB
JavaScript
import React, { PropTypes } from 'react'
|
|
import { Form, Input, InputNumber, Radio, Modal } from 'antd'
|
|
const FormItem = Form.Item
|
|
|
|
const formItemLayout = {
|
|
labelCol: {
|
|
span: 6
|
|
},
|
|
wrapperCol: {
|
|
span: 14
|
|
}
|
|
}
|
|
|
|
const modal = ({
|
|
visible,
|
|
type,
|
|
item = {},
|
|
onOk,
|
|
onCancel,
|
|
form: {
|
|
getFieldDecorator,
|
|
validateFields,
|
|
getFieldsValue
|
|
}
|
|
}) => {
|
|
function handleOk () {
|
|
validateFields((errors) => {
|
|
if (errors) {
|
|
return
|
|
}
|
|
const data = {
|
|
...getFieldsValue(),
|
|
key: item.key
|
|
}
|
|
onOk(data)
|
|
})
|
|
}
|
|
|
|
const modalOpts = {
|
|
title: `${type === 'create' ? '新建用户' : '修改用户'}`,
|
|
visible,
|
|
onOk: handleOk,
|
|
onCancel,
|
|
wrapClassName: 'vertical-center-modal'
|
|
}
|
|
|
|
return (
|
|
<Modal {...modalOpts}>
|
|
<Form horizontal>
|
|
<FormItem label='姓名:' hasFeedback {...formItemLayout}>
|
|
{getFieldDecorator('name', {
|
|
initialValue: item.name,
|
|
rules: [
|
|
{
|
|
required: true,
|
|
message: '姓名未填写'
|
|
}
|
|
]
|
|
})(<Input />)}
|
|
</FormItem>
|
|
<FormItem label='昵称:' hasFeedback {...formItemLayout}>
|
|
{getFieldDecorator('nickName', {
|
|
initialValue: item.nickName,
|
|
rules: [
|
|
{
|
|
required: true,
|
|
message: '昵称未填写'
|
|
}
|
|
]
|
|
})(<Input />)}
|
|
</FormItem>
|
|
<FormItem label='性别' hasFeedback {...formItemLayout}>
|
|
{getFieldDecorator('isMale', {
|
|
initialValue: item.isMale,
|
|
rules: [
|
|
{
|
|
required: true,
|
|
type: 'boolean',
|
|
message: '请选择性别'
|
|
}
|
|
]
|
|
})(
|
|
<Radio.Group>
|
|
<Radio value>男</Radio>
|
|
<Radio value={false}>女</Radio>
|
|
</Radio.Group>
|
|
)}
|
|
</FormItem>
|
|
<FormItem label='年龄:' hasFeedback {...formItemLayout}>
|
|
{getFieldDecorator('age', {
|
|
initialValue: item.age,
|
|
rules: [
|
|
{
|
|
required: true,
|
|
type: 'number',
|
|
message: '年龄未填写'
|
|
}
|
|
]
|
|
})(<InputNumber min={18} max={100} />)}
|
|
</FormItem>
|
|
<FormItem label='电话:' hasFeedback {...formItemLayout}>
|
|
{getFieldDecorator('phone', {
|
|
initialValue: item.phone,
|
|
rules: [
|
|
{
|
|
required: true,
|
|
message: '不能为空'
|
|
}
|
|
]
|
|
})(<Input />)}
|
|
</FormItem>
|
|
<FormItem label='邮箱:' hasFeedback {...formItemLayout}>
|
|
{getFieldDecorator('email', {
|
|
initialValue: item.email,
|
|
rules: [
|
|
{
|
|
required: true,
|
|
message: '不能为空'
|
|
}
|
|
]
|
|
})(<Input />)}
|
|
</FormItem>
|
|
<FormItem label='住址:' hasFeedback {...formItemLayout}>
|
|
{getFieldDecorator('address', {
|
|
initialValue: item.address,
|
|
rules: [
|
|
{
|
|
required: true,
|
|
message: '不能为空'
|
|
}
|
|
]
|
|
})(<Input />)}
|
|
</FormItem>
|
|
</Form>
|
|
</Modal>
|
|
)
|
|
}
|
|
|
|
modal.propTypes = {
|
|
visible: PropTypes.any,
|
|
form: PropTypes.object,
|
|
item: PropTypes.object,
|
|
onOk: PropTypes.func,
|
|
onCancel: PropTypes.func
|
|
}
|
|
|
|
export default Form.create()(modal)
|