Skip to content

Commit 286800f

Browse files
YunMeng99WB01081293
andauthored
fix(Dialog): the status returned by using onCancel in Promise loading added to the okProps
--------- Co-authored-by: WB01081293 <gym01081293@alibaba-inc.com>
1 parent 56a1fd0 commit 286800f

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

src/dialog/show.jsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class Modal extends Component {
6868
*/
6969
onClose: PropTypes.func,
7070
okProps: PropTypes.object,
71+
cancelProps: PropTypes.object,
7172
locale: PropTypes.object,
7273
needWrapper: PropTypes.bool,
7374
className: PropTypes.string,
@@ -81,13 +82,15 @@ class Modal extends Component {
8182
onCancel: noop,
8283
onClose: noop,
8384
okProps: {},
85+
cancelProps: {},
8486
locale: zhCN.Dialog,
8587
needWrapper: true,
8688
};
8789

8890
state = {
8991
visible: true,
90-
loading: false,
92+
okLoading: false,
93+
cancelLoading: false,
9194
};
9295

9396
close = () => {
@@ -96,26 +99,31 @@ class Modal extends Component {
9699
});
97100
};
98101

99-
loading = loading => {
102+
okLoading = loading => {
100103
this.setState({
101-
loading,
104+
okLoading: loading,
105+
});
106+
};
107+
cancelLoading = loading => {
108+
this.setState({
109+
cancelLoading: loading,
102110
});
103111
};
104112

105-
wrapper(fn, callback) {
113+
wrapper(fn, callback, changeLoading) {
106114
return (...args) => {
107115
const res = fn(...args);
108116
if (res && res.then) {
109-
this.loading(true);
117+
changeLoading(true);
110118

111119
res.then(result => {
112-
this.loading(false);
120+
changeLoading(false);
113121

114122
if (result !== false) {
115123
return callback();
116124
}
117125
}).catch(e => {
118-
this.loading(false);
126+
changeLoading(false);
119127
throw e;
120128
});
121129
} else if (res !== false) {
@@ -136,6 +144,7 @@ class Modal extends Component {
136144
onCancel,
137145
onClose,
138146
okProps,
147+
cancelProps,
139148
needWrapper,
140149
rtl,
141150
className,
@@ -166,17 +175,21 @@ class Modal extends Component {
166175
: ['alert', 'success', 'error', 'notice', 'warning', 'help'].indexOf(type) > -1
167176
? ['ok']
168177
: undefined);
169-
const newOnOk = this.wrapper(onOk, this.close);
170-
const newOnCancel = this.wrapper(onCancel, this.close);
171-
const newOnClose = this.wrapper(onClose, this.close);
178+
const newOnOk = this.wrapper(onOk, this.close, this.okLoading);
179+
const newOnCancel = this.wrapper(onCancel, this.close, this.cancelLoading);
180+
const newOnClose = this.wrapper(onClose, this.close, this.cancelLoading);
172181

173-
const { visible, loading } = this.state;
182+
const { visible, okLoading, cancelLoading } = this.state;
174183
// 不能直接改,这里修改相当于改了全局 okProps
175184
// okProps.loading = loading;
176185

177186
const newOkProps = { ...okProps };
178187
if (!('loading' in okProps)) {
179-
newOkProps.loading = loading;
188+
newOkProps.loading = okLoading;
189+
}
190+
const newCancelProps = { ...cancelProps };
191+
if (!('loading' in cancelProps)) {
192+
newCancelProps.loading = cancelLoading;
180193
}
181194

182195
const classNames = cx(`${prefix}dialog-quick`, className);
@@ -196,6 +209,7 @@ class Modal extends Component {
196209
onCancel={newOnCancel}
197210
onClose={newOnClose}
198211
okProps={newOkProps}
212+
cancelProps={newCancelProps}
199213
className={classNames}
200214
width={v2 ? width : undefined}
201215
>

0 commit comments

Comments
 (0)