码迷,mamicode.com
首页 > 其他好文 > 详细

ant-design 实现 添加页面

时间:2018-09-20 22:18:16      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:border   import   姓名   end   ops   ini   type   red   select   

1.逻辑代码

/**
 * 添加用户
 */
import React,{PureComponent} from ‘react‘
import {Card,Form,Input,Select,Button} from ‘antd‘
import {connect} from ‘react-redux‘

/**
 *  用户列表
 */

const FormItem = Form.Item;

const Option = Select.Option;

@Form.create()
class UserAdd extends PureComponent{
  // 生命周期--组件加载完毕
  componentDidMount(){
    // this.props.changetitle("用户管理—添加")
  }

  render(){
    const { getFieldDecorator } = this.props.form;

    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
        md: { span: 10 },
      },
    };

    const submitFormLayout = {
      wrapperCol: {
        xs: { span: 24, offset: 0 },
        sm: { span: 10, offset: 7 },
      },
    };
  
    return(
      <Card bordered={false}>
        <Form layout="horizontal">
          {/*账号*/}
          <FormItem {...formItemLayout} label="账号">
            {getFieldDecorator(‘account‘, {
              rules: [{
                required: true, message: ‘请输入账号‘,
              }],
            })(
              <Input placeholder="请输入账号" />
            )}
          </FormItem>
          {/*姓名*/}
          <FormItem {...formItemLayout} label="姓名">
            {getFieldDecorator(‘name‘, {
              rules: [{
                required: true, message: ‘请输入姓名‘,
              }],
            })(
              <Input placeholder="请输入姓名" />
            )}
          </FormItem>
          {/*状态*/}
          <FormItem {...formItemLayout} label="状态">
            {getFieldDecorator(‘state‘, {
              rules: [{
                required: true, message: ‘请选择状态‘,
              }],
              initialValue:"0",
            })(
              <Select >
                <Option value="0">禁用</Option>
                <Option value="1">启用</Option>
              </Select>
            )}
          </FormItem>
          {/*提交|保存按钮*/}
          <FormItem {...submitFormLayout} style={{ marginTop: 32 }}>
            <Button type="primary" htmlType="submit" >
              提交
            </Button>
            <Button style={{ marginLeft: 8 }}>保存</Button>
          </FormItem>
        </Form>
      </Card>
    )
  }
}

export default connect ((state)=>(
  {
    state
  }
))(UserAdd)

2.效果图

技术分享图片

ant-design 实现 添加页面

标签:border   import   姓名   end   ops   ini   type   red   select   

原文地址:https://www.cnblogs.com/crazycode2/p/9678374.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!