import React, { Component } from 'react'; import { Card, Form, Icon, Button, Col, Row, DatePicker, TimePicker, Input, Select, Popover, } from 'antd'; import { connect } from 'dva'; import TableForm from './components/TableForm'; import styles from './style.less'; import { FormComponentProps } from 'antd/lib/form'; import { Dispatch } from 'redux'; import FooterToolbar from './components/FooterToolbar'; const { Option } = Select; const { RangePicker } = DatePicker; const fieldLabels = { name: '仓库名', url: '仓库域名', owner: '仓库管理员', approver: '审批人', dateRange: '生效日期', type: '仓库类型', name2: '任务名', url2: '任务描述', owner2: '执行人', approver2: '责任人', dateRange2: '生效日期', type2: '任务类型', }; const tableData = [ { key: '1', workId: '00001', name: 'John Brown', department: 'New York No. 1 Lake Park', }, { key: '2', workId: '00002', name: 'Jim Green', department: 'London No. 1 Lake Park', }, { key: '3', workId: '00003', name: 'Joe Black', department: 'Sidney No. 1 Lake Park', }, ]; interface PAGE_NAME_UPPER_CAMEL_CASEProps extends FormComponentProps { dispatch: Dispatch; submitting: boolean; } @connect(({ loading }: { loading: { effects: { [key: string]: boolean } } }) => ({ submitting: loading.effects['BLOCK_NAME_CAMEL_CASE/submitAdvancedForm'], })) class PAGE_NAME_UPPER_CAMEL_CASE extends Component { state = { width: '100%', }; componentDidMount() { window.addEventListener('resize', this.resizeFooterToolbar, { passive: true }); } componentWillUnmount() { window.removeEventListener('resize', this.resizeFooterToolbar); } getErrorInfo = () => { const { form: { getFieldsError }, } = this.props; const errors = getFieldsError(); const errorCount = Object.keys(errors).filter(key => errors[key]).length; if (!errors || errorCount === 0) { return null; } const scrollToField = (fieldKey: string) => { const labelNode = document.querySelector(`label[for="${fieldKey}"]`); if (labelNode) { labelNode.scrollIntoView(true); } }; const errorList = Object.keys(errors).map(key => { if (!errors[key]) { return null; } return (
  • scrollToField(key)}>
    {errors[key][0]}
    {fieldLabels[key]}
  • ); }); return ( { if (trigger && trigger.parentNode) { return trigger.parentNode as HTMLElement; } return trigger; }} > {errorCount} ); }; resizeFooterToolbar = () => { requestAnimationFrame(() => { const sider = document.querySelectorAll('.ant-layout-sider')[0] as HTMLDivElement; if (sider) { const width = `calc(100% - ${sider.style.width})`; const { width: stateWidth } = this.state; if (stateWidth !== width) { this.setState({ width }); } } }); }; validate = () => { const { form: { validateFieldsAndScroll }, dispatch, } = this.props; validateFieldsAndScroll((error, values) => { if (!error) { // submit the values dispatch({ type: 'BLOCK_NAME_CAMEL_CASE/submitAdvancedForm', payload: values, }); } }); }; render() { const { form: { getFieldDecorator }, submitting, } = this.props; const { width } = this.state; return ( <>
    {getFieldDecorator('name', { rules: [{ required: true, message: '请输入仓库名称' }], })()} {getFieldDecorator('url', { rules: [{ required: true, message: '请选择' }], })( )} {getFieldDecorator('owner', { rules: [{ required: true, message: '请选择管理员' }], })( )} {getFieldDecorator('approver', { rules: [{ required: true, message: '请选择审批员' }], })( )} {getFieldDecorator('dateRange', { rules: [{ required: true, message: '请选择生效日期' }], })( )} {getFieldDecorator('type', { rules: [{ required: true, message: '请选择仓库类型' }], })( )}
    {getFieldDecorator('name2', { rules: [{ required: true, message: '请输入' }], })()} {getFieldDecorator('url2', { rules: [{ required: true, message: '请选择' }], })()} {getFieldDecorator('owner2', { rules: [{ required: true, message: '请选择管理员' }], })( )} {getFieldDecorator('approver2', { rules: [{ required: true, message: '请选择审批员' }], })( )} {getFieldDecorator('dateRange2', { rules: [{ required: true, message: '请输入' }], })( { if (trigger && trigger.parentNode) { return trigger.parentNode as HTMLElement; } return trigger; }} /> )} {getFieldDecorator('type2', { rules: [{ required: true, message: '请选择仓库类型' }], })( )}
    {getFieldDecorator('members', { initialValue: tableData, })()} {this.getErrorInfo()} ); } } export default Form.create()(PAGE_NAME_UPPER_CAMEL_CASE);