import React, { Component, Fragment } from 'react'; import { Form, Input, Upload, Select, Button } from 'antd'; import Debounce from 'lodash-decorators/debounce'; import Bind from 'lodash-decorators/bind'; import styles from './BaseView.less'; import GeographicView from './GeographicView'; import PhoneView from './PhoneView'; const FormItem = Form.Item; const { Option } = Select; // 头像组件 方便以后独立,增加裁剪之类的功能 const AvatarView = ({ avatar }) => (
头像
avatar
); const validatorGeographic = (rule, value, callback) => { const { province, city } = value; if (!province.key) { callback('Please input your province!'); } if (!city.key) { callback('Please input your city!'); } callback(); }; const validatorPhone = (rule, value, callback) => { const values = value.split('-'); if (!values[0]) { callback('Please input your area code!'); } if (!values[1]) { callback('Please input your phone number!'); } callback(); }; @Form.create() export default class BaseView extends Component { state = { md: false, }; componentDidMount() { this.setBaseInfo(); this.resize(); window.addEventListener('resize', this.resize); } componentWillUnmount() { window.removeEventListener('resize', this.resize); } setBaseInfo = () => { const { currentUser } = this.props; Object.keys(this.props.form.getFieldsValue()).forEach((key) => { const obj = {}; obj[key] = currentUser[key] || null; this.props.form.setFieldsValue(obj); }); }; getAvatarURL() { if (this.props.currentUser.avatar) { return this.props.currentUser.avatar; } const url = 'https://gw.alipayobjects.com/zos/rmsportal/BiazfanxmamNRoxxVxka.png'; return url; } getViewDom = (ref) => { this.view = ref; }; @Bind() @Debounce(200) resize() { if (this.view.offsetWidth > 696) { this.setState({ md: false, }); return; } this.setState({ md: true, }); } render() { const { getFieldDecorator } = this.props.form; return (
{getFieldDecorator('email', { rules: [ { required: true, message: 'Please input your email!' }, ], })()} {getFieldDecorator('name', { rules: [ { required: true, message: 'Please input your nick name!' }, ], })()} {getFieldDecorator('profile', { rules: [ { required: true, message: 'Please input personal profile!' }, ], })()} {getFieldDecorator('country', { rules: [ { required: true, message: 'Please input your country!' }, ], })( , )} {getFieldDecorator('geographic', { rules: [ { required: true, message: 'Please input your geographic info!', }, { validator: validatorGeographic, }, ], })()} {getFieldDecorator('address', { rules: [ { required: true, message: 'Please input your address!' }, ], })()} {getFieldDecorator('phone', { rules: [ { required: true, message: 'Please input your phone!' }, { validator: validatorPhone }, ], })()}
); } }