import React, { Component } from 'react' import ReactDOM from 'react-dom' import { Anchor, Button, Card, Col, Divider, Row, Spin } from 'antd' import { AntIcon, ComponentDynamic, Container } from 'components' import { isEqual, merge } from 'lodash' const parts = [ { // title: '标题', component: () => import('./part'), }, ] export default class index extends Component { state = { loading: true, record: null, saveDisabled: true, saving: false, } // 子表单实例集合 children = [] // 整合提交数据 formData = {} // 锚点挂载DOM container = window /** * 阻止外部组件引发的渲染,提升性能 * 可自行添加渲染条件 * [必要] * @param {*} props * @param {*} state * @returns */ shouldComponentUpdate(props, state) { return !isEqual(this.state, state) } /** * DOM加载完成钩子,可在此获取详细数据赋值到record */ componentDidMount() {} call(child, index) { this.children[index] = child if (this.children.filter(p => p).length === parts.filter(p => p.show).length) { this.setState({ saveDisabled: false }) } } /** * 提交 * [异步,必要] * @returns */ async onSubmit() { for (const child of this.children) { try { const data = await child.getData() merge(this.formData, data) } catch (e) { return e } } //#region 提交数据 this.setState({ saving: true }) this.setState({ saving: false }) //#endregion } /** * 设置锚点容器 * [非必要] * @param {*} container */ setContainer = container => { this.container = (ReactDOM.findDOMNode(container) || {}).parentNode } /** * 渲染 * 当前渲染结构已完善,非必要可以不用修改 * [必要] * @returns */ render() { const { id } = this.props const { loading, record, saveDisabled, saving } = this.state return (