update 完成表单中上传控件的使用
This commit is contained in:
@@ -16,6 +16,7 @@ export default class index extends Component {
|
||||
actived: '0',
|
||||
loading: true,
|
||||
record: null,
|
||||
saveDisabled: true,
|
||||
saving: false,
|
||||
}
|
||||
|
||||
@@ -42,6 +43,16 @@ export default class index extends Component {
|
||||
*/
|
||||
componentDidMount() {}
|
||||
|
||||
/**
|
||||
* 接收到所有子组件已加载完成,并启用提交按钮
|
||||
*/
|
||||
call(child, index) {
|
||||
this.children[index] = child
|
||||
if (this.children.filter(p => p).length === tabs.filter(p => p.show).length) {
|
||||
this.setState({ saveDisabled: false })
|
||||
}
|
||||
}
|
||||
|
||||
async onSubmit() {
|
||||
for (const child of this.children) {
|
||||
try {
|
||||
@@ -62,7 +73,7 @@ export default class index extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { actived, loading, record, saving } = this.state
|
||||
const { actived, loading, record, saveDisabled, saving } = this.state
|
||||
|
||||
return (
|
||||
<div className="yo-form-page">
|
||||
@@ -77,6 +88,7 @@ export default class index extends Component {
|
||||
取消
|
||||
</Button>
|
||||
<Button
|
||||
disabled={saveDisabled}
|
||||
loading={saving}
|
||||
type="primary"
|
||||
onClick={() => this.onSubmit()}
|
||||
@@ -125,7 +137,7 @@ export default class index extends Component {
|
||||
is={tab.component}
|
||||
record={record}
|
||||
loading={loading}
|
||||
onRef={c => this.children.push(c)}
|
||||
onRef={child => this.call(child, i)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -34,11 +34,13 @@ export default class index extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* DDOM加载完成钩子,在此将自身传递给父级
|
||||
* 加载完成,通知父级组件并传递自身
|
||||
*/
|
||||
componentDidMount() {
|
||||
if (this.props.onRef) {
|
||||
this.props.onRef(this)
|
||||
call(child, index) {
|
||||
this.children[index] = child
|
||||
if (this.children.filter(p => p).length === parts.length) {
|
||||
const { onRef } = this.props
|
||||
if (onRef) onRef(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,17 +87,17 @@ export default class index extends Component {
|
||||
<Card className="yo-form-page--body">
|
||||
{parts.map((item, i) => (
|
||||
<section key={i} id={`form-${i}-${id}`}>
|
||||
{item.title && <h5>{parts.title}</h5>}
|
||||
{item.title && <h5>{item.title}</h5>}
|
||||
<Spin
|
||||
spinning={loading}
|
||||
indicator={<AntIcon type="loading" />}
|
||||
wrapperClassName="h-400-min"
|
||||
wrapperClassName={loading && 'h-400-min'}
|
||||
>
|
||||
{!loading && (
|
||||
<ComponentDynamic
|
||||
is={item.component}
|
||||
record={record}
|
||||
onRef={r => this.children.push(r)}
|
||||
onRef={child => this.call(child, i)}
|
||||
/>
|
||||
)}
|
||||
</Spin>
|
||||
|
||||
@@ -36,17 +36,22 @@ export default class part extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* DOM加载完成钩子,在此将自身传递给父级,并且绑定数据
|
||||
* DOM加载完成钩子,绑定数据
|
||||
*/
|
||||
componentDidMount() {
|
||||
if (this.props.onRef) {
|
||||
this.props.onRef(this)
|
||||
}
|
||||
this.fillData({
|
||||
record: this.props.record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载完成,通知父级组件并传递自身
|
||||
*/
|
||||
call() {
|
||||
const { onRef } = this.props
|
||||
if (onRef) onRef(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
@@ -59,9 +64,8 @@ export default class part extends Component {
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false,
|
||||
})
|
||||
this.setState({ loading: false })
|
||||
this.call()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,6 +15,7 @@ export default class index extends Component {
|
||||
state = {
|
||||
loading: true,
|
||||
record: null,
|
||||
saveDisabled: true,
|
||||
saving: false,
|
||||
}
|
||||
|
||||
@@ -44,6 +45,13 @@ export default class index extends Component {
|
||||
*/
|
||||
componentDidMount() {}
|
||||
|
||||
call(child, index) {
|
||||
this.children[index] = child
|
||||
if (this.children.filter(p => p).length === tabs.filter(p => p.show).length) {
|
||||
this.setState({ saveDisabled: false })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交
|
||||
* [异步,必要]
|
||||
@@ -86,7 +94,7 @@ export default class index extends Component {
|
||||
render() {
|
||||
const { id } = this.props
|
||||
|
||||
const { loading, record, saving } = this.state
|
||||
const { loading, record, saveDisabled, saving } = this.state
|
||||
|
||||
return (
|
||||
<div className="yo-form-page">
|
||||
@@ -98,17 +106,17 @@ export default class index extends Component {
|
||||
<Card className="yo-form-page--body">
|
||||
{parts.map((item, i) => (
|
||||
<section key={i} id={`form-${i}-${id}`}>
|
||||
{item.title && <h5>{parts.title}</h5>}
|
||||
{item.title && <h5>{item.title}</h5>}
|
||||
<Spin
|
||||
spinning={loading}
|
||||
indicator={<AntIcon type="loading" />}
|
||||
wrapperClassName="h-400-min"
|
||||
wrapperClassName={loading && 'h-400-min'}
|
||||
>
|
||||
{!loading && (
|
||||
<ComponentDynamic
|
||||
is={item.component}
|
||||
record={record}
|
||||
onRef={r => this.children.push(r)}
|
||||
onRef={child => this.call(child, i)}
|
||||
/>
|
||||
)}
|
||||
</Spin>
|
||||
@@ -143,6 +151,7 @@ export default class index extends Component {
|
||||
<span>
|
||||
<Button onClick={() => window.closeContentWindow()}>取消</Button>
|
||||
<Button
|
||||
disabled={saveDisabled}
|
||||
loading={saving}
|
||||
type="primary"
|
||||
onClick={() => this.onSubmit()}
|
||||
|
||||
@@ -36,17 +36,22 @@ export default class part extends Component {
|
||||
}
|
||||
|
||||
/**
|
||||
* DOM加载完成钩子,在此将自身传递给父级,并且绑定数据
|
||||
* DOM加载完成钩子,绑定数据
|
||||
*/
|
||||
componentDidMount() {
|
||||
if (this.props.onRef) {
|
||||
this.props.onRef(this)
|
||||
}
|
||||
this.fillData({
|
||||
record: this.props.record,
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载完成,通知父级组件并传递自身
|
||||
*/
|
||||
call() {
|
||||
const { onRef } = this.props
|
||||
if (onRef) onRef(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* 填充数据
|
||||
* 可以在设置this.record之后对其作出数据结构调整
|
||||
@@ -59,9 +64,8 @@ export default class part extends Component {
|
||||
//#endregion
|
||||
this.form.current.setFieldsValue(this.record)
|
||||
|
||||
this.setState({
|
||||
loading: false,
|
||||
})
|
||||
this.setState({ loading: false })
|
||||
this.call()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user