容器内可能直接放表单项的情况

This commit is contained in:
2betop 2021-06-01 17:03:23 +08:00
parent f158aaac62
commit f77921c6ff
3 changed files with 33 additions and 2 deletions

View File

@ -322,9 +322,16 @@ export default class Dialog extends React.Component<DialogProps> {
store.setFormData(data);
}
handleFormChange(data: any) {
handleFormChange(data: any, name?: string) {
const {store} = this.props;
// 如果 dialog 里面不放 form而是直接放表单项就会进到这里来。
if (typeof name === 'string') {
data = {
[name]: data
};
}
store.setFormData(data);
}

View File

@ -325,9 +325,15 @@ export default class Drawer extends React.Component<DrawerProps> {
store.setFormData(data);
}
handleFormChange(data: any) {
handleFormChange(data: any, name?: string) {
const {store} = this.props;
if (typeof name === 'string') {
data = {
[name]: data
};
}
store.setFormData(data);
}

View File

@ -192,6 +192,7 @@ export default class Page extends React.Component<PageProps> {
// autobind 会让继承里面的 super 指向有问题,所以先这样!
bulkBindFunctions<Page /*为毛 this 的类型自动识别不出来*/>(this, [
'handleAction',
'handleChange',
'handleQuery',
'handleDialogConfirm',
'handleDialogClose',
@ -413,6 +414,22 @@ export default class Page extends React.Component<PageProps> {
return value;
}
handleChange(
value: any,
name: string,
submit?: boolean,
changePristine?: boolean
) {
const {store} = this.props;
// 注意 form 也有 onChange 会进来,但是传参会不一样,而且不应该处理。
if (typeof name !== 'string' || !name) {
return;
}
store.changeValue(name, value, changePristine);
}
renderHeader() {
const {
title,
@ -502,6 +519,7 @@ export default class Page extends React.Component<PageProps> {
const subProps = {
onAction: this.handleAction,
onQuery: initApi ? this.handleQuery : undefined,
onChange: this.handleChange,
loading: store.loading
};