fix 一些问题修复
This commit is contained in:
@@ -73,6 +73,8 @@ export default class index extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { id } = this.props
|
||||||
|
|
||||||
const { actived, loading, record, saveDisabled, saving } = this.state
|
const { actived, loading, record, saveDisabled, saving } = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -135,6 +137,7 @@ export default class index extends Component {
|
|||||||
>
|
>
|
||||||
<ComponentDynamic
|
<ComponentDynamic
|
||||||
is={tab.component}
|
is={tab.component}
|
||||||
|
id={id}
|
||||||
record={record}
|
record={record}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
onRef={child => this.call(child, i)}
|
onRef={child => this.call(child, i)}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default class index extends Component {
|
|||||||
* [非必要]
|
* [非必要]
|
||||||
* @param {*} container
|
* @param {*} container
|
||||||
*/
|
*/
|
||||||
setContainer(container) {
|
setContainer = container => {
|
||||||
this.container = (ReactDOM.findDOMNode(container) || {}).parentNode
|
this.container = (ReactDOM.findDOMNode(container) || {}).parentNode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ export default class index extends Component {
|
|||||||
const { id, loading } = this.props
|
const { id, loading } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container mode="fluid" ref={e => this.setContainer(e)}>
|
<Container mode="fluid" ref={this.setContainer}>
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col flex="1">
|
<Col flex="1">
|
||||||
<br />
|
<br />
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ export default class index extends Component {
|
|||||||
* [非必要]
|
* [非必要]
|
||||||
* @param {*} container
|
* @param {*} container
|
||||||
*/
|
*/
|
||||||
setContainer(container) {
|
setContainer = container => {
|
||||||
this.container = (ReactDOM.findDOMNode(container) || {}).parentNode
|
this.container = (ReactDOM.findDOMNode(container) || {}).parentNode
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ export default class index extends Component {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="yo-form-page">
|
<div className="yo-form-page">
|
||||||
<Container mode="fluid" ref={e => this.setContainer(e)}>
|
<Container mode="fluid" ref={this.setContainer}>
|
||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col flex="1">
|
<Col flex="1">
|
||||||
<br />
|
<br />
|
||||||
@@ -116,6 +116,7 @@ export default class index extends Component {
|
|||||||
{!loading && (
|
{!loading && (
|
||||||
<ComponentDynamic
|
<ComponentDynamic
|
||||||
is={item.component}
|
is={item.component}
|
||||||
|
id={id}
|
||||||
record={record}
|
record={record}
|
||||||
onRef={child => this.call(child, i)}
|
onRef={child => this.call(child, i)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ export default class index extends Component {
|
|||||||
>
|
>
|
||||||
<ComponentDynamic
|
<ComponentDynamic
|
||||||
is={tab.component}
|
is={tab.component}
|
||||||
|
id={this.props.id}
|
||||||
record={record}
|
record={record}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
onRef={child => this.call(child, i)}
|
onRef={child => this.call(child, i)}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import ReactDOM from 'react-dom'
|
import ReactDOM from 'react-dom'
|
||||||
import { Row, Col, Card, Anchor, Spin } from 'antd'
|
import { Anchor, Card, Col, Divider, Row, Spin } from 'antd'
|
||||||
import { merge } from 'lodash'
|
|
||||||
import { AntIcon, ComponentDynamic, Container } from 'components'
|
import { AntIcon, ComponentDynamic, Container } from 'components'
|
||||||
|
import { isEqual, merge } from 'lodash'
|
||||||
|
|
||||||
const parts = [
|
const parts = [
|
||||||
{
|
{
|
||||||
@@ -28,76 +28,103 @@ const parts = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
export default class index extends Component {
|
export default class index extends Component {
|
||||||
container = window
|
// 子表单实例集合
|
||||||
|
|
||||||
children = []
|
children = []
|
||||||
|
|
||||||
|
// 整合提交数据
|
||||||
formData = {}
|
formData = {}
|
||||||
|
|
||||||
shouldComponentUpdate(props) {
|
// 锚点挂载DOM
|
||||||
return this.props.loading !== props.loading
|
container = window
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阻止外部组件引发的渲染,提升性能
|
||||||
|
* 可自行添加渲染条件
|
||||||
|
* [必要]
|
||||||
|
* @param {*} props
|
||||||
|
* @param {*} state
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
shouldComponentUpdate(props, state) {
|
||||||
|
return !isEqual(this.state, state) || this.props.loading !== props.loading
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通知上层组件已加载完毕
|
/**
|
||||||
|
* 加载完成,通知父级组件并传递自身
|
||||||
|
*/
|
||||||
call(child, index) {
|
call(child, index) {
|
||||||
this.children[index] = child
|
this.children[index] = child
|
||||||
if (this.children.filter(p => p).length === parts.length) {
|
if (this.children.filter(p => p).length === parts.length) {
|
||||||
if (this.props.onRef) {
|
const { onRef } = this.props
|
||||||
this.props.onRef(this)
|
if (onRef) onRef(this)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getContainer = () => {
|
/**
|
||||||
return this.container
|
* 从下级组件获取表单数据,并传递给更上级组件
|
||||||
}
|
* [异步,必要]
|
||||||
|
* @returns
|
||||||
setContainer = container => {
|
*/
|
||||||
this.container = (ReactDOM.findDOMNode(container) || {}).parentNode
|
|
||||||
}
|
|
||||||
|
|
||||||
async getData() {
|
async getData() {
|
||||||
for (const child of this.children) {
|
for (const child of this.children) {
|
||||||
const data = await child.getData()
|
const data = await child.getData()
|
||||||
merge(this.formData, data)
|
merge(this.formData, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.formData
|
return this.formData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置锚点容器
|
||||||
|
* [非必要]
|
||||||
|
* @param {*} container
|
||||||
|
*/
|
||||||
|
setContainer = container => {
|
||||||
|
this.container = (ReactDOM.findDOMNode(container) || {}).parentNode
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染
|
||||||
|
* 当前渲染结构已完善,非必要可以不用修改
|
||||||
|
* [必要]
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
render() {
|
render() {
|
||||||
const { id, loading } = this.props
|
const { id, loading } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container mode="fluid" ref={this.setContainer}>
|
<Container mode="fluid" ref={this.setContainer}>
|
||||||
<Row gutter={16} type="flex">
|
<Row gutter={16}>
|
||||||
<Col flex="1">
|
<Col flex="1">
|
||||||
<br />
|
<br />
|
||||||
<div className="yo-adorn--house-top" />
|
<div className="yo-adorn--house-top" />
|
||||||
<Card className="yo-form-page--body">
|
<Card className="yo-form-page--body">
|
||||||
{parts.map((part, i) => (
|
{parts.map((item, i) => (
|
||||||
<section key={i} id={`form-${i}-${id}`}>
|
<React.Fragment key={i}>
|
||||||
{part.title && <h5>{part.title}</h5>}
|
<section id={`form-${i}-${id}`}>
|
||||||
<Spin
|
{item.title && <h5>{item.title}</h5>}
|
||||||
spinning={loading}
|
<Spin
|
||||||
indicator={<AntIcon type="loading" />}
|
spinning={loading}
|
||||||
wrapperClassName={loading && 'h-400-min'}
|
indicator={<AntIcon type="loading" />}
|
||||||
>
|
wrapperClassName={loading && 'h-400-min'}
|
||||||
{!loading && (
|
>
|
||||||
<ComponentDynamic
|
{!loading && (
|
||||||
is={part.component}
|
<ComponentDynamic
|
||||||
{...this.props}
|
is={item.component}
|
||||||
onRef={child => this.call(child, i)}
|
{...this.props}
|
||||||
/>
|
onRef={child => this.call(child, i)}
|
||||||
)}
|
/>
|
||||||
</Spin>
|
)}
|
||||||
</section>
|
</Spin>
|
||||||
|
</section>
|
||||||
|
{i < parts.length - 1 && <Divider />}
|
||||||
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</Card>
|
</Card>
|
||||||
</Col>
|
</Col>
|
||||||
|
{/* 锚点,如果不需要可以删除以下节点 */}
|
||||||
<Col flex="240px">
|
<Col flex="240px">
|
||||||
<Anchor
|
<Anchor
|
||||||
getContainer={this.getContainer}
|
getContainer={() => this.container}
|
||||||
offsetTop={24}
|
offsetTop={24}
|
||||||
targetOffset={100}
|
targetOffset={100}
|
||||||
wrapperStyle={{ backgroundColor: 'transparent' }}
|
wrapperStyle={{ backgroundColor: 'transparent' }}
|
||||||
|
|||||||
@@ -1,7 +1,115 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
|
import { Form, Spin } from 'antd'
|
||||||
|
import { AntIcon } from 'components'
|
||||||
|
import { cloneDeep, isEqual } from 'lodash'
|
||||||
|
|
||||||
|
const initialValues = {}
|
||||||
|
|
||||||
|
const layout = {
|
||||||
|
labelCol: { flex: '150px' },
|
||||||
|
wrapperCol: { flex: '1' },
|
||||||
|
}
|
||||||
|
|
||||||
export default class inspection extends Component {
|
export default class inspection extends Component {
|
||||||
|
state = {
|
||||||
|
loading: true,
|
||||||
|
codes: {},
|
||||||
|
options: {},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 表单实例
|
||||||
|
form = React.createRef()
|
||||||
|
|
||||||
|
// 初始化数据
|
||||||
|
record = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 阻止外部组件引发的渲染,提升性能
|
||||||
|
* 可自行添加渲染条件
|
||||||
|
* [必要]
|
||||||
|
* @param {*} props
|
||||||
|
* @param {*} state
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
shouldComponentUpdate(props, state) {
|
||||||
|
return !isEqual(this.state, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DOM加载完成钩子,绑定数据
|
||||||
|
*/
|
||||||
|
componentDidMount() {
|
||||||
|
this.fillData({
|
||||||
|
record: this.props.record,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 加载完成,通知父级组件并传递自身
|
||||||
|
*/
|
||||||
|
call() {
|
||||||
|
const { onRef } = this.props
|
||||||
|
if (onRef) onRef(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 填充数据
|
||||||
|
* 可以在设置this.record之后对其作出数据结构调整
|
||||||
|
* [异步,必要]
|
||||||
|
* @param {*} params
|
||||||
|
*/
|
||||||
|
async fillData(params) {
|
||||||
|
this.record = cloneDeep(params.record)
|
||||||
|
//#region 从后端转换成前段所需格式
|
||||||
|
//#endregion
|
||||||
|
this.form.current.setFieldsValue(this.record)
|
||||||
|
|
||||||
|
this.setState({ loading: false })
|
||||||
|
this.call()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取数据
|
||||||
|
* 可以对postData进行数据结构调整
|
||||||
|
* [异步,必要]
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
async getData() {
|
||||||
|
const form = this.form.current
|
||||||
|
|
||||||
|
const valid = await form.validateFields()
|
||||||
|
if (valid) {
|
||||||
|
const postData = form.getFieldsValue()
|
||||||
|
//#region 从前段转换后端所需格式
|
||||||
|
//#endregion
|
||||||
|
return postData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//#region 自定义方法
|
||||||
|
/**
|
||||||
|
* 表单change事件处理,包括了所有字段的change
|
||||||
|
* [异步,非必要]
|
||||||
|
* @param {*} changedValues
|
||||||
|
* @param {*} allValues
|
||||||
|
*/
|
||||||
|
async onValuesChange(changedValues, allValues) {}
|
||||||
|
//#endregion
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <div>1</div>
|
const { loading } = this.state
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Spin spinning={loading} indicator={<AntIcon type="loading" />}>
|
||||||
|
<Form
|
||||||
|
initialValues={initialValues}
|
||||||
|
ref={this.form}
|
||||||
|
{...layout}
|
||||||
|
onValuesChange={(changedValues, allValues) =>
|
||||||
|
this.onValuesChange(changedValues, allValues)
|
||||||
|
}
|
||||||
|
></Form>
|
||||||
|
</Spin>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user