首页分享
海ͯ伊ͯ · 大乘

antdpro 刷新后数据丢失 怎么搞哦

海ͯ伊ͯ发布于
import {
  Button,
  Card,
  DatePicker,
  Form,
  Input,
  Radio,
  Select,
  Switch,
  Row,
  Col,
  Typography,

} from 'antd';
const { Text } = Typography;
import React, { Component } from 'react';
import { Dispatch } from 'redux';
import { FormComponentProps } from 'antd/es/form';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { connect } from 'dva';


const FormItem = Form.Item;
const { Option } = Select;
const { RangePicker } = DatePicker;
const { TextArea } = Input;
interface FormBasicFormProps extends FormComponentProps {
  submitting: boolean;
  dispatch: Dispatch<any>;
  forminfo: Object;
  state: any;
  setingxcx: any
}

interface FromState {
  is_getphone: Boolean | String,
  is_trial: Boolean | String,

}
@connect(({ setingxcx, loading }) : ({
  setingxcx,
  loading: loading.models.setingxcx,
}))




class FormBasicForm extends Component<FormBasicFormProps> {



  state: FromState = {
    is_getphone: '',
    is_trial: '',
  };

// 即将进入
  componentWillMount(){
    console.log(111111111);

    const { dispatch } = this.props;
    if (dispatch) {
      dispatch({
        type: 'setingxcx/getsetting',
      });
    }
  }
  //进入
  componentDidMount() {
    const { setingxcx } = this.props;
    const { forminfo } = setingxcx
    console.log(forminfo);

    this.setState({
      is_getphone:forminfo.is_getphone,
      is_trial:forminfo.is_triay
    })
  }

  // 数据更新生命
  componentDidUpdate() {
    console.log(this.state);




  }


  handleSubmit = (e: React.FormEvent) : {
    const { dispatch, form } = this.props;
    e.preventDefault();
    form.validateFieldsAndScroll((err, values) : {
      if (!err) {
        dispatch({
          type: 'settingxcx/submitRegularForm',
          payload: values,
        });
      }
    });
  };



  getphoen = (e: any) : {

    if (e == true) {
      this.setState({
        is_getphone:1
      })

    }else{
        this.setState({
          is_getphone:2
        }) 
    }

  };

  render() {
    const { submitting, setingxcx } = this.props;
    const { forminfo } = setingxcx
    console.log(forminfo);


    const {
      form: { getFieldDecorator, getFieldValue },
    } = this.props;
    const formItemLayout = {
      labelCol: {
        xs: {
          span: 6,
        },
        sm: {
          span: 6,
        },
      },
      wrapperCol: {
        xs: {
          span: 18,
        },
        sm: {
          span: 18,
        },
        md: {
          span: 18,
        },
      },
    };
    const submitFormLayout = {
      wrapperCol: {
        xs: {
          span: 24,
          offset: 0,
        },
        sm: {
          span: 10,
          offset: 7,
        },
      },
    };


    return (
      <PageHeaderWrapper content="">
        <Card bordered={false}>
          <Form
            onSubmit={this.handleSubmit}
            hideRequiredMark
            style={{
              marginTop: 8,
            }}
          >
            {/* switch开关 */}
            <FormItem {...formItemLayout} label="快捷开关">
              {getFieldDecorator('switch', {
                rules: [
                  {
                    required: true,
                    message: 'formbasicform.title.required',
                  },
                ],
              })(

                <Card >
                  <Row>
                    <Col span={8}>
                      <Switch defaultChecked={forminfo.is_getphone == 1 ? true : false}
                        onChange={this.getphoen}

                      />
                      <Text> 获取手机号</Text>
                    </Col>
                    <Col span={8}>
                      <Switch defaultChecked={forminfo.is_triay == 1 ? true : false} />
                      <Text> 过审模式</Text>
                    </Col>


                  </Row>

                </Card>


              )}
            </FormItem>



            <FormItem {...formItemLayout} label="小程序名称">
              {getFieldDecorator('title', {
                rules: [
                  {
                    required: true,
                    message: 'formbasicform.title.required',
                  },
                ],
              })(<Input placeholder="请输入小程序名称" />)}
            </FormItem>
            <FormItem {...formItemLayout} label="日期选择">
              {getFieldDecorator('date', {
                rules: [
                  {
                    required: true,
                    message: 'formbasicform.date.required',
                  },
                ],
              })(
                <RangePicker
                  style={{
                    width: '100%',
                  }}
                  placeholder={['开始时间', '结束时间']}
                />,
              )}
            </FormItem>
            <FormItem {...formItemLayout} label="登录使用条款">
              {getFieldDecorator('goal', {
                rules: [
                  {
                    required: true,
                    message: 'formbasicform.goal.required',
                  },
                ],
              })(
                <TextArea
                  style={{
                    minHeight: 32,
                  }}
                  placeholder="写点什么吧"
                  rows={4}
                />,
              )}
            </FormItem>
            <FormItem {...formItemLayout} label="免责声明">
              {getFieldDecorator('standard', {
                rules: [
                  {
                    required: true,
                    message: 'formbasicform.standard.required',
                  },
                ],
              })(
                <TextArea
                  style={{
                    minHeight: 32,
                  }}
                  placeholder="写点什么吧"
                  rows={4}
                />,
              )}
            </FormItem>
            <FormItem {...formItemLayout} label="会员手册">
              {getFieldDecorator('standard', {
                rules: [
                  {
                    required: true,
                    message: 'formbasicform.standard.required',
                  },
                ],
              })(
                <TextArea
                  style={{
                    minHeight: 32,
                  }}
                  placeholder="写点什么吧"
                  rows={4}
                />,
              )}
            </FormItem>




            <FormItem
              {...formItemLayout}
              label="formbasicform.public.label"
              help=""
            >
              <div>
                {getFieldDecorator('public', {
                  initialValue: '1',
                })(
                  <Radio.Group>
                    <Radio value="1">选项A</Radio>
                    <Radio value="2">选项B</Radio>
                    <Radio value="3">选项C</Radio>
                  </Radio.Group>,
                )}
                <FormItem
                  style={{
                    marginBottom: 0,
                  }}
                >
                  {getFieldDecorator('publicUsers')(
                    <Select
                      mode="multiple"
                      placeholder="111111"
                      style={{
                        margin: '8px 0',
                        display: getFieldValue('public') === '2' ? 'block' : 'none',
                      }}
                    >
                      <Option value="1">选项A</Option>
                      <Option value="2">选项B</Option>
                      <Option value="3">选项C</Option>
                    </Select>,
                  )}
                </FormItem>
              </div>
            </FormItem>
            <FormItem
              {...submitFormLayout}
              style={{
                marginTop: 32,
              }}
            >
              <Button type="primary" htmlType="submit" loading={submitting}>
                提交
              </Button>

            </FormItem>
          </Form>
        </Card>
      </PageHeaderWrapper>
    );
  }
}

export default Form.create<FormBasicFormProps>()(
  connect(({ loading }: { loading: { effects: { [key: string]: boolean } } }) : ({
    submitting: loading.effects['settingxcx/submitRegularForm'],

  }))(FormBasicForm),
);

本站帖子均为原创内容,如需转载请注明出处,谢谢。

0 条回复
暂无回复~~
喜欢

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 在线学员:132

Top