fix: revert #9941 修复弹窗下有多个 form 时数据混乱问题

This commit is contained in:
2betop 2024-04-24 18:39:28 +08:00
parent b48173a314
commit a29b0dab55
3 changed files with 26 additions and 14 deletions

View File

@ -4,12 +4,17 @@ import {createObject} from '../utils/helper';
export const ModalStore = ServiceStore.named('ModalStore')
.props({
form: types.frozen(),
entered: false,
resizeCoord: 0,
schema: types.frozen()
})
.views(self => {
return {};
return {
get formData() {
return createObject(self.data, self.form);
}
};
})
.actions(self => {
return {
@ -17,7 +22,11 @@ export const ModalStore = ServiceStore.named('ModalStore')
self.entered = value;
},
setFormData(obj: any) {
self.form = obj;
},
reset() {
self.form = {};
self.reInitData({}, true);
},

View File

@ -423,7 +423,7 @@ export default class Dialog extends React.Component<DialogProps> {
handleFormInit(data: any) {
const {store} = this.props;
store.updateData(data);
store.setFormData(data);
}
handleFormChange(data: any, name?: string) {
@ -435,13 +435,13 @@ export default class Dialog extends React.Component<DialogProps> {
return;
}
store.updateData(data);
store.setFormData(data);
}
handleFormSaved(data: any, response: any) {
const {store} = this.props;
store.updateData({
store.setFormData({
...data,
...response
});
@ -553,7 +553,7 @@ export default class Dialog extends React.Component<DialogProps> {
) : null}
{actions.map((action, key) =>
render(`action/${key}`, action, {
data: store.data,
data: store.formData,
onAction: this.handleAction,
key,
disabled: action.disabled || store.loading || !show
@ -684,7 +684,7 @@ export default class Dialog extends React.Component<DialogProps> {
})
)}
>
{filter(__(title), store.data)}
{filter(__(title), store.formData)}
</div>
</div>
) : title ? (
@ -714,7 +714,7 @@ export default class Dialog extends React.Component<DialogProps> {
</a>
) : null}
{render('title', title, {
data: store.data,
data: store.formData,
onAction: this.handleAction
})}
</div>
@ -730,6 +730,7 @@ export default class Dialog extends React.Component<DialogProps> {
{header
? render('header', header, {
data: store.formData,
onAction: this.handleAction
})
: null}

View File

@ -423,25 +423,24 @@ export default class Drawer extends React.Component<DrawerProps> {
handleFormInit(data: any) {
const {store} = this.props;
store.updateData(data);
store.setFormData(data);
}
handleFormChange(data: any, name?: string) {
const {store} = this.props;
// 如果 drawer 里面不放 form而是直接放表单项就会进到这里来。
if (typeof name === 'string') {
data = {
[name]: data
};
store.changeValue(name, data);
return;
}
store.updateData(data);
store.setFormData(data);
}
handleFormSaved(data: any, response: any) {
const {store} = this.props;
store.updateData({
store.setFormData({
...data,
...response
});
@ -551,6 +550,7 @@ export default class Drawer extends React.Component<DrawerProps> {
{actions.map((action, key) =>
render(`action/${key}`, action, {
onAction: this.handleAction,
data: store.formData,
key,
disabled: action.disabled || store.loading
})
@ -681,6 +681,7 @@ export default class Drawer extends React.Component<DrawerProps> {
)}
>
{render('title', title, {
data: store.formData,
onConfirm: this.handleDrawerConfirm,
onClose: this.handleDrawerClose,
onAction: this.handleAction
@ -689,6 +690,7 @@ export default class Drawer extends React.Component<DrawerProps> {
) : null}
{header
? render('header', header, {
data: store.formData,
onConfirm: this.handleDrawerConfirm,
onClose: this.handleDrawerClose,
onAction: this.handleAction